Skip to content

Commit

Permalink
Merge pull request #116 from vektah/extends-missing
Browse files Browse the repository at this point in the history
Allow extending types that haven't been declared
  • Loading branch information
vektah authored Feb 8, 2020
2 parents c07bed4 + 3eaa5ac commit 4684b46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 6 additions & 1 deletion validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, *gqlerror.Error) {
for _, ext := range ast.Extensions {
def := schema.Types[ext.Name]
if def == nil {
return nil, gqlerror.ErrorPosf(ext.Position, "Cannot extend type %s because it does not exist.", ext.Name)
schema.Types[ext.Name] = &Definition{
Kind: ext.Kind,
Name: ext.Name,
Position: ext.Position,
}
def = schema.Types[ext.Name]
}

if def.Kind != ext.Kind {
Expand Down
6 changes: 2 additions & 4 deletions validator/schema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,12 @@ unions:
locations: [{line: 1, column: 7}]

type extensions:
- name: cannot extend non existant types
- name: can extend non existant types
input: |
extend type A {
name: String
}
error:
message: "Cannot extend type A because it does not exist."
locations: [{line: 1, column: 13}]
- name: cannot extend incorret type existant types
input: |
Expand Down

0 comments on commit 4684b46

Please sign in to comment.