From c5e3f78ac81b3b9cb7f0cbc08b5b235859875c07 Mon Sep 17 00:00:00 2001 From: Jatin Dev <64803093+JatinDevDG@users.noreply.github.com> Date: Sat, 6 Jun 2020 03:19:53 +0530 Subject: [PATCH] [Breaking] graphql: Add camelCase for add/update mutation. (#5547) This PR Modify lowercase typename for add/update mutation to camelCase. Fixes #5380 Fixes #GRAPHQL-448 Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com> --- graphql/e2e/auth/add_mutation_test.go | 2 +- graphql/e2e/common/mutation.go | 2 +- graphql/resolve/add_mutation_test.yaml | 2 +- graphql/resolve/auth_add_test.yaml | 12 ++++++------ graphql/resolve/auth_update_test.yaml | 6 +++--- graphql/resolve/update_mutation_test.yaml | 6 +++--- graphql/schema/gqlschema.go | 16 ++++++++++++---- ...tive-on-concrete-type-with-interfaces.graphql | 4 ++-- ...aph-reverse-directive-with-interfaces.graphql | 4 ++-- ...reverse-predicate-in-dgraph-directive.graphql | 4 ++-- 10 files changed, 33 insertions(+), 25 deletions(-) diff --git a/graphql/e2e/auth/add_mutation_test.go b/graphql/e2e/auth/add_mutation_test.go index 3fcd28488ce..8cf29bbcece 100644 --- a/graphql/e2e/auth/add_mutation_test.go +++ b/graphql/e2e/auth/add_mutation_test.go @@ -662,7 +662,7 @@ func TestAddGQLOnly(t *testing.T) { query := ` mutation addUser($user: AddUserSecretInput!) { addUserSecret(input: [$user]) { - usersecret { + userSecret { aSecret } } diff --git a/graphql/e2e/common/mutation.go b/graphql/e2e/common/mutation.go index d466fce8ceb..2c1aa27b1e8 100644 --- a/graphql/e2e/common/mutation.go +++ b/graphql/e2e/common/mutation.go @@ -2576,7 +2576,7 @@ func addMutationWithReverseDgraphEdge(t *testing.T) { addMovieDirectorParams := &GraphQLParams{ Query: `mutation addMovieDirector($dir: [AddMovieDirectorInput!]!) { addMovieDirector(input: $dir) { - moviedirector { + movieDirector { id name } diff --git a/graphql/resolve/add_mutation_test.yaml b/graphql/resolve/add_mutation_test.yaml index 26be00bde9c..d077ac820a4 100644 --- a/graphql/resolve/add_mutation_test.yaml +++ b/graphql/resolve/add_mutation_test.yaml @@ -982,7 +982,7 @@ gqlmutation: | mutation addMovieDirector($dir: AddMovieDirectorInput!) { addMovieDirector(input: [$dir]) { - moviedirector { + movieDirector { id } } diff --git a/graphql/resolve/auth_add_test.yaml b/graphql/resolve/auth_add_test.yaml index e1f403d58ae..d3578f39912 100644 --- a/graphql/resolve/auth_add_test.yaml +++ b/graphql/resolve/auth_add_test.yaml @@ -2,7 +2,7 @@ gqlquery: | mutation addUserSecret($secret: AddUserSecretInput!) { addUserSecret(input: [$secret]) { - usersecret { + userSecret { id } } @@ -30,7 +30,7 @@ gqlquery: | mutation addUserSecret($secrets: [AddUserSecretInput!]!) { addUserSecret(input: $secrets) { - usersecret { + userSecret { id } } @@ -59,7 +59,7 @@ gqlquery: | mutation addUserSecret($secret: AddUserSecretInput!) { addUserSecret(input: [$secret]) { - usersecret { + userSecret { id } } @@ -89,7 +89,7 @@ gqlquery: | mutation addUserSecret($secrets: [AddUserSecretInput!]!) { addUserSecret(input: $secrets) { - usersecret { + userSecret { id } } @@ -932,7 +932,7 @@ gqlquery: | mutation addComplexLog($log: AddComplexLogInput!) { addComplexLog(input: [$log]) { - complexlog { + complexLog { id } } @@ -953,7 +953,7 @@ gqlquery: | mutation addComplexLog($log: AddComplexLogInput!) { addComplexLog(input: [$log]) { - complexlog { + complexLog { id } } diff --git a/graphql/resolve/auth_update_test.yaml b/graphql/resolve/auth_update_test.yaml index 334e1167860..0187e68e6fe 100644 --- a/graphql/resolve/auth_update_test.yaml +++ b/graphql/resolve/auth_update_test.yaml @@ -2,7 +2,7 @@ gqlquery: | mutation updateUserSecret($upd: UpdateUserSecretInput!) { updateUserSecret(input: $upd) { - usersecret { + userSecret { id } } @@ -600,7 +600,7 @@ gqlquery: | mutation updateComplexLog($log: UpdateComplexLogInput!) { updateComplexLog(input: $log) { - complexlog { + complexLog { id } } @@ -626,7 +626,7 @@ gqlquery: | mutation updateComplexLog($log: UpdateComplexLogInput!) { updateComplexLog(input: $log) { - complexlog { + complexLog { id } } diff --git a/graphql/resolve/update_mutation_test.yaml b/graphql/resolve/update_mutation_test.yaml index d54331f6fa8..823f0a04f4e 100644 --- a/graphql/resolve/update_mutation_test.yaml +++ b/graphql/resolve/update_mutation_test.yaml @@ -872,7 +872,7 @@ gqlmutation: | mutation updateMovieDirector($patch: UpdateMovieDirectorInput!) { updateMovieDirector(input: $patch) { - moviedirector { + movieDirector { id } } @@ -912,7 +912,7 @@ gqlmutation: | mutation updateMovieDirector($patch: UpdateMovieDirectorInput!) { updateMovieDirector(input: $patch) { - moviedirector { + movieDirector { id } } @@ -1375,7 +1375,7 @@ gqlmutation: | mutation updateComputerOwner($patch: UpdateComputerOwnerInput!) { updateComputerOwner(input: $patch) { - computerowner { + computerOwner { name } } diff --git a/graphql/schema/gqlschema.go b/graphql/schema/gqlschema.go index f5b2d390137..e5857612b86 100644 --- a/graphql/schema/gqlschema.go +++ b/graphql/schema/gqlschema.go @@ -842,12 +842,12 @@ func hasOrderables(defn *ast.Definition) bool { func hasID(defn *ast.Definition) bool { return fieldAny(defn.Fields, - func(fld *ast.FieldDefinition) bool { return isID(fld) }) + isID) } func hasXID(defn *ast.Definition) bool { return fieldAny(defn.Fields, - func(fld *ast.FieldDefinition) bool { return hasIDDirective(fld) }) + hasIDDirective) } // fieldAny returns true if any field in fields satisfies pred @@ -971,7 +971,7 @@ func addTypeOrderable(schema *ast.Schema, defn *ast.Definition) { func addAddPayloadType(schema *ast.Schema, defn *ast.Definition) { qry := &ast.FieldDefinition{ - Name: strings.ToLower(defn.Name), + Name: camelCase(defn.Name), Type: ast.ListType(&ast.Type{ NamedType: defn.Name, }, nil), @@ -1001,7 +1001,7 @@ func addUpdatePayloadType(schema *ast.Schema, defn *ast.Definition) { } qry := &ast.FieldDefinition{ - Name: strings.ToLower(defn.Name), + Name: camelCase(defn.Name), Type: &ast.Type{ Elem: &ast.Type{ NamedType: defn.Name, @@ -1640,3 +1640,11 @@ func isGraphqlSpecScalar(typ string) bool { _, ok := graphqlSpecScalars[typ] return ok } + +func camelCase(x string) string { + if x == "" { + return "" + } + + return strings.ToLower(x[:1]) + x[1:] +} diff --git a/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql b/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql index 4c3ecc7b5d7..0804234b383 100755 --- a/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql +++ b/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-on-concrete-type-with-interfaces.graphql @@ -148,7 +148,7 @@ type AddDirectorPayload { } type AddOscarMoviePayload { - oscarmovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] + oscarMovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] numUids: Int } @@ -178,7 +178,7 @@ type UpdateMoviePayload { } type UpdateOscarMoviePayload { - oscarmovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] + oscarMovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] numUids: Int } diff --git a/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql b/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql index a6b88abb7c5..18cd1d1666a 100755 --- a/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql +++ b/graphql/schema/testdata/schemagen/output/dgraph-reverse-directive-with-interfaces.graphql @@ -148,7 +148,7 @@ type AddDirectorPayload { } type AddOscarMoviePayload { - oscarmovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] + oscarMovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] numUids: Int } @@ -178,7 +178,7 @@ type UpdateMoviePayload { } type UpdateOscarMoviePayload { - oscarmovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] + oscarMovie(filter: OscarMovieFilter, order: OscarMovieOrder, first: Int, offset: Int): [OscarMovie] numUids: Int } diff --git a/graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql b/graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql index 8cb7f212dcb..7171b1d786b 100755 --- a/graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql +++ b/graphql/schema/testdata/schemagen/output/field-with-reverse-predicate-in-dgraph-directive.graphql @@ -136,7 +136,7 @@ input StringHashFilter { ####################### type AddMovieDirectorPayload { - moviedirector(filter: MovieDirectorFilter, order: MovieDirectorOrder, first: Int, offset: Int): [MovieDirector] + movieDirector(filter: MovieDirectorFilter, order: MovieDirectorOrder, first: Int, offset: Int): [MovieDirector] numUids: Int } @@ -156,7 +156,7 @@ type DeleteMoviePayload { } type UpdateMovieDirectorPayload { - moviedirector(filter: MovieDirectorFilter, order: MovieDirectorOrder, first: Int, offset: Int): [MovieDirector] + movieDirector(filter: MovieDirectorFilter, order: MovieDirectorOrder, first: Int, offset: Int): [MovieDirector] numUids: Int }