Skip to content

Commit

Permalink
BREAKING - do not apply camelCase naming convention in buildOperation…
Browse files Browse the repository at this point in the history
…NodeForField and remove camel-case dependency
  • Loading branch information
ardatan committed Jun 17, 2021
1 parent 9520001 commit e610927
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-yaks-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - do not apply camelCase naming convention in buildOperationNodeForField
1 change: 0 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"dependencies": {
"@ardatan/aggregate-error": "0.0.6",
"camel-case": "4.1.2",
"tslib": "~2.3.0"
},
"publishConfig": {
Expand Down
9 changes: 2 additions & 7 deletions packages/utils/src/build-operation-for-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
isEnumType,
Kind,
} from 'graphql';
import { camelCase } from 'camel-case';

let operationVariables: VariableDefinitionNode[] = [];
let fieldTypeMap = new Map();
Expand All @@ -44,10 +43,6 @@ function resetFieldMap() {
fieldTypeMap = new Map();
}

function buildOperationName(name: string) {
return camelCase(name);
}

export type Skip = string[];
export type Force = string[];
export type Ignore = string[];
Expand Down Expand Up @@ -131,7 +126,7 @@ function buildOperationAndCollectVariables({
};
const type = typeMap[kind];
const field = type.getFields()[fieldName];
const operationName = buildOperationName(`${fieldName}_${kind}`);
const operationName = `${fieldName}_${kind}`;

if (field.args) {
field.args.forEach(arg => {
Expand Down Expand Up @@ -396,7 +391,7 @@ function resolveVariable(arg: GraphQLArgument, name?: string): VariableDefinitio
}

function getArgumentName(name: string, path: string[]): string {
return camelCase([...path, name].join('_'));
return [...path, name].join('_');
}

function resolveField({
Expand Down
28 changes: 14 additions & 14 deletions packages/utils/tests/build-operation-node-for-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test('should work with Query', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query meQuery {
query me_query {
me {
id
name
Expand Down Expand Up @@ -131,7 +131,7 @@ test('should work with Query and variables', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query userQuery($id: ID!) {
query user_query($id: ID!) {
user(id: $id) {
id
name
Expand Down Expand Up @@ -178,7 +178,7 @@ test('should work with Query and complicated variable', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query menuByIngredientsQuery($ingredients: [String!]!) {
query menuByIngredients_query($ingredients: [String!]!) {
menuByIngredients(ingredients: $ingredients) {
... on Pizza {
dough
Expand Down Expand Up @@ -211,7 +211,7 @@ test('should work with Union', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query menuQuery {
query menu_query {
menu {
... on Pizza {
dough
Expand Down Expand Up @@ -244,7 +244,7 @@ test('should work with mutation', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
mutation addSaladMutation($ingredients: [String!]!) {
mutation addSalad_mutation($ingredients: [String!]!) {
addSalad(ingredients: $ingredients) {
... on CaeserSalad {
ingredients
Expand All @@ -271,7 +271,7 @@ test('should work with mutation and unions', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
mutation addRandomFoodMutation {
mutation addRandomFood_mutation {
addRandomFood {
... on Pizza {
dough
Expand Down Expand Up @@ -304,9 +304,9 @@ test('should work with Query and nested variables', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query feedQuery($feedCommentsFilter: String!) {
query feed_query($feed_comments_filter: String!) {
feed {
comments(filter: $feedCommentsFilter)
comments(filter: $feed_comments_filter)
}
}
`)
Expand All @@ -324,7 +324,7 @@ test('should be able to ignore using models when requested', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query userQuery($id: ID!) {
query user_query($id: ID!) {
user(id: $id) {
id
name
Expand Down Expand Up @@ -373,7 +373,7 @@ test('should work with Subscription', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
subscription onFoodSubscription {
subscription onFood_subscription {
onFood {
... on Pizza {
dough
Expand Down Expand Up @@ -423,7 +423,7 @@ test('should work with circular ref (default depth limit === 1)', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query aQuery {
query a_query {
a {
b {
c {
Expand Down Expand Up @@ -465,7 +465,7 @@ test('should work with circular ref (custom depth limit)', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query aQuery {
query a_query {
a {
b {
c {
Expand Down Expand Up @@ -510,7 +510,7 @@ test('arguments', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query usersQuery($pageInfo: PageInfoInput!) {
query users_query($pageInfo: PageInfoInput!) {
users(pageInfo: $pageInfo) {
id
name
Expand Down Expand Up @@ -538,7 +538,7 @@ test('selectedFields', async () => {

expect(clean(document)).toEqual(
clean(/* GraphQL */ `
query userQuery($id: ID!) {
query user_query($id: ID!) {
user(id: $id) {
favoriteFood {
... on Pizza {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4095,7 +4095,7 @@ callsites@^3.0.0:
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==

camel-case@4.1.2, camel-case@^4.1.1:
camel-case@^4.1.1:
version "4.1.2"
resolved "https://registry.yarnpkg.com/camel-case/-/camel-case-4.1.2.tgz#9728072a954f805228225a6deea6b38461e1bd5a"
integrity sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==
Expand Down

0 comments on commit e610927

Please sign in to comment.