From b26b915ea6f5a8529cc63c1f5285118426868510 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Thu, 7 Feb 2019 10:29:20 +1100 Subject: [PATCH] Move input validation into gqlparser see https://github.com/vektah/gqlparser/pull/96 --- codegen/args.go | 10 -------- codegen/directive.go | 5 ---- codegen/errors_test.go | 35 ---------------------------- codegen/field.go | 12 ---------- codegen/testdata/typeinput.graphqls | 7 ------ codegen/testdata/unioninput.graphqls | 5 ---- 6 files changed, 74 deletions(-) delete mode 100644 codegen/errors_test.go delete mode 100644 codegen/testdata/typeinput.graphqls delete mode 100644 codegen/testdata/unioninput.graphqls diff --git a/codegen/args.go b/codegen/args.go index aa57026b5f9..b5690e7d78b 100644 --- a/codegen/args.go +++ b/codegen/args.go @@ -31,16 +31,6 @@ func (f *FieldArgument) Stream() bool { } func (b *builder) buildArg(obj *Object, arg *ast.ArgumentDefinition) (*FieldArgument, error) { - def := b.Schema.Types[arg.Type.Name()] - if !def.IsInputType() { - return nil, errors.Errorf( - "cannot use %s as argument %s because %s is not a valid input type", - arg.Type.String(), - arg.Name, - def.Kind, - ) - } - tr, err := b.Binder.TypeReference(arg.Type, nil) if err != nil { return nil, err diff --git a/codegen/directive.go b/codegen/directive.go index 37c496bf5a6..52f3cbae7b5 100644 --- a/codegen/directive.go +++ b/codegen/directive.go @@ -28,11 +28,6 @@ func (b *builder) buildDirectives() (map[string]*Directive, error) { var args []*FieldArgument for _, arg := range dir.Arguments { - def := b.Schema.Types[arg.Type.Name()] - if !def.IsInputType() { - return nil, errors.Errorf("%s cannot be used as argument of directive %s(%s) only input and scalar types are allowed", arg.Type, dir.Name, arg.Name) - } - tr, err := b.Binder.TypeReference(arg.Type, nil) if err != nil { return nil, err diff --git a/codegen/errors_test.go b/codegen/errors_test.go deleted file mode 100644 index 2e5eaebf1b9..00000000000 --- a/codegen/errors_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package codegen - -import ( - "testing" - - "github.com/99designs/gqlgen/codegen/config" - "github.com/stretchr/testify/require" -) - -func TestTypeUnionAsInput(t *testing.T) { - err := generate("inputunion", `testdata/unioninput.graphqls`) - - require.EqualError(t, err, "unable to build object definition: cannot use Bookmarkable! as argument b because UNION is not a valid input type") -} - -func TestTypeInInput(t *testing.T) { - err := generate("typeinput", `testdata/typeinput.graphqls`) - - require.EqualError(t, err, "unable to build input definition: BookmarkableInput.item: cannot use Item because OBJECT is not a valid input type") -} - -func generate(name string, schemaFilename string) error { - _, err := BuildData(&config.Config{ - SchemaFilename: config.StringList{schemaFilename}, - Exec: config.PackageConfig{Filename: "gen/" + name + "/exec.go"}, - Model: config.PackageConfig{Filename: "gen/" + name + "/model.go"}, - Models: map[string]config.TypeMapEntry{ - "Item": {Model: config.StringList{"map[string]interface{}"}}, - "Bookmarkable": {Model: config.StringList{"interface{}"}}, - "BookmarkableInput": {Model: config.StringList{"interface{}"}}, - }, - }) - - return err -} diff --git a/codegen/field.go b/codegen/field.go index 6d64a3b8e9e..42dce261004 100644 --- a/codegen/field.go +++ b/codegen/field.go @@ -36,18 +36,6 @@ func (b *builder) buildField(obj *Object, field *ast.FieldDefinition) (*Field, e return nil, err } - def := b.Schema.Types[field.Type.Name()] - - if obj.Kind == ast.InputObject && !def.IsInputType() { - return nil, errors.Errorf( - "%s.%s: cannot use %s because %s is not a valid input type", - obj.Name, - field.Name, - def.Name, - def.Kind, - ) - } - f := Field{ FieldDefinition: field, Object: obj, diff --git a/codegen/testdata/typeinput.graphqls b/codegen/testdata/typeinput.graphqls deleted file mode 100644 index ba0438afca4..00000000000 --- a/codegen/testdata/typeinput.graphqls +++ /dev/null @@ -1,7 +0,0 @@ -type Query { - addBookmark(b: BookmarkableInput!): Boolean! -} -type Item {name: String} -input BookmarkableInput { - item: Item -} diff --git a/codegen/testdata/unioninput.graphqls b/codegen/testdata/unioninput.graphqls deleted file mode 100644 index b1a17b1dd1f..00000000000 --- a/codegen/testdata/unioninput.graphqls +++ /dev/null @@ -1,5 +0,0 @@ -type Query { - addBookmark(b: Bookmarkable!): Boolean! -} -type Item {name: String} -union Bookmarkable = Item