diff --git a/graphql/schema/gqlschema_test.yml b/graphql/schema/gqlschema_test.yml index 55d3310e779..10f4faaa451 100644 --- a/graphql/schema/gqlschema_test.yml +++ b/graphql/schema/gqlschema_test.yml @@ -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: | @@ -2677,4 +2689,4 @@ valid_schemas: id: ID! name: String owns: [Object] @dgraph(pred: "~Object.owner") - } + } \ No newline at end of file diff --git a/graphql/schema/rules.go b/graphql/schema/rules.go index 6f60b70ccf2..8b3a7d6812f 100644 --- a/graphql/schema/rules.go +++ b/graphql/schema/rules.go @@ -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 }