Skip to content

Commit

Permalink
fix(GraphQL): Disallow Subscription typename. (#6077) (#6173)
Browse files Browse the repository at this point in the history
This PR disallow Subscription typename so that it doesn't conflict with Subscriptions generated.

(cherry picked from commit 601e837)
  • Loading branch information
JatinDev543 authored Aug 13, 2020
1 parent 1986e70 commit fed5092
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion graphql/schema/gqlschema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,18 @@ invalid_schemas:
"locations":[{"line":6, "column":5}]}
]

-
name: "Subscription typename should return error"
input: |
type Subscription {
name: String
}
errlist: [
{"message": "Subscription is a reserved word, so you can't declare a type with this name. Pick a different name for the type.", "locations": [{"line":1, "column":6}]},
]


valid_schemas:
- name: "@auth on interface implementation"
input: |
Expand Down Expand Up @@ -2677,4 +2689,4 @@ valid_schemas:
id: ID!
name: String
owns: [Object] @dgraph(pred: "~Object.owner")
}
}
8 changes: 7 additions & 1 deletion graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,13 @@ func isReservedArgument(name string) bool {
}

func isReservedKeyWord(name string) bool {
if isScalar(name) || isQueryOrMutation(name) || name == "uid" {
reservedTypeNames := map[string]bool{
// Reserved Type names
"uid": true,
"Subscription": true,
}

if isScalar(name) || isQueryOrMutation(name) || reservedTypeNames[name] {
return true
}

Expand Down

0 comments on commit fed5092

Please sign in to comment.