Skip to content

Commit

Permalink
fix(GraphQL): Don't reserve certain queries/mutations/inputs when a t…
Browse files Browse the repository at this point in the history
…ype is remote. (#6055) (#6201)

Fixes the issue mentioned in https://discuss.dgraph.io/t/custom-directive-issue-documentation-related/8885 where certain identifiers were incorrectly reserved even though they shouldn't have been.

(cherry picked from commit 9b67c2f)
  • Loading branch information
pawanrawal authored Aug 17, 2020
1 parent 63b586c commit 025891e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
39 changes: 39 additions & 0 deletions graphql/schema/gqlschema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2689,4 +2689,43 @@ valid_schemas:
id: ID!
name: String
owns: [Object] @dgraph(pred: "~Object.owner")
}
- name: "@custom getAuthor query is allowed if Author is of remote type"
input: |
type Author @remote {
id: ID!
name: String
}
type Query {
getAuthor(id: ID): Author! @custom(http: {url: "http://blah.com", method: "GET"})
}
- name: "@custom addAuthor mutation is allowed if Author is of remote type"
input: |
type Author @remote {
id: ID!
name: String
}
type Mutation {
addAuthor(id: ID): Author! @custom(http: {url: "http://blah.com", method: "GET"})
}
- name: "UpdateAuthorInput is allowed if Author is of remote type"
input: |
type Author @remote {
id: ID!
name: String
}
type User {
id: ID!
name: String
}
input UpdateAuthorInput {
id: ID!
name: String
}
21 changes: 21 additions & 0 deletions graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ func inputTypeNameValidation(schema *ast.SchemaDocument) gqlerror.List {
continue
}

// If the type has a remote directive, then the input types below are not forbidden and can
// be used.
remote := defn.Directives.ForName(remoteDirective)
if remote != nil {
continue
}

// types that are generated by us
forbiddenInputTypeNames[defName+"Ref"] = true
forbiddenInputTypeNames[defName+"Patch"] = true
Expand Down Expand Up @@ -331,6 +338,13 @@ func customQueryNameValidation(schema *ast.SchemaDocument) gqlerror.List {
continue
}

// If the type has a remote directive, then getT, checkT and queryT are not forbidden
// since we won't automatically generate them.
remote := defn.Directives.ForName(remoteDirective)
if remote != nil {
continue
}

// forbid query names that are generated by us
forbiddenNames["get"+defName] = true
forbiddenNames["check"+defName+"Password"] = true
Expand Down Expand Up @@ -363,6 +377,13 @@ func customMutationNameValidation(schema *ast.SchemaDocument) gqlerror.List {
continue
}

// If the type has a remote directive, then updateT, deleteT and addT are not forbidden
// since we won't automatically generate them.
remote := defn.Directives.ForName(remoteDirective)
if remote != nil {
continue
}

// forbid mutation names that are generated by us
switch defn.Kind {
case ast.Interface:
Expand Down

0 comments on commit 025891e

Please sign in to comment.