Skip to content

Commit

Permalink
[Breaking] graphql: Add camelCase for add/update mutation. (#5547)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
JatinDev543 and abhimanyusinghgaur authored Jun 5, 2020
1 parent aef7072 commit c5e3f78
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion graphql/e2e/auth/add_mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func TestAddGQLOnly(t *testing.T) {
query := `
mutation addUser($user: AddUserSecretInput!) {
addUserSecret(input: [$user]) {
usersecret {
userSecret {
aSecret
}
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ func addMutationWithReverseDgraphEdge(t *testing.T) {
addMovieDirectorParams := &GraphQLParams{
Query: `mutation addMovieDirector($dir: [AddMovieDirectorInput!]!) {
addMovieDirector(input: $dir) {
moviedirector {
movieDirector {
id
name
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/resolve/add_mutation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@
gqlmutation: |
mutation addMovieDirector($dir: AddMovieDirectorInput!) {
addMovieDirector(input: [$dir]) {
moviedirector {
movieDirector {
id
}
}
Expand Down
12 changes: 6 additions & 6 deletions graphql/resolve/auth_add_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
gqlquery: |
mutation addUserSecret($secret: AddUserSecretInput!) {
addUserSecret(input: [$secret]) {
usersecret {
userSecret {
id
}
}
Expand Down Expand Up @@ -30,7 +30,7 @@
gqlquery: |
mutation addUserSecret($secrets: [AddUserSecretInput!]!) {
addUserSecret(input: $secrets) {
usersecret {
userSecret {
id
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@
gqlquery: |
mutation addUserSecret($secret: AddUserSecretInput!) {
addUserSecret(input: [$secret]) {
usersecret {
userSecret {
id
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@
gqlquery: |
mutation addUserSecret($secrets: [AddUserSecretInput!]!) {
addUserSecret(input: $secrets) {
usersecret {
userSecret {
id
}
}
Expand Down Expand Up @@ -932,7 +932,7 @@
gqlquery: |
mutation addComplexLog($log: AddComplexLogInput!) {
addComplexLog(input: [$log]) {
complexlog {
complexLog {
id
}
}
Expand All @@ -953,7 +953,7 @@
gqlquery: |
mutation addComplexLog($log: AddComplexLogInput!) {
addComplexLog(input: [$log]) {
complexlog {
complexLog {
id
}
}
Expand Down
6 changes: 3 additions & 3 deletions graphql/resolve/auth_update_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
gqlquery: |
mutation updateUserSecret($upd: UpdateUserSecretInput!) {
updateUserSecret(input: $upd) {
usersecret {
userSecret {
id
}
}
Expand Down Expand Up @@ -600,7 +600,7 @@
gqlquery: |
mutation updateComplexLog($log: UpdateComplexLogInput!) {
updateComplexLog(input: $log) {
complexlog {
complexLog {
id
}
}
Expand All @@ -626,7 +626,7 @@
gqlquery: |
mutation updateComplexLog($log: UpdateComplexLogInput!) {
updateComplexLog(input: $log) {
complexlog {
complexLog {
id
}
}
Expand Down
6 changes: 3 additions & 3 deletions graphql/resolve/update_mutation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@
gqlmutation: |
mutation updateMovieDirector($patch: UpdateMovieDirectorInput!) {
updateMovieDirector(input: $patch) {
moviedirector {
movieDirector {
id
}
}
Expand Down Expand Up @@ -912,7 +912,7 @@
gqlmutation: |
mutation updateMovieDirector($patch: UpdateMovieDirectorInput!) {
updateMovieDirector(input: $patch) {
moviedirector {
movieDirector {
id
}
}
Expand Down Expand Up @@ -1375,7 +1375,7 @@
gqlmutation: |
mutation updateComputerOwner($patch: UpdateComputerOwnerInput!) {
updateComputerOwner(input: $patch) {
computerowner {
computerOwner {
name
}
}
Expand Down
16 changes: 12 additions & 4 deletions graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit c5e3f78

Please sign in to comment.