-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam Scarr
committed
Jul 11, 2018
1 parent
5f29b46
commit 923c6ed
Showing
5 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package validator | ||
|
||
import "github.com/vektah/gqlparser" | ||
|
||
func init() { | ||
fieldVisitors = append(fieldVisitors, scalarLeafs) | ||
} | ||
|
||
func scalarLeafs(ctx *vctx, parentDef *gqlparser.Definition, fieldDef *gqlparser.FieldDefinition, field *gqlparser.Field) { | ||
if fieldDef == nil { | ||
return | ||
} | ||
|
||
fieldType := ctx.schema.Types[fieldDef.Type.Name()] | ||
if fieldType == nil { | ||
return | ||
} | ||
|
||
if fieldType.IsLeafType() && len(field.SelectionSet) > 0 { | ||
ctx.errors = append(ctx.errors, Error( | ||
Rule("ScalarLeafs"), | ||
Message(`Field "%s" must not have a selection since type "%s" has no subfields.`, field.Name, fieldType.Name), | ||
)) | ||
} | ||
|
||
if !fieldType.IsLeafType() && len(field.SelectionSet) == 0 { | ||
ctx.errors = append(ctx.errors, Error( | ||
Rule("ScalarLeafs"), | ||
Message(`Field "%s" of type "%s" must have a selection of subfields.`, field.Name, fieldDef.Type.String()), | ||
Suggestf(`"%s { ... }"`, field.Name), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters