From 2487809d27865f04d761e4593bfac533dcc5fd8e Mon Sep 17 00:00:00 2001 From: harshil Date: Wed, 11 Dec 2019 13:50:23 +0530 Subject: [PATCH 01/25] Changed vektah to dgraph-io --- ast/definition.go | 2 +- ast/document_test.go | 4 ++-- formatter/formatter.go | 4 ++-- formatter/formatter_test.go | 8 ++++---- go.mod | 2 +- gqlerror/error.go | 2 +- gqlparser.go | 10 +++++----- lexer/lexer.go | 4 ++-- lexer/lexer_test.go | 4 ++-- lexer/token.go | 2 +- parser/parser.go | 6 +++--- parser/parser_test.go | 4 ++-- parser/query.go | 6 +++--- parser/query_test.go | 4 ++-- parser/schema.go | 6 +++--- parser/schema_test.go | 4 ++-- parser/testrunner/runner.go | 2 +- readme.md | 2 +- validator/error.go | 4 ++-- validator/imported_test.go | 6 +++--- validator/prelude.go | 2 +- validator/rules/fields_on_correct_type.go | 4 ++-- validator/rules/fragments_on_composite_types.go | 4 ++-- validator/rules/known_argument_names.go | 4 ++-- validator/rules/known_directives.go | 4 ++-- validator/rules/known_fragment_names.go | 4 ++-- validator/rules/known_type_names.go | 4 ++-- validator/rules/lone_anonymous_operation.go | 4 ++-- validator/rules/no_fragment_cycles.go | 4 ++-- validator/rules/no_undefined_variables.go | 4 ++-- validator/rules/no_unused_fragments.go | 4 ++-- validator/rules/no_unused_variables.go | 4 ++-- validator/rules/overlapping_fields_can_be_merged.go | 4 ++-- validator/rules/possible_fragment_spreads.go | 4 ++-- validator/rules/provided_required_arguments.go | 4 ++-- validator/rules/scalar_leafs.go | 4 ++-- validator/rules/single_field_subscriptions.go | 4 ++-- validator/rules/unique_argument_names.go | 4 ++-- validator/rules/unique_directives_per_location.go | 4 ++-- validator/rules/unique_fragment_names.go | 4 ++-- validator/rules/unique_input_field_names.go | 4 ++-- validator/rules/unique_operation_names.go | 4 ++-- validator/rules/unique_variable_names.go | 4 ++-- validator/rules/values_of_correct_type.go | 4 ++-- validator/rules/variables_are_input_types.go | 4 ++-- validator/rules/variables_in_allowed_position.go | 4 ++-- validator/schema.go | 6 +++--- validator/schema_test.go | 4 ++-- validator/validator.go | 4 ++-- validator/vars.go | 4 ++-- validator/vars_test.go | 6 +++--- validator/walk.go | 2 +- validator/walk_test.go | 4 ++-- 53 files changed, 109 insertions(+), 109 deletions(-) diff --git a/ast/definition.go b/ast/definition.go index f5c8ea37..36076774 100644 --- a/ast/definition.go +++ b/ast/definition.go @@ -14,7 +14,7 @@ const ( // ObjectDefinition is the core type definition object, it includes all of the definable types // but does *not* cover schema or directives. // -// @vektah: Javascript implementation has different types for all of these, but they are +// @dgraph-io: Javascript implementation has different types for all of these, but they are // more similar than different and don't define any behaviour. I think this style of // "some hot" struct works better, at least for go. // diff --git a/ast/document_test.go b/ast/document_test.go index b6461594..74b85f4a 100644 --- a/ast/document_test.go +++ b/ast/document_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser" + . "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser" ) func TestQueryDocMethods(t *testing.T) { diff --git a/formatter/formatter.go b/formatter/formatter.go index 3131b70f..b4f1ea96 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/vektah/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/ast" ) type Formatter interface { @@ -532,7 +532,7 @@ func (f *formatter) FormatVariableDefinition(def *ast.VariableDefinition) { f.FormatValue(def.DefaultValue) } - // TODO https://github.com/vektah/gqlparser/v2/issues/102 + // TODO https://github.com/dgraph-io/gqlparser/issues/102 // VariableDefinition : Variable : Type DefaultValue? Directives[Const]? } diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index 6e1f67e2..410f7a72 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -10,10 +10,10 @@ import ( "unicode/utf8" "github.com/stretchr/testify/assert" - "github.com/vektah/gqlparser/v2" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/formatter" - "github.com/vektah/gqlparser/v2/parser" + "github.com/dgraph-io/gqlparser" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/formatter" + "github.com/dgraph-io/gqlparser/parser" ) var update = flag.Bool("u", false, "update golden files") diff --git a/go.mod b/go.mod index afdb99d8..41e7a276 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/vektah/gqlparser/v2 +module github.com/dgraph-io/gqlparser go 1.12 diff --git a/gqlerror/error.go b/gqlerror/error.go index 70a5a6cf..64f269d7 100644 --- a/gqlerror/error.go +++ b/gqlerror/error.go @@ -5,7 +5,7 @@ import ( "fmt" "strconv" - "github.com/vektah/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/ast" ) // Error is the standard graphql error type described in https://facebook.github.io/graphql/draft/#sec-Errors diff --git a/gqlparser.go b/gqlparser.go index ace63e14..c3527bb0 100644 --- a/gqlparser.go +++ b/gqlparser.go @@ -1,11 +1,11 @@ package gqlparser import ( - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" - "github.com/vektah/gqlparser/v2/parser" - "github.com/vektah/gqlparser/v2/validator" - _ "github.com/vektah/gqlparser/v2/validator/rules" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/parser" + "github.com/dgraph-io/gqlparser/validator" + _ "github.com/dgraph-io/gqlparser/validator/rules" ) func LoadSchema(str ...*ast.Source) (*ast.Schema, *gqlerror.Error) { diff --git a/lexer/lexer.go b/lexer/lexer.go index 720dd5b4..499fab8a 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -4,8 +4,8 @@ import ( "bytes" "unicode/utf8" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" ) // Lexer turns graphql request and schema strings into tokens diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 82510eaf..fe2aa7d2 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -3,8 +3,8 @@ package lexer import ( "testing" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser/testrunner" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser/testrunner" ) func TestLexer(t *testing.T) { diff --git a/lexer/token.go b/lexer/token.go index 8985a7ef..d76649b8 100644 --- a/lexer/token.go +++ b/lexer/token.go @@ -3,7 +3,7 @@ package lexer import ( "strconv" - "github.com/vektah/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/ast" ) const ( diff --git a/parser/parser.go b/parser/parser.go index 52b8e684..e96fa002 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3,9 +3,9 @@ package parser import ( "strconv" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" - "github.com/vektah/gqlparser/v2/lexer" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/lexer" ) type parser struct { diff --git a/parser/parser_test.go b/parser/parser_test.go index 02ff41fe..0936d251 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/lexer" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/lexer" ) func TestParserUtils(t *testing.T) { diff --git a/parser/query.go b/parser/query.go index 939e8af4..4afad7b8 100644 --- a/parser/query.go +++ b/parser/query.go @@ -1,10 +1,10 @@ package parser import ( - "github.com/vektah/gqlparser/v2/gqlerror" - "github.com/vektah/gqlparser/v2/lexer" + "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/lexer" - . "github.com/vektah/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/ast" ) func ParseQuery(source *Source) (*QueryDocument, *gqlerror.Error) { diff --git a/parser/query_test.go b/parser/query_test.go index 08d2ad15..a157f718 100644 --- a/parser/query_test.go +++ b/parser/query_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser/testrunner" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser/testrunner" ) func TestQueryDocument(t *testing.T) { diff --git a/parser/schema.go b/parser/schema.go index 7cfdd147..ed8d47a3 100644 --- a/parser/schema.go +++ b/parser/schema.go @@ -1,9 +1,9 @@ package parser import ( - . "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" - "github.com/vektah/gqlparser/v2/lexer" + . "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/lexer" ) func ParseSchema(source *Source) (*SchemaDocument, *gqlerror.Error) { diff --git a/parser/schema_test.go b/parser/schema_test.go index 5c3d19c0..674242bc 100644 --- a/parser/schema_test.go +++ b/parser/schema_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser/testrunner" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser/testrunner" ) func TestSchemaDocument(t *testing.T) { diff --git a/parser/testrunner/runner.go b/parser/testrunner/runner.go index 4c5d9685..7ca78a45 100644 --- a/parser/testrunner/runner.go +++ b/parser/testrunner/runner.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/andreyvit/diff" - "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/gqlerror" "gopkg.in/yaml.v2" ) diff --git a/readme.md b/readme.md index a7cb346b..4d90d1eb 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -gqlparser [![CircleCI](https://badgen.net/circleci/github/vektah/gqlparser/master)](https://circleci.com/gh/vektah/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/vektah/gqlparser/v2)](https://goreportcard.com/report/github.com/vektah/gqlparser/v2) [![Coverage Status](https://badgen.net/coveralls/c/github/vektah/gqlparser)](https://coveralls.io/github/vektah/gqlparser?branch=master) +gqlparser [![CircleCI](https://badgen.net/circleci/github/dgraph-io/gqlparser/master)](https://circleci.com/gh/dgraph-io/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/dgraph-io/gqlparser)](https://goreportcard.com/report/github.com/dgraph-io/gqlparser) [![Coverage Status](https://badgen.net/coveralls/c/github/dgraph-io/gqlparser)](https://coveralls.io/github/dgraph-io/gqlparser?branch=master) === This is a parser for graphql, written to mirror the graphql-js reference implementation as closely while remaining idiomatic and easy to use. diff --git a/validator/error.go b/validator/error.go index f8f76055..983e1b96 100644 --- a/validator/error.go +++ b/validator/error.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" ) type ErrorOption func(err *gqlerror.Error) diff --git a/validator/imported_test.go b/validator/imported_test.go index adef3049..61de910e 100644 --- a/validator/imported_test.go +++ b/validator/imported_test.go @@ -12,9 +12,9 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" "gopkg.in/yaml.v2" ) diff --git a/validator/prelude.go b/validator/prelude.go index 0c7e9b2d..08ce53f5 100644 --- a/validator/prelude.go +++ b/validator/prelude.go @@ -1,6 +1,6 @@ package validator -import "github.com/vektah/gqlparser/v2/ast" +import "github.com/dgraph-io/gqlparser/ast" var Prelude = &ast.Source{ Name: "prelude.graphql", diff --git a/validator/rules/fields_on_correct_type.go b/validator/rules/fields_on_correct_type.go index 8bfb8cc3..944b9e29 100644 --- a/validator/rules/fields_on_correct_type.go +++ b/validator/rules/fields_on_correct_type.go @@ -4,8 +4,8 @@ import ( "fmt" "sort" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/fragments_on_composite_types.go b/validator/rules/fragments_on_composite_types.go index 5215f697..fddad16b 100644 --- a/validator/rules/fragments_on_composite_types.go +++ b/validator/rules/fragments_on_composite_types.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/known_argument_names.go b/validator/rules/known_argument_names.go index 9a53df17..ef9e3ee7 100644 --- a/validator/rules/known_argument_names.go +++ b/validator/rules/known_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/known_directives.go b/validator/rules/known_directives.go index f3c0f80e..8cc73872 100644 --- a/validator/rules/known_directives.go +++ b/validator/rules/known_directives.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/known_fragment_names.go b/validator/rules/known_fragment_names.go index b7427d0d..78b8d14e 100644 --- a/validator/rules/known_fragment_names.go +++ b/validator/rules/known_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/known_type_names.go b/validator/rules/known_type_names.go index c228af70..0cc5cae6 100644 --- a/validator/rules/known_type_names.go +++ b/validator/rules/known_type_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/lone_anonymous_operation.go b/validator/rules/lone_anonymous_operation.go index d2752854..83f26b9c 100644 --- a/validator/rules/lone_anonymous_operation.go +++ b/validator/rules/lone_anonymous_operation.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/no_fragment_cycles.go b/validator/rules/no_fragment_cycles.go index 81fffa57..d7c0bd0a 100644 --- a/validator/rules/no_fragment_cycles.go +++ b/validator/rules/no_fragment_cycles.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/no_undefined_variables.go b/validator/rules/no_undefined_variables.go index 4f05f00a..9755cb06 100644 --- a/validator/rules/no_undefined_variables.go +++ b/validator/rules/no_undefined_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/no_unused_fragments.go b/validator/rules/no_unused_fragments.go index dfc89672..5d8d9fd1 100644 --- a/validator/rules/no_unused_fragments.go +++ b/validator/rules/no_unused_fragments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/no_unused_variables.go b/validator/rules/no_unused_variables.go index df2e5f4b..cf19bbc6 100644 --- a/validator/rules/no_unused_variables.go +++ b/validator/rules/no_unused_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/overlapping_fields_can_be_merged.go b/validator/rules/overlapping_fields_can_be_merged.go index 5cd028df..7c7264ff 100644 --- a/validator/rules/overlapping_fields_can_be_merged.go +++ b/validator/rules/overlapping_fields_can_be_merged.go @@ -5,8 +5,8 @@ import ( "fmt" "reflect" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/possible_fragment_spreads.go b/validator/rules/possible_fragment_spreads.go index a3f795c9..b3cba7ee 100644 --- a/validator/rules/possible_fragment_spreads.go +++ b/validator/rules/possible_fragment_spreads.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/provided_required_arguments.go b/validator/rules/provided_required_arguments.go index 4410288a..49d49f14 100644 --- a/validator/rules/provided_required_arguments.go +++ b/validator/rules/provided_required_arguments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/scalar_leafs.go b/validator/rules/scalar_leafs.go index 718bc683..783b0577 100644 --- a/validator/rules/scalar_leafs.go +++ b/validator/rules/scalar_leafs.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/single_field_subscriptions.go b/validator/rules/single_field_subscriptions.go index 206e3a6e..a3c3b14e 100644 --- a/validator/rules/single_field_subscriptions.go +++ b/validator/rules/single_field_subscriptions.go @@ -3,8 +3,8 @@ package validator import ( "strconv" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_argument_names.go b/validator/rules/unique_argument_names.go index fc2b639d..03b4f54d 100644 --- a/validator/rules/unique_argument_names.go +++ b/validator/rules/unique_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_directives_per_location.go b/validator/rules/unique_directives_per_location.go index 2ea4f13d..bb7b8b13 100644 --- a/validator/rules/unique_directives_per_location.go +++ b/validator/rules/unique_directives_per_location.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_fragment_names.go b/validator/rules/unique_fragment_names.go index 8c348aea..b742536b 100644 --- a/validator/rules/unique_fragment_names.go +++ b/validator/rules/unique_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_input_field_names.go b/validator/rules/unique_input_field_names.go index 092be671..d7bf4824 100644 --- a/validator/rules/unique_input_field_names.go +++ b/validator/rules/unique_input_field_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_operation_names.go b/validator/rules/unique_operation_names.go index 4d41b60a..023882a6 100644 --- a/validator/rules/unique_operation_names.go +++ b/validator/rules/unique_operation_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/unique_variable_names.go b/validator/rules/unique_variable_names.go index 64ac5072..ca003272 100644 --- a/validator/rules/unique_variable_names.go +++ b/validator/rules/unique_variable_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/values_of_correct_type.go b/validator/rules/values_of_correct_type.go index 40dc2194..75fb7d2c 100644 --- a/validator/rules/values_of_correct_type.go +++ b/validator/rules/values_of_correct_type.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/variables_are_input_types.go b/validator/rules/variables_are_input_types.go index 4ea94e5a..123d4ccf 100644 --- a/validator/rules/variables_are_input_types.go +++ b/validator/rules/variables_are_input_types.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/rules/variables_in_allowed_position.go b/validator/rules/variables_in_allowed_position.go index aba6eb62..abce1c1c 100644 --- a/validator/rules/variables_in_allowed_position.go +++ b/validator/rules/variables_in_allowed_position.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/vektah/gqlparser/v2/ast" - . "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/validator" ) func init() { diff --git a/validator/schema.go b/validator/schema.go index 72dfe65f..59a3b06f 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -6,9 +6,9 @@ import ( "strconv" "strings" - . "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" - "github.com/vektah/gqlparser/v2/parser" + . "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/parser" ) func LoadSchema(inputs ...*Source) (*Schema, *gqlerror.Error) { diff --git a/validator/schema_test.go b/validator/schema_test.go index c5dae23c..99ac0762 100644 --- a/validator/schema_test.go +++ b/validator/schema_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser/testrunner" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser/testrunner" ) func TestLoadSchema(t *testing.T) { diff --git a/validator/validator.go b/validator/validator.go index 34bf93db..cb0d0c09 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -1,8 +1,8 @@ package validator import ( - . "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" + . "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" ) type AddErrFunc func(options ...ErrorOption) diff --git a/validator/vars.go b/validator/vars.go index 209b1c9c..676975f1 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -6,8 +6,8 @@ import ( "fmt" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/gqlerror" ) var UnexpectedType = fmt.Errorf("Unexpected Type") diff --git a/validator/vars_test.go b/validator/vars_test.go index ec77df7f..c7025244 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -7,9 +7,9 @@ import ( "encoding/json" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/validator" + "github.com/dgraph-io/gqlparser" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/validator" ) func TestValidateVars(t *testing.T) { diff --git a/validator/walk.go b/validator/walk.go index 8f8abf10..ea4f0db4 100644 --- a/validator/walk.go +++ b/validator/walk.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/vektah/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/ast" ) type Events struct { diff --git a/validator/walk_test.go b/validator/walk_test.go index 3343872c..8fed399c 100644 --- a/validator/walk_test.go +++ b/validator/walk_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser" + "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/parser" ) func TestWalker(t *testing.T) { From 11dafedfd473e2db55bed3a3caf3e49b7f527ac9 Mon Sep 17 00:00:00 2001 From: Pawan Rawal Date: Tue, 3 Nov 2020 13:08:13 +0530 Subject: [PATCH 02/25] Fix import paths to have v2 suffix --- ast/document_test.go | 4 ++-- formatter/formatter.go | 4 ++-- formatter/formatter_test.go | 8 ++++---- go.mod | 2 +- gqlerror/error.go | 2 +- gqlerror/error_test.go | 2 +- gqlparser.go | 10 +++++----- lexer/lexer.go | 4 ++-- lexer/lexer_test.go | 4 ++-- lexer/token.go | 2 +- parser/parser.go | 6 +++--- parser/parser_test.go | 4 ++-- parser/query.go | 6 +++--- parser/query_test.go | 4 ++-- parser/schema.go | 6 +++--- parser/schema_test.go | 4 ++-- parser/testrunner/runner.go | 2 +- readme.md | 2 +- validator/error.go | 4 ++-- validator/imported_test.go | 6 +++--- validator/prelude.go | 2 +- validator/rules/fields_on_correct_type.go | 4 ++-- validator/rules/fragments_on_composite_types.go | 4 ++-- validator/rules/known_argument_names.go | 4 ++-- validator/rules/known_directives.go | 4 ++-- validator/rules/known_fragment_names.go | 4 ++-- validator/rules/known_type_names.go | 4 ++-- validator/rules/lone_anonymous_operation.go | 4 ++-- validator/rules/no_fragment_cycles.go | 4 ++-- validator/rules/no_undefined_variables.go | 4 ++-- validator/rules/no_unused_fragments.go | 4 ++-- validator/rules/no_unused_variables.go | 4 ++-- validator/rules/overlapping_fields_can_be_merged.go | 4 ++-- validator/rules/possible_fragment_spreads.go | 4 ++-- validator/rules/provided_required_arguments.go | 4 ++-- validator/rules/scalar_leafs.go | 4 ++-- validator/rules/single_field_subscriptions.go | 4 ++-- validator/rules/unique_argument_names.go | 4 ++-- validator/rules/unique_directives_per_location.go | 4 ++-- validator/rules/unique_fragment_names.go | 4 ++-- validator/rules/unique_input_field_names.go | 4 ++-- validator/rules/unique_operation_names.go | 4 ++-- validator/rules/unique_variable_names.go | 4 ++-- validator/rules/values_of_correct_type.go | 4 ++-- validator/rules/variables_are_input_types.go | 4 ++-- validator/rules/variables_in_allowed_position.go | 4 ++-- validator/schema.go | 10 +++++----- validator/schema_test.go | 4 ++-- validator/validator.go | 4 ++-- validator/validator_test.go | 8 ++++---- validator/vars.go | 4 ++-- validator/vars_test.go | 6 +++--- validator/walk.go | 2 +- validator/walk_test.go | 4 ++-- 54 files changed, 115 insertions(+), 115 deletions(-) diff --git a/ast/document_test.go b/ast/document_test.go index 74b85f4a..0389b352 100644 --- a/ast/document_test.go +++ b/ast/document_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser" + . "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser" ) func TestQueryDocMethods(t *testing.T) { diff --git a/formatter/formatter.go b/formatter/formatter.go index b4f1ea96..66de72b2 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/v2/ast" ) type Formatter interface { @@ -532,7 +532,7 @@ func (f *formatter) FormatVariableDefinition(def *ast.VariableDefinition) { f.FormatValue(def.DefaultValue) } - // TODO https://github.com/dgraph-io/gqlparser/issues/102 + // TODO https://github.com/dgraph-io/gqlparser/v2/issues/102 // VariableDefinition : Variable : Type DefaultValue? Directives[Const]? } diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index 410f7a72..cdf2c19c 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -9,11 +9,11 @@ import ( "testing" "unicode/utf8" + "github.com/dgraph-io/gqlparser/v2" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/formatter" + "github.com/dgraph-io/gqlparser/v2/parser" "github.com/stretchr/testify/assert" - "github.com/dgraph-io/gqlparser" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/formatter" - "github.com/dgraph-io/gqlparser/parser" ) var update = flag.Bool("u", false, "update golden files") diff --git a/go.mod b/go.mod index 41e7a276..0d094d59 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/dgraph-io/gqlparser +module github.com/dgraph-io/gqlparser/v2 go 1.12 diff --git a/gqlerror/error.go b/gqlerror/error.go index 64f269d7..c2ce8cbd 100644 --- a/gqlerror/error.go +++ b/gqlerror/error.go @@ -5,7 +5,7 @@ import ( "fmt" "strconv" - "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/v2/ast" ) // Error is the standard graphql error type described in https://facebook.github.io/graphql/draft/#sec-Errors diff --git a/gqlerror/error_test.go b/gqlerror/error_test.go index 3a06b00a..e8ee06db 100644 --- a/gqlerror/error_test.go +++ b/gqlerror/error_test.go @@ -3,8 +3,8 @@ package gqlerror import ( "testing" + "github.com/dgraph-io/gqlparser/v2/ast" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2/ast" ) func TestErrorFormatting(t *testing.T) { diff --git a/gqlparser.go b/gqlparser.go index c3527bb0..f09f1b36 100644 --- a/gqlparser.go +++ b/gqlparser.go @@ -1,11 +1,11 @@ package gqlparser import ( - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" - "github.com/dgraph-io/gqlparser/parser" - "github.com/dgraph-io/gqlparser/validator" - _ "github.com/dgraph-io/gqlparser/validator/rules" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/v2/parser" + "github.com/dgraph-io/gqlparser/v2/validator" + _ "github.com/dgraph-io/gqlparser/v2/validator/rules" ) func LoadSchema(str ...*ast.Source) (*ast.Schema, *gqlerror.Error) { diff --git a/lexer/lexer.go b/lexer/lexer.go index 499fab8a..f25f7d02 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -4,8 +4,8 @@ import ( "bytes" "unicode/utf8" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" ) // Lexer turns graphql request and schema strings into tokens diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index fe2aa7d2..5d9f84bf 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -3,8 +3,8 @@ package lexer import ( "testing" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser/testrunner" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser/testrunner" ) func TestLexer(t *testing.T) { diff --git a/lexer/token.go b/lexer/token.go index d76649b8..c6f5eb1e 100644 --- a/lexer/token.go +++ b/lexer/token.go @@ -3,7 +3,7 @@ package lexer import ( "strconv" - "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/v2/ast" ) const ( diff --git a/parser/parser.go b/parser/parser.go index e96fa002..724343f8 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3,9 +3,9 @@ package parser import ( "strconv" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" - "github.com/dgraph-io/gqlparser/lexer" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/v2/lexer" ) type parser struct { diff --git a/parser/parser_test.go b/parser/parser_test.go index 0936d251..3bda7e12 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -3,9 +3,9 @@ package parser import ( "testing" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/lexer" "github.com/stretchr/testify/require" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/lexer" ) func TestParserUtils(t *testing.T) { diff --git a/parser/query.go b/parser/query.go index 4afad7b8..994be82d 100644 --- a/parser/query.go +++ b/parser/query.go @@ -1,10 +1,10 @@ package parser import ( - "github.com/dgraph-io/gqlparser/gqlerror" - "github.com/dgraph-io/gqlparser/lexer" + "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/v2/lexer" - . "github.com/dgraph-io/gqlparser/ast" + . "github.com/dgraph-io/gqlparser/v2/ast" ) func ParseQuery(source *Source) (*QueryDocument, *gqlerror.Error) { diff --git a/parser/query_test.go b/parser/query_test.go index a157f718..b03f94cf 100644 --- a/parser/query_test.go +++ b/parser/query_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser/testrunner" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser/testrunner" ) func TestQueryDocument(t *testing.T) { diff --git a/parser/schema.go b/parser/schema.go index ed8d47a3..c3679cfe 100644 --- a/parser/schema.go +++ b/parser/schema.go @@ -1,9 +1,9 @@ package parser import ( - . "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" - "github.com/dgraph-io/gqlparser/lexer" + . "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/v2/lexer" ) func ParseSchema(source *Source) (*SchemaDocument, *gqlerror.Error) { diff --git a/parser/schema_test.go b/parser/schema_test.go index 674242bc..c66c04ff 100644 --- a/parser/schema_test.go +++ b/parser/schema_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser/testrunner" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser/testrunner" ) func TestSchemaDocument(t *testing.T) { diff --git a/parser/testrunner/runner.go b/parser/testrunner/runner.go index 7ca78a45..6deb4819 100644 --- a/parser/testrunner/runner.go +++ b/parser/testrunner/runner.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/andreyvit/diff" - "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/v2/gqlerror" "gopkg.in/yaml.v2" ) diff --git a/readme.md b/readme.md index 4d90d1eb..6f8c9a5a 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -gqlparser [![CircleCI](https://badgen.net/circleci/github/dgraph-io/gqlparser/master)](https://circleci.com/gh/dgraph-io/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/dgraph-io/gqlparser)](https://goreportcard.com/report/github.com/dgraph-io/gqlparser) [![Coverage Status](https://badgen.net/coveralls/c/github/dgraph-io/gqlparser)](https://coveralls.io/github/dgraph-io/gqlparser?branch=master) +gqlparser [![CircleCI](https://badgen.net/circleci/github/dgraph-io/gqlparser/v2/master)](https://circleci.com/gh/dgraph-io/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/dgraph-io/gqlparser)](https://goreportcard.com/report/github.com/dgraph-io/gqlparser) [![Coverage Status](https://badgen.net/coveralls/c/github/dgraph-io/gqlparser)](https://coveralls.io/github/dgraph-io/gqlparser?branch=master) === This is a parser for graphql, written to mirror the graphql-js reference implementation as closely while remaining idiomatic and easy to use. diff --git a/validator/error.go b/validator/error.go index 983e1b96..dd916dcc 100644 --- a/validator/error.go +++ b/validator/error.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" ) type ErrorOption func(err *gqlerror.Error) diff --git a/validator/imported_test.go b/validator/imported_test.go index 61de910e..2f770fa4 100644 --- a/validator/imported_test.go +++ b/validator/imported_test.go @@ -11,10 +11,10 @@ import ( "strings" "testing" + "github.com/dgraph-io/gqlparser/v2" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" "github.com/stretchr/testify/require" - "github.com/dgraph-io/gqlparser" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" "gopkg.in/yaml.v2" ) diff --git a/validator/prelude.go b/validator/prelude.go index 08ce53f5..c75d44d2 100644 --- a/validator/prelude.go +++ b/validator/prelude.go @@ -1,6 +1,6 @@ package validator -import "github.com/dgraph-io/gqlparser/ast" +import "github.com/dgraph-io/gqlparser/v2/ast" var Prelude = &ast.Source{ Name: "prelude.graphql", diff --git a/validator/rules/fields_on_correct_type.go b/validator/rules/fields_on_correct_type.go index 944b9e29..e9dc25c6 100644 --- a/validator/rules/fields_on_correct_type.go +++ b/validator/rules/fields_on_correct_type.go @@ -4,8 +4,8 @@ import ( "fmt" "sort" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/fragments_on_composite_types.go b/validator/rules/fragments_on_composite_types.go index fddad16b..4ea69cca 100644 --- a/validator/rules/fragments_on_composite_types.go +++ b/validator/rules/fragments_on_composite_types.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_argument_names.go b/validator/rules/known_argument_names.go index ef9e3ee7..cb2949fc 100644 --- a/validator/rules/known_argument_names.go +++ b/validator/rules/known_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_directives.go b/validator/rules/known_directives.go index 8cc73872..0e42e0d5 100644 --- a/validator/rules/known_directives.go +++ b/validator/rules/known_directives.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_fragment_names.go b/validator/rules/known_fragment_names.go index 78b8d14e..c4638c93 100644 --- a/validator/rules/known_fragment_names.go +++ b/validator/rules/known_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_type_names.go b/validator/rules/known_type_names.go index 0cc5cae6..2901dfec 100644 --- a/validator/rules/known_type_names.go +++ b/validator/rules/known_type_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/lone_anonymous_operation.go b/validator/rules/lone_anonymous_operation.go index 83f26b9c..e6c7beec 100644 --- a/validator/rules/lone_anonymous_operation.go +++ b/validator/rules/lone_anonymous_operation.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_fragment_cycles.go b/validator/rules/no_fragment_cycles.go index d7c0bd0a..727d8e17 100644 --- a/validator/rules/no_fragment_cycles.go +++ b/validator/rules/no_fragment_cycles.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_undefined_variables.go b/validator/rules/no_undefined_variables.go index 9755cb06..82eab4be 100644 --- a/validator/rules/no_undefined_variables.go +++ b/validator/rules/no_undefined_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_unused_fragments.go b/validator/rules/no_unused_fragments.go index 5d8d9fd1..0dad6c76 100644 --- a/validator/rules/no_unused_fragments.go +++ b/validator/rules/no_unused_fragments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_unused_variables.go b/validator/rules/no_unused_variables.go index cf19bbc6..b71b40ce 100644 --- a/validator/rules/no_unused_variables.go +++ b/validator/rules/no_unused_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/overlapping_fields_can_be_merged.go b/validator/rules/overlapping_fields_can_be_merged.go index 7c7264ff..d95093e2 100644 --- a/validator/rules/overlapping_fields_can_be_merged.go +++ b/validator/rules/overlapping_fields_can_be_merged.go @@ -5,8 +5,8 @@ import ( "fmt" "reflect" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/possible_fragment_spreads.go b/validator/rules/possible_fragment_spreads.go index b3cba7ee..8881822d 100644 --- a/validator/rules/possible_fragment_spreads.go +++ b/validator/rules/possible_fragment_spreads.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/provided_required_arguments.go b/validator/rules/provided_required_arguments.go index 49d49f14..455aad7c 100644 --- a/validator/rules/provided_required_arguments.go +++ b/validator/rules/provided_required_arguments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/scalar_leafs.go b/validator/rules/scalar_leafs.go index 783b0577..55155fdf 100644 --- a/validator/rules/scalar_leafs.go +++ b/validator/rules/scalar_leafs.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/single_field_subscriptions.go b/validator/rules/single_field_subscriptions.go index a3c3b14e..4663128b 100644 --- a/validator/rules/single_field_subscriptions.go +++ b/validator/rules/single_field_subscriptions.go @@ -3,8 +3,8 @@ package validator import ( "strconv" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_argument_names.go b/validator/rules/unique_argument_names.go index 03b4f54d..624180ff 100644 --- a/validator/rules/unique_argument_names.go +++ b/validator/rules/unique_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_directives_per_location.go b/validator/rules/unique_directives_per_location.go index bb7b8b13..3b2f4149 100644 --- a/validator/rules/unique_directives_per_location.go +++ b/validator/rules/unique_directives_per_location.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_fragment_names.go b/validator/rules/unique_fragment_names.go index b742536b..736494c4 100644 --- a/validator/rules/unique_fragment_names.go +++ b/validator/rules/unique_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_input_field_names.go b/validator/rules/unique_input_field_names.go index d7bf4824..f4131d31 100644 --- a/validator/rules/unique_input_field_names.go +++ b/validator/rules/unique_input_field_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_operation_names.go b/validator/rules/unique_operation_names.go index 023882a6..8b4681de 100644 --- a/validator/rules/unique_operation_names.go +++ b/validator/rules/unique_operation_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_variable_names.go b/validator/rules/unique_variable_names.go index ca003272..c0252db6 100644 --- a/validator/rules/unique_variable_names.go +++ b/validator/rules/unique_variable_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/values_of_correct_type.go b/validator/rules/values_of_correct_type.go index 75fb7d2c..06af3cbb 100644 --- a/validator/rules/values_of_correct_type.go +++ b/validator/rules/values_of_correct_type.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/variables_are_input_types.go b/validator/rules/variables_are_input_types.go index 123d4ccf..a1353663 100644 --- a/validator/rules/variables_are_input_types.go +++ b/validator/rules/variables_are_input_types.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/variables_in_allowed_position.go b/validator/rules/variables_in_allowed_position.go index abce1c1c..0445e847 100644 --- a/validator/rules/variables_in_allowed_position.go +++ b/validator/rules/variables_in_allowed_position.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/ast" - . "github.com/dgraph-io/gqlparser/validator" + "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/dgraph-io/gqlparser/v2/validator" ) func init() { diff --git a/validator/schema.go b/validator/schema.go index 59a3b06f..4f482fec 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -6,9 +6,9 @@ import ( "strconv" "strings" - . "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" - "github.com/dgraph-io/gqlparser/parser" + . "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/dgraph-io/gqlparser/v2/parser" ) func LoadSchema(inputs ...*Source) (*Schema, *gqlerror.Error) { @@ -40,8 +40,8 @@ func ValidateSchemaDocument(ast *SchemaDocument) (*Schema, *gqlerror.Error) { def := schema.Types[ext.Name] if def == nil { schema.Types[ext.Name] = &Definition{ - Kind: ext.Kind, - Name: ext.Name, + Kind: ext.Kind, + Name: ext.Name, Position: ext.Position, } def = schema.Types[ext.Name] diff --git a/validator/schema_test.go b/validator/schema_test.go index 99ac0762..6eb0324f 100644 --- a/validator/schema_test.go +++ b/validator/schema_test.go @@ -4,9 +4,9 @@ import ( "io/ioutil" "testing" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser/testrunner" "github.com/stretchr/testify/require" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser/testrunner" ) func TestLoadSchema(t *testing.T) { diff --git a/validator/validator.go b/validator/validator.go index cb0d0c09..e26875b1 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -1,8 +1,8 @@ package validator import ( - . "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" + . "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" ) type AddErrFunc func(options ...ErrorOption) diff --git a/validator/validator_test.go b/validator/validator_test.go index 2ea024bd..824f4dec 100644 --- a/validator/validator_test.go +++ b/validator/validator_test.go @@ -3,11 +3,11 @@ package validator_test import ( "testing" + "github.com/dgraph-io/gqlparser/v2" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser" + "github.com/dgraph-io/gqlparser/v2/validator" "github.com/stretchr/testify/require" - "github.com/vektah/gqlparser/v2" - "github.com/vektah/gqlparser/v2/ast" - "github.com/vektah/gqlparser/v2/parser" - "github.com/vektah/gqlparser/v2/validator" ) func TestExtendingNonExistantTypes(t *testing.T) { diff --git a/validator/vars.go b/validator/vars.go index 676975f1..c0fcdbb0 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -6,8 +6,8 @@ import ( "fmt" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/gqlerror" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" ) var UnexpectedType = fmt.Errorf("Unexpected Type") diff --git a/validator/vars_test.go b/validator/vars_test.go index c7025244..47b41fff 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -6,10 +6,10 @@ import ( "encoding/json" + "github.com/dgraph-io/gqlparser/v2" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/validator" "github.com/stretchr/testify/require" - "github.com/dgraph-io/gqlparser" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/validator" ) func TestValidateVars(t *testing.T) { diff --git a/validator/walk.go b/validator/walk.go index ea4f0db4..d8e06724 100644 --- a/validator/walk.go +++ b/validator/walk.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/dgraph-io/gqlparser/ast" + "github.com/dgraph-io/gqlparser/v2/ast" ) type Events struct { diff --git a/validator/walk_test.go b/validator/walk_test.go index 8fed399c..6c2e8731 100644 --- a/validator/walk_test.go +++ b/validator/walk_test.go @@ -3,9 +3,9 @@ package validator import ( "testing" + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/parser" "github.com/stretchr/testify/require" - "github.com/dgraph-io/gqlparser/ast" - "github.com/dgraph-io/gqlparser/parser" ) func TestWalker(t *testing.T) { From 8dcf91975b30c00625b2d478cb93f598ec32aa31 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 3 Nov 2020 14:03:54 +0530 Subject: [PATCH 03/25] added code and test for array coercing --- validator/testdata/vars.graphql | 7 +++- validator/vars.go | 69 ++++++++++++++++----------------- validator/vars_test.go | 29 ++++++++++++-- 3 files changed, 64 insertions(+), 41 deletions(-) diff --git a/validator/testdata/vars.graphql b/validator/testdata/vars.graphql index 51666489..5609d66d 100644 --- a/validator/testdata/vars.graphql +++ b/validator/testdata/vars.graphql @@ -12,6 +12,7 @@ type Query { intArrayArg(i: [Int]): Boolean! stringArrayArg(i: [String]): Boolean! boolArrayArg(i: [Boolean]): Boolean! + typeArrayArg(i: [CustomType]): Boolean! } input InputType { @@ -26,8 +27,12 @@ input Embedded { name: String! } +input CustomType { + and: [Int!] +} + enum Enum { A } -scalar Custom +scalar Custom \ No newline at end of file diff --git a/validator/vars.go b/validator/vars.go index c0fcdbb0..b7ba0f25 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -54,17 +54,16 @@ func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables m rv = rv.Elem() } - if err := validator.validateVarType(v.Type, rv); err != nil { + rval, err := validator.validateVarType(v.Type, rv) + if err != nil { return nil, err } - - coercedVars[v.Variable] = val + coercedVars[v.Variable] = rval.Interface() } } validator.path = validator.path[0 : len(validator.path)-1] } - return coercedVars, nil } @@ -73,38 +72,37 @@ type varValidator struct { schema *ast.Schema } -func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerror.Error { +func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflect.Value, *gqlerror.Error) { currentPath := v.path resetPath := func() { v.path = currentPath } defer resetPath() - if typ.Elem != nil { if val.Kind() != reflect.Slice { - return gqlerror.ErrorPathf(v.path, "must be an array") + // GraphQL spec says that non-null values should be coerced to an array when possible. + // Hence if the value is not a slice, we create a slice and add val to it. + slc := reflect.MakeSlice(reflect.SliceOf(val.Type()), 0, 0) + slc = reflect.Append(slc, val) + val = slc } - for i := 0; i < val.Len(); i++ { resetPath() v.path = append(v.path, ast.PathIndex(i)) field := val.Index(i) - if field.Kind() == reflect.Ptr || field.Kind() == reflect.Interface { if typ.Elem.NonNull && field.IsNil() { - return gqlerror.ErrorPathf(v.path, "cannot be null") + return val, gqlerror.ErrorPathf(v.path, "cannot be null") } field = field.Elem() } - - if err := v.validateVarType(typ.Elem, field); err != nil { - return err + _, err := v.validateVarType(typ.Elem, field) + if err != nil { + return val, err } } - - return nil + return val, nil } - def := v.schema.Types[typ.NamedType] if def == nil { panic(fmt.Errorf("missing def for %s", typ.NamedType)) @@ -112,14 +110,14 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr if !typ.NonNull && !val.IsValid() { // If the type is not null and we got a invalid value namely null/nil, then it's valid - return nil + return val, nil } switch def.Kind { case ast.Enum: kind := val.Type().Kind() if kind != reflect.Int && kind != reflect.Int32 && kind != reflect.Int64 && kind != reflect.String { - return gqlerror.ErrorPathf(v.path, "enums must be ints or strings") + return val, gqlerror.ErrorPathf(v.path, "enums must be ints or strings") } isValidEnum := false for _, enumVal := range def.EnumValues { @@ -128,42 +126,42 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr } } if !isValidEnum { - return gqlerror.ErrorPathf(v.path, "%s is not a valid %s", val.String(), def.Name) + return val, gqlerror.ErrorPathf(v.path, "%s is not a valid %s", val.String(), def.Name) } - return nil + return val, nil case ast.Scalar: kind := val.Type().Kind() switch typ.NamedType { case "Int": if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { - return nil + return val, nil } case "Float": if kind == reflect.String || kind == reflect.Float32 || kind == reflect.Float64 || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { - return nil + return val, nil } case "String": if kind == reflect.String { - return nil + return val, nil } case "Boolean": if kind == reflect.Bool { - return nil + return val, nil } case "ID": if kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 || kind == reflect.String { - return nil + return val, nil } default: // assume custom scalars are ok - return nil + return val, nil } - return gqlerror.ErrorPathf(v.path, "cannot use %s as %s", kind.String(), typ.NamedType) + return val, gqlerror.ErrorPathf(v.path, "cannot use %s as %s", kind.String(), typ.NamedType) case ast.InputObject: if val.Kind() != reflect.Map { - return gqlerror.ErrorPathf(v.path, "must be a %s", def.Name) + return val, gqlerror.ErrorPathf(v.path, "must be a %s", def.Name) } // check for unknown fields @@ -174,7 +172,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr v.path = append(v.path, ast.PathName(name.String())) if fieldDef == nil { - return gqlerror.ErrorPathf(v.path, "unknown field") + return val, gqlerror.ErrorPathf(v.path, "unknown field") } } @@ -192,14 +190,14 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr continue } } - return gqlerror.ErrorPathf(v.path, "must be defined") + return val, gqlerror.ErrorPathf(v.path, "must be defined") } continue } if field.Kind() == reflect.Ptr || field.Kind() == reflect.Interface { if fieldDef.Type.NonNull && field.IsNil() { - return gqlerror.ErrorPathf(v.path, "cannot be null") + return val, gqlerror.ErrorPathf(v.path, "cannot be null") } //allow null object field and skip it if !fieldDef.Type.NonNull && field.IsNil() { @@ -207,15 +205,14 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) *gqlerr } field = field.Elem() } - - err := v.validateVarType(fieldDef.Type, field) + cval, err := v.validateVarType(fieldDef.Type, field) if err != nil { - return err + return val, err } + val.SetMapIndex(reflect.ValueOf(fieldDef.Name), cval) } default: panic(fmt.Errorf("unsupported type %s", def.Kind)) } - - return nil + return val, nil } diff --git a/validator/vars_test.go b/validator/vars_test.go index 47b41fff..a1807901 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -151,12 +151,33 @@ func TestValidateVars(t *testing.T) { }) t.Run("array", func(t *testing.T) { - t.Run("non array", func(t *testing.T) { + t.Run("non-null object value should be coerced to an array", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: [InputType!]) { arrayArg(i: $var) }`) - _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ - "var": "hello", + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": map[string]interface{}{"name": "hello"}, + }) + require.Nil(t, gerr) + require.EqualValues(t, []map[string]interface{}{{"name": "hello"}}, vars["var"]) + }) + + t.Run("non-null int value should be coerced to an array", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: [Int!]) { intArrayArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": 5, }) - require.EqualError(t, gerr, "input: variable.var must be an array") + require.Nil(t, gerr) + expected := []int{5} + require.EqualValues(t, expected, vars["var"]) + }) + + t.Run("non-null int deep value should be coerced to an array", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: [CustomType]) { typeArrayArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": []map[string]interface{}{{"and": 5}}, + }) + require.Nil(t, gerr) + expected := []map[string]interface{}{{"and": []int{5}}} + require.EqualValues(t, expected, vars["var"]) }) t.Run("defaults", func(t *testing.T) { From b296ca2145bea28b854924ce98240c948c9c7899 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Mon, 14 Dec 2020 11:48:36 +0530 Subject: [PATCH 04/25] changed slice type to interface --- validator/vars.go | 9 ++++----- validator/vars_test.go | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index b7ba0f25..a68b1538 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -10,8 +10,6 @@ import ( "github.com/dgraph-io/gqlparser/v2/gqlerror" ) -var UnexpectedType = fmt.Errorf("Unexpected Type") - // VariableValues coerces and validates variable values func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables map[string]interface{}) (map[string]interface{}, *gqlerror.Error) { coercedVars := map[string]interface{}{} @@ -82,9 +80,10 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec if val.Kind() != reflect.Slice { // GraphQL spec says that non-null values should be coerced to an array when possible. // Hence if the value is not a slice, we create a slice and add val to it. - slc := reflect.MakeSlice(reflect.SliceOf(val.Type()), 0, 0) - slc = reflect.Append(slc, val) - val = slc + slc := make([]interface{}, 0) + slc = append(slc, val.Interface()) + val = reflect.ValueOf(slc) + val.Convert(val.Type()) } for i := 0; i < val.Len(); i++ { resetPath() diff --git a/validator/vars_test.go b/validator/vars_test.go index a1807901..eb7a17c2 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -157,7 +157,7 @@ func TestValidateVars(t *testing.T) { "var": map[string]interface{}{"name": "hello"}, }) require.Nil(t, gerr) - require.EqualValues(t, []map[string]interface{}{{"name": "hello"}}, vars["var"]) + require.EqualValues(t, []interface{}{map[string]interface{}{"name": "hello"}}, vars["var"]) }) t.Run("non-null int value should be coerced to an array", func(t *testing.T) { @@ -166,7 +166,7 @@ func TestValidateVars(t *testing.T) { "var": 5, }) require.Nil(t, gerr) - expected := []int{5} + expected := []interface{}{5} require.EqualValues(t, expected, vars["var"]) }) @@ -176,7 +176,7 @@ func TestValidateVars(t *testing.T) { "var": []map[string]interface{}{{"and": 5}}, }) require.Nil(t, gerr) - expected := []map[string]interface{}{{"and": []int{5}}} + expected := []map[string]interface{}{{"and": []interface{}{5}}} require.EqualValues(t, expected, vars["var"]) }) From 479ab4dc8cf95074b73d310e83f7cbe6a2fbd062 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Mon, 18 Jan 2021 15:00:09 +0530 Subject: [PATCH 05/25] added input coercion to string for ID types --- validator/testdata/vars.graphql | 1 + validator/vars.go | 25 +++++++++++++++++++------ validator/vars_test.go | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/validator/testdata/vars.graphql b/validator/testdata/vars.graphql index 5609d66d..fccc7b1c 100644 --- a/validator/testdata/vars.graphql +++ b/validator/testdata/vars.graphql @@ -10,6 +10,7 @@ type Query { defaultStructArg(i: InputType! = {name: "foo"}): Boolean! arrayArg(i: [InputType!]): Boolean! intArrayArg(i: [Int]): Boolean! + idArrayArg(i: [ID]): Boolean! stringArrayArg(i: [String]): Boolean! boolArrayArg(i: [Boolean]): Boolean! typeArrayArg(i: [CustomType]): Boolean! diff --git a/validator/vars.go b/validator/vars.go index a68b1538..aab270cd 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -76,15 +76,20 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec v.path = currentPath } defer resetPath() + slc := make([]interface{}, 0) if typ.Elem != nil { if val.Kind() != reflect.Slice { // GraphQL spec says that non-null values should be coerced to an array when possible. // Hence if the value is not a slice, we create a slice and add val to it. - slc := make([]interface{}, 0) - slc = append(slc, val.Interface()) + if typ.Name() == "ID" { + val = val.Convert((reflect.ValueOf("string")).Type()) + slc = append(slc, val.String()) + } else { + slc = append(slc, val.Interface()) + } val = reflect.ValueOf(slc) - val.Convert(val.Type()) } + slc = []interface{}{} for i := 0; i < val.Len(); i++ { resetPath() v.path = append(v.path, ast.PathIndex(i)) @@ -95,11 +100,18 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec } field = field.Elem() } - _, err := v.validateVarType(typ.Elem, field) + cVal, err := v.validateVarType(typ.Elem, field) + if typ.Name() == "ID" { + cVal = cVal.Convert((reflect.ValueOf("string")).Type()) + slc = append(slc, cVal.String()) + } if err != nil { return val, err } } + if typ.Name() == "ID" { + val = reflect.ValueOf(slc) + } return val, nil } def := v.schema.Types[typ.NamedType] @@ -151,6 +163,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec case "ID": if kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 || kind == reflect.String { + val = val.Convert((reflect.ValueOf("string")).Type()) return val, nil } default: @@ -204,11 +217,11 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec } field = field.Elem() } - cval, err := v.validateVarType(fieldDef.Type, field) + cVal, err := v.validateVarType(fieldDef.Type, field) if err != nil { return val, err } - val.SetMapIndex(reflect.ValueOf(fieldDef.Name), cval) + val.SetMapIndex(reflect.ValueOf(fieldDef.Name), cVal) } default: panic(fmt.Errorf("unsupported type %s", def.Kind)) diff --git a/validator/vars_test.go b/validator/vars_test.go index eb7a17c2..aa8b8ed5 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -170,6 +170,26 @@ func TestValidateVars(t *testing.T) { require.EqualValues(t, expected, vars["var"]) }) + t.Run("int value should be coerced to string array when required type is [ID]", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: [ID]) { idArrayArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": 5, + }) + require.Nil(t, gerr) + expected := []interface{}{"\x05"} + require.EqualValues(t, expected, vars["var"]) + }) + + t.Run("int array should be coerced to string array when required type is [ID]", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: [ID]) { idArrayArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": []interface{}{5, 6}, + }) + require.Nil(t, gerr) + expected := []interface{}{"\x05", "\x06"} + require.EqualValues(t, expected, vars["var"]) + }) + t.Run("non-null int deep value should be coerced to an array", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: [CustomType]) { typeArrayArg(i: $var) }`) vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ From 159060472cf0bf3e69d0ca51899fea3086b50f89 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Tue, 19 Jan 2021 23:06:08 +0530 Subject: [PATCH 06/25] clean code and added test for single ID case --- validator/vars.go | 22 +++++++++++++--------- validator/vars_test.go | 10 ++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index aab270cd..a76271f7 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -81,10 +81,10 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec if val.Kind() != reflect.Slice { // GraphQL spec says that non-null values should be coerced to an array when possible. // Hence if the value is not a slice, we create a slice and add val to it. - if typ.Name() == "ID" { + if typ.Name() == "ID" && val.Type().Name() != "string" { val = val.Convert((reflect.ValueOf("string")).Type()) slc = append(slc, val.String()) - } else { + } else if typ.Name() != "ID" { slc = append(slc, val.Interface()) } val = reflect.ValueOf(slc) @@ -100,10 +100,12 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec } field = field.Elem() } - cVal, err := v.validateVarType(typ.Elem, field) - if typ.Name() == "ID" { - cVal = cVal.Convert((reflect.ValueOf("string")).Type()) - slc = append(slc, cVal.String()) + cval, err := v.validateVarType(typ.Elem, field) + if typ.Name() == "ID" && val.Type().Name() != "string" { + cval = cval.Convert((reflect.ValueOf("string")).Type()) + slc = append(slc, cval.String()) + } else if typ.Name() == "ID" { + slc = append(slc, cval.String()) } if err != nil { return val, err @@ -163,7 +165,9 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec case "ID": if kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 || kind == reflect.String { - val = val.Convert((reflect.ValueOf("string")).Type()) + if val.Type().Name() != "string" { + val = val.Convert((reflect.ValueOf("string")).Type()) + } return val, nil } default: @@ -217,11 +221,11 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec } field = field.Elem() } - cVal, err := v.validateVarType(fieldDef.Type, field) + cval, err := v.validateVarType(fieldDef.Type, field) if err != nil { return val, err } - val.SetMapIndex(reflect.ValueOf(fieldDef.Name), cVal) + val.SetMapIndex(reflect.ValueOf(fieldDef.Name), cval) } default: panic(fmt.Errorf("unsupported type %s", def.Kind)) diff --git a/validator/vars_test.go b/validator/vars_test.go index aa8b8ed5..8d6bd710 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -200,6 +200,16 @@ func TestValidateVars(t *testing.T) { require.EqualValues(t, expected, vars["var"]) }) + t.Run("int value will be converted to string when required type is ID", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: ID!) { idArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": 5, + }) + require.Nil(t, gerr) + expected := "\x05" + require.EqualValues(t, expected, vars["var"]) + }) + t.Run("defaults", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: [InputType!] = [{name: "foo"}]) { arrayArg(i: $var) }`) vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), nil) From 41867a0d8676bda10fa41422ce535d64c0cda33f Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 21 Jan 2021 14:34:40 +0530 Subject: [PATCH 07/25] removed extra check --- validator/vars.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/vars.go b/validator/vars.go index a76271f7..e0764933 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -84,7 +84,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec if typ.Name() == "ID" && val.Type().Name() != "string" { val = val.Convert((reflect.ValueOf("string")).Type()) slc = append(slc, val.String()) - } else if typ.Name() != "ID" { + } else { slc = append(slc, val.Interface()) } val = reflect.ValueOf(slc) From a39ba99aad14d20436d6e08d4cd55488c3be4762 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 21 Jan 2021 14:44:48 +0530 Subject: [PATCH 08/25] added test --- validator/vars_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/validator/vars_test.go b/validator/vars_test.go index 8d6bd710..a09df501 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -180,6 +180,16 @@ func TestValidateVars(t *testing.T) { require.EqualValues(t, expected, vars["var"]) }) + t.Run("single string value should be coerced to string array when required type is [ID]", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: [ID]) { idArrayArg(i: $var) }`) + vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": "5", + }) + require.Nil(t, gerr) + expected := []interface{}{"5"} + require.EqualValues(t, expected, vars["var"]) + }) + t.Run("int array should be coerced to string array when required type is [ID]", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: [ID]) { idArrayArg(i: $var) }`) vars, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ From 83d89f44043507b2d627051d58da384c2d9738ce Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 21 Jan 2021 15:20:48 +0530 Subject: [PATCH 09/25] reformat code a bit --- validator/vars.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index e0764933..cdf83110 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -101,10 +101,10 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec field = field.Elem() } cval, err := v.validateVarType(typ.Elem, field) - if typ.Name() == "ID" && val.Type().Name() != "string" { - cval = cval.Convert((reflect.ValueOf("string")).Type()) - slc = append(slc, cval.String()) - } else if typ.Name() == "ID" { + if typ.Name() == "ID" { + if val.Type().Name() != "string" { + cval = cval.Convert((reflect.ValueOf("string")).Type()) + } slc = append(slc, cval.String()) } if err != nil { From f73942d68ed03175e464087512df2d832b753f58 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Sun, 7 Feb 2021 22:17:47 +0530 Subject: [PATCH 10/25] added code for Int input coercion and tests --- validator/vars.go | 25 ++++++++++++++++++++++++- validator/vars_test.go | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/validator/vars.go b/validator/vars.go index cdf83110..9ae59bb1 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -1,7 +1,9 @@ package validator import ( + "errors" "reflect" + "strconv" "strings" "fmt" @@ -145,10 +147,31 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec case ast.Scalar: kind := val.Type().Kind() switch typ.NamedType { - case "Int": + case "Int", "Int64": if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { + var errIntCoerce error + var valString string + if kind == reflect.String { + valString = val.String() + } else { + valString = strconv.FormatInt(val.Int(), 10) + } + if typ.NamedType == "Int" { + _, errIntCoerce = strconv.ParseInt(valString, 10, 32) + } else { + _, errIntCoerce = strconv.ParseInt(valString, 10, 64) + } + if errIntCoerce != nil { + if errors.Is(errIntCoerce, strconv.ErrRange) { + return val, gqlerror.ErrorPathf(v.path, "Out of range value '%s', for type `%s`", valString, typ.NamedType) + + } else { + return val, gqlerror.ErrorPathf(v.path, "Type mismatched for Value `%s`, expected:`%s`", valString, typ.NamedType) + } + } return val, nil } + case "Float": if kind == reflect.String || kind == reflect.Float32 || kind == reflect.Float64 || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { return val, nil diff --git a/validator/vars_test.go b/validator/vars_test.go index a09df501..0084d629 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -334,6 +334,22 @@ func TestValidateVars(t *testing.T) { }) require.EqualError(t, gerr, "input: variable.var cannot use bool as Int") }) + + t.Run("error for invalid coercing like Float -> Int", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`) + _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": 18.0, + }) + require.EqualError(t, gerr, "input: variable.var cannot use float64 as Int") + }) + + t.Run("out of range error for Int", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`) + _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": 2147483648, + }) + require.EqualError(t, gerr, "input: variable.var Out of range value '2147483648', for type `Int`") + }) }) t.Run("Int Array", func(t *testing.T) { From 3a9b1f56df400547fcb806a673001aab8d334b62 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 12 Feb 2021 12:48:11 +0530 Subject: [PATCH 11/25] added test for int64 out of range --- validator/testdata/vars.graphql | 3 +++ validator/vars_test.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/validator/testdata/vars.graphql b/validator/testdata/vars.graphql index fccc7b1c..ab8043e2 100644 --- a/validator/testdata/vars.graphql +++ b/validator/testdata/vars.graphql @@ -1,6 +1,7 @@ type Query { optionalIntArg(i: Int): Boolean! intArg(i: Int!): Boolean! + int64Arg(i: Int64!): Boolean! stringArg(i: String): Boolean! boolArg(i: Boolean!): Boolean! floatArg(i: Float!): Boolean! @@ -16,6 +17,8 @@ type Query { typeArrayArg(i: [CustomType]): Boolean! } +scalar Int64 + input InputType { name: String! nullName: String diff --git a/validator/vars_test.go b/validator/vars_test.go index 0084d629..9e83da5b 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -350,8 +350,15 @@ func TestValidateVars(t *testing.T) { }) require.EqualError(t, gerr, "input: variable.var Out of range value '2147483648', for type `Int`") }) - }) + t.Run("out of range error for Int64", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: Int64!) { int64Arg(i: $var) }`) + _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": "9223372036854775808", + }) + require.EqualError(t, gerr, "input: variable.var Out of range value '9223372036854775808', for type `Int64`") + }) + }) t.Run("Int Array", func(t *testing.T) { t.Run("Array with null", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: [Int]) { intArrayArg(i: $var) }`) From 3521f3909932fd8c6c86459caed93908bd221396 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Wed, 24 Feb 2021 13:25:42 +0530 Subject: [PATCH 12/25] added validation for parameterized cascade arguments present in variables --- validator/vars.go | 64 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index 9ae59bb1..b5b13bb3 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -2,14 +2,12 @@ package validator import ( "errors" - "reflect" - "strconv" - "strings" - "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" "github.com/dgraph-io/gqlparser/v2/gqlerror" + "reflect" + "strconv" + "strings" ) // VariableValues coerces and validates variable values @@ -59,14 +57,70 @@ func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables m return nil, err } coercedVars[v.Variable] = rval.Interface() + } } validator.path = validator.path[0 : len(validator.path)-1] } + // cascade directive arguments validation + if op.VariableDefinitions != nil { + err := validator.cascadeDirectiveValidation(op, op.SelectionSet, variables) + if err != nil { + return nil, err + } + } return coercedVars, nil } +func (v *varValidator) cascadeDirectiveValidation(op *ast.OperationDefinition, sel ast.SelectionSet, variables map[string]interface{}) *gqlerror.Error { + + for _, s := range sel { + if f, ok := s.(*ast.Field); ok { + cascadedir := f.Directives.ForName("cascade") + if cascadedir == nil { + continue + } + if len(cascadedir.Arguments) == 1 { + if cascadedir.ParentDefinition == nil { + return gqlerror.Errorf("Schema is not set yet. Please try after sometime.") + } + } + if cascadedir.Arguments.ForName("fields") == nil { + continue + } + fieldArg := cascadedir.Arguments.ForName("fields") + isVariable := strings.HasPrefix(fieldArg.Value.String(), "$") + if !isVariable { + continue + } + + varName := op.VariableDefinitions.ForName(cascadedir.Arguments.ForName("fields").Value.Raw) + v.path = append(v.path, ast.PathName(varName.Variable)) + if cascadedir.ArgumentMap(variables)["fields"] == nil { + return gqlerror.ErrorPathf(v.path, "variable %s not defined", varName.Variable) + } + + variableVal := cascadedir.ArgumentMap(variables)["fields"].([]interface{}) + typFields := cascadedir.ParentDefinition.Fields + typName := cascadedir.ParentDefinition.Name + for _, val := range variableVal { + if typFields.ForName(val.(string)) == nil { + v.path = append(v.path, ast.PathName(val.(string))) + return gqlerror.ErrorPathf(v.path, "Field `%s` is not present in type `%s`."+ + " You can only use fields which are in type `%s`", val, typName, typName) + } + } + v.path = v.path[0 : len(v.path)-1] + err := v.cascadeDirectiveValidation(op, f.SelectionSet, variables) + if err != nil { + return err + } + } + } + return nil +} + type varValidator struct { path ast.Path schema *ast.Schema From a86723d5bfe77b0e02d8e3f0e2a29bd73d66ea05 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Wed, 24 Feb 2021 13:35:08 +0530 Subject: [PATCH 13/25] format imports --- validator/vars.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index b5b13bb3..2c8d8423 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -3,11 +3,12 @@ package validator import ( "errors" "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" "reflect" "strconv" "strings" + + "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/dgraph-io/gqlparser/v2/gqlerror" ) // VariableValues coerces and validates variable values From 45e53e46e0b8e52fcfc1e01116068dba8c70e008 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 25 Feb 2021 10:30:05 +0530 Subject: [PATCH 14/25] support variables in validation hooks --- validator/validator.go | 4 +-- validator/vars.go | 55 ------------------------------------------ validator/walk.go | 13 +++++----- validator/walk_test.go | 4 +-- 4 files changed, 11 insertions(+), 65 deletions(-) diff --git a/validator/validator.go b/validator/validator.go index e26875b1..e145e570 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -22,7 +22,7 @@ func AddRule(name string, f ruleFunc) { rules = append(rules, rule{name: name, rule: f}) } -func Validate(schema *Schema, doc *QueryDocument) gqlerror.List { +func Validate(schema *Schema, doc *QueryDocument, variables map[string]interface{}) gqlerror.List { var errs gqlerror.List observers := &Events{} @@ -39,6 +39,6 @@ func Validate(schema *Schema, doc *QueryDocument) gqlerror.List { }) } - Walk(schema, doc, observers) + Walk(schema, doc, observers, variables) return errs } diff --git a/validator/vars.go b/validator/vars.go index 2c8d8423..9665c9f8 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -64,64 +64,9 @@ func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables m validator.path = validator.path[0 : len(validator.path)-1] } - // cascade directive arguments validation - if op.VariableDefinitions != nil { - err := validator.cascadeDirectiveValidation(op, op.SelectionSet, variables) - if err != nil { - return nil, err - } - } return coercedVars, nil } -func (v *varValidator) cascadeDirectiveValidation(op *ast.OperationDefinition, sel ast.SelectionSet, variables map[string]interface{}) *gqlerror.Error { - - for _, s := range sel { - if f, ok := s.(*ast.Field); ok { - cascadedir := f.Directives.ForName("cascade") - if cascadedir == nil { - continue - } - if len(cascadedir.Arguments) == 1 { - if cascadedir.ParentDefinition == nil { - return gqlerror.Errorf("Schema is not set yet. Please try after sometime.") - } - } - if cascadedir.Arguments.ForName("fields") == nil { - continue - } - fieldArg := cascadedir.Arguments.ForName("fields") - isVariable := strings.HasPrefix(fieldArg.Value.String(), "$") - if !isVariable { - continue - } - - varName := op.VariableDefinitions.ForName(cascadedir.Arguments.ForName("fields").Value.Raw) - v.path = append(v.path, ast.PathName(varName.Variable)) - if cascadedir.ArgumentMap(variables)["fields"] == nil { - return gqlerror.ErrorPathf(v.path, "variable %s not defined", varName.Variable) - } - - variableVal := cascadedir.ArgumentMap(variables)["fields"].([]interface{}) - typFields := cascadedir.ParentDefinition.Fields - typName := cascadedir.ParentDefinition.Name - for _, val := range variableVal { - if typFields.ForName(val.(string)) == nil { - v.path = append(v.path, ast.PathName(val.(string))) - return gqlerror.ErrorPathf(v.path, "Field `%s` is not present in type `%s`."+ - " You can only use fields which are in type `%s`", val, typName, typName) - } - } - v.path = v.path[0 : len(v.path)-1] - err := v.cascadeDirectiveValidation(op, f.SelectionSet, variables) - if err != nil { - return err - } - } - } - return nil -} - type varValidator struct { path ast.Path schema *ast.Schema diff --git a/validator/walk.go b/validator/walk.go index d8e06724..e8fcc2d9 100644 --- a/validator/walk.go +++ b/validator/walk.go @@ -43,22 +43,23 @@ func (o *Events) OnValue(f func(walker *Walker, value *ast.Value)) { o.value = append(o.value, f) } -func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events) { +func Walk(schema *ast.Schema, document *ast.QueryDocument, observers *Events, variables map[string]interface{}) { w := Walker{ Observers: observers, Schema: schema, Document: document, + Variables: variables, } w.walk() } type Walker struct { - Context context.Context - Observers *Events - Schema *ast.Schema - Document *ast.QueryDocument - + Context context.Context + Observers *Events + Schema *ast.Schema + Document *ast.QueryDocument + Variables map[string]interface{} validatedFragmentSpreads map[string]bool CurrentOperation *ast.OperationDefinition } diff --git a/validator/walk_test.go b/validator/walk_test.go index 6c2e8731..9ac9bf5c 100644 --- a/validator/walk_test.go +++ b/validator/walk_test.go @@ -25,7 +25,7 @@ func TestWalker(t *testing.T) { require.Equal(t, "Query", field.ObjectDefinition.Name) }) - Walk(schema, query, observers) + Walk(schema, query, observers, nil) require.True(t, called) } @@ -46,7 +46,7 @@ func TestWalkInlineFragment(t *testing.T) { require.Equal(t, "Query", field.ObjectDefinition.Name) }) - Walk(schema, query, observers) + Walk(schema, query, observers, nil) require.True(t, called) } From cb06f9b8902285d06c5c5ae1e987751baa625701 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 25 Feb 2021 10:38:57 +0530 Subject: [PATCH 15/25] fix tests --- gqlparser.go | 2 +- validator/validator_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gqlparser.go b/gqlparser.go index f09f1b36..73a5390e 100644 --- a/gqlparser.go +++ b/gqlparser.go @@ -25,7 +25,7 @@ func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.Lis if err != nil { return nil, gqlerror.List{err} } - errs := validator.Validate(schema, query) + errs := validator.Validate(schema, query, nil) if errs != nil { return nil, errs } diff --git a/validator/validator_test.go b/validator/validator_test.go index 824f4dec..9ab400c6 100644 --- a/validator/validator_test.go +++ b/validator/validator_test.go @@ -37,5 +37,5 @@ extend type Query { } }`}) require.Nil(t, err) - require.Nil(t, validator.Validate(s, q)) + require.Nil(t, validator.Validate(s, q, nil)) } From d9375ee07ede2adcf45c63d87a6be415be967827 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Thu, 25 Feb 2021 10:40:11 +0530 Subject: [PATCH 16/25] clean code --- validator/vars.go | 1 - 1 file changed, 1 deletion(-) diff --git a/validator/vars.go b/validator/vars.go index 9665c9f8..2c69d6cb 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -58,7 +58,6 @@ func VariableValues(schema *ast.Schema, op *ast.OperationDefinition, variables m return nil, err } coercedVars[v.Variable] = rval.Interface() - } } From 4e8354aeab481647c2434596e98293028e3a7f5c Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 26 Feb 2021 12:45:45 +0530 Subject: [PATCH 17/25] fixed panic --- validator/vars.go | 3 ++- validator/walk.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/validator/vars.go b/validator/vars.go index 2c69d6cb..52c3de7d 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -145,6 +145,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec return val, nil case ast.Scalar: kind := val.Type().Kind() + namedType := val.Type().Name() switch typ.NamedType { case "Int", "Int64": if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { @@ -176,7 +177,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec return val, nil } case "String": - if kind == reflect.String { + if namedType == "string" { return val, nil } diff --git a/validator/walk.go b/validator/walk.go index e8fcc2d9..e85cd796 100644 --- a/validator/walk.go +++ b/validator/walk.go @@ -59,7 +59,7 @@ type Walker struct { Observers *Events Schema *ast.Schema Document *ast.QueryDocument - Variables map[string]interface{} + Variables map[string]interface{} // These variables are not coerced validatedFragmentSpreads map[string]bool CurrentOperation *ast.OperationDefinition } From 0488d0ae2f02ae64e44ca3c0839c010edbb52927 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Fri, 26 Feb 2021 15:28:57 +0530 Subject: [PATCH 18/25] fix error --- validator/vars.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator/vars.go b/validator/vars.go index 52c3de7d..f671d1b4 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -197,7 +197,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec // assume custom scalars are ok return val, nil } - return val, gqlerror.ErrorPathf(v.path, "cannot use %s as %s", kind.String(), typ.NamedType) + return val, gqlerror.ErrorPathf(v.path, "cannot use %s as %s", namedType, typ.NamedType) case ast.InputObject: if val.Kind() != reflect.Map { return val, gqlerror.ErrorPathf(v.path, "must be a %s", def.Name) From 06de469afa76e060c5d829fbe242c8f025b5b777 Mon Sep 17 00:00:00 2001 From: JatinDevDG Date: Mon, 15 Mar 2021 22:50:42 +0530 Subject: [PATCH 19/25] remove support of string -->int32 coercion --- validator/vars.go | 2 +- validator/vars_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/validator/vars.go b/validator/vars.go index 52c3de7d..e3815055 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -148,7 +148,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec namedType := val.Type().Name() switch typ.NamedType { case "Int", "Int64": - if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 { + if kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 || (namedType == "string" && typ.NamedType == "Int64") || namedType == "Number" { var errIntCoerce error var valString string if kind == reflect.String { diff --git a/validator/vars_test.go b/validator/vars_test.go index 9e83da5b..d063a960 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -343,6 +343,14 @@ func TestValidateVars(t *testing.T) { require.EqualError(t, gerr, "input: variable.var cannot use float64 as Int") }) + t.Run("error for invalid coercing, String -> Int ", func(t *testing.T) { + q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`) + _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ + "var": "18", + }) + require.EqualError(t, gerr, "input: variable.var cannot use string as Int") + }) + t.Run("out of range error for Int", func(t *testing.T) { q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`) _, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{ From d24123fc6ca91bd6461693aa01956199f8cb0f2e Mon Sep 17 00:00:00 2001 From: Anurag Sharma Date: Fri, 19 Mar 2021 13:09:20 +0530 Subject: [PATCH 20/25] fix(Parser): Add Directive argument validator --- validator/schema.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/validator/schema.go b/validator/schema.go index 4f482fec..72499b02 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -289,12 +289,30 @@ func validateArgs(schema *Schema, args ArgumentDefinitionList, currentDirective return nil } +func validateDirectiveArgs(dir *Directive, schema *Schema) *gqlerror.Error { + allowedArgs := make(map[string]struct{}, len(schema.Directives[dir.Name].Arguments)) + for _, arg := range schema.Directives[dir.Name].Arguments { + allowedArgs[arg.Name] = struct{}{} + } + + for _, arg := range dir.Arguments { + if _, ok := allowedArgs[arg.Name]; !ok { + return gqlerror.Errorf("%s is not supported as an argument for %s directive.", arg.Name, dir.Name) + } + } + return nil + +} + func validateDirectives(schema *Schema, dirs DirectiveList, location DirectiveLocation, currentDirective *DirectiveDefinition) *gqlerror.Error { for _, dir := range dirs { if err := validateName(dir.Position, dir.Name); err != nil { // now, GraphQL spec doesn't have reserved directive name return err } + if err := validateDirectiveArgs(dir, schema); err != nil { + return err + } if currentDirective != nil && dir.Name == currentDirective.Name { return gqlerror.ErrorPosf(dir.Position, "Directive %s cannot refer to itself.", currentDirective.Name) } From f3f3532a84f1d1cfc768659bafbeddaa1573d8f0 Mon Sep 17 00:00:00 2001 From: Anurag Sharma Date: Fri, 19 Mar 2021 14:34:33 +0530 Subject: [PATCH 21/25] Add tests --- validator/schema.go | 10 +++++----- validator/schema_test.yml | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/validator/schema.go b/validator/schema.go index 72499b02..25ee7469 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -290,14 +290,14 @@ func validateArgs(schema *Schema, args ArgumentDefinitionList, currentDirective } func validateDirectiveArgs(dir *Directive, schema *Schema) *gqlerror.Error { - allowedArgs := make(map[string]struct{}, len(schema.Directives[dir.Name].Arguments)) + allowedArgs := make(map[string]struct{}) for _, arg := range schema.Directives[dir.Name].Arguments { allowedArgs[arg.Name] = struct{}{} } for _, arg := range dir.Arguments { if _, ok := allowedArgs[arg.Name]; !ok { - return gqlerror.Errorf("%s is not supported as an argument for %s directive.", arg.Name, dir.Name) + return gqlerror.ErrorPosf(dir.Position, "%s is not supported as an argument for %s directive.", arg.Name, dir.Name) } } return nil @@ -310,15 +310,15 @@ func validateDirectives(schema *Schema, dirs DirectiveList, location DirectiveLo // now, GraphQL spec doesn't have reserved directive name return err } - if err := validateDirectiveArgs(dir, schema); err != nil { - return err - } if currentDirective != nil && dir.Name == currentDirective.Name { return gqlerror.ErrorPosf(dir.Position, "Directive %s cannot refer to itself.", currentDirective.Name) } if schema.Directives[dir.Name] == nil { return gqlerror.ErrorPosf(dir.Position, "Undefined directive %s.", dir.Name) } + if err := validateDirectiveArgs(dir, schema); err != nil { + return err + } validKind := false for _, dirLocation := range schema.Directives[dir.Name].Locations { if dirLocation == location { diff --git a/validator/schema_test.yml b/validator/schema_test.yml index 05dba9e0..85373bd9 100644 --- a/validator/schema_test.yml +++ b/validator/schema_test.yml @@ -505,6 +505,16 @@ directives: directive @A(a: Input, b: Scalar, c: Enum) on FIELD_DEFINITION + - name: Valid arg for directive + input: | + type User @include(aggregate: false) { + name: String + } + + error: + message: 'aggregate is not supported as an argument for include directive.' + locations: [{line: 1, column: 12}] + - name: Objects not allowed input: | type Object { id: ID } From 97b20a5117bf57bcd6cf891d35c0f0ab0c58e852 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 31 Aug 2021 11:50:44 +0530 Subject: [PATCH 22/25] chore: adding order to the validation rules --- validator/validator.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/validator/validator.go b/validator/validator.go index e145e570..bd7be340 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -3,6 +3,7 @@ package validator import ( . "github.com/dgraph-io/gqlparser/v2/ast" "github.com/dgraph-io/gqlparser/v2/gqlerror" + "sort" ) type AddErrFunc func(options ...ErrorOption) @@ -11,7 +12,9 @@ type ruleFunc func(observers *Events, addError AddErrFunc) type rule struct { name string - rule ruleFunc + // rules will be called in the ascending order + order int + rule ruleFunc } var rules []rule @@ -22,10 +25,19 @@ func AddRule(name string, f ruleFunc) { rules = append(rules, rule{name: name, rule: f}) } +// AddRuleWithOrder to rule set with an order. +// f is called once each time `Validate` is executed. +func AddRuleWithOrder(name string, order int, f ruleFunc) { + rules = append(rules, rule{name: name, order: order, rule: f}) +} + func Validate(schema *Schema, doc *QueryDocument, variables map[string]interface{}) gqlerror.List { var errs gqlerror.List observers := &Events{} + sort.Slice(rules, func(i, j int) bool { + return rules[i].order < rules[j].order + }) for i := range rules { rule := rules[i] rule.rule(observers, func(options ...ErrorOption) { From 40ef8203b3a37f8ff20c7de5d8409b9b75318650 Mon Sep 17 00:00:00 2001 From: aman-bansal Date: Tue, 31 Aug 2021 11:52:18 +0530 Subject: [PATCH 23/25] fmt run --- validator/validator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/validator/validator.go b/validator/validator.go index bd7be340..7955b761 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -1,9 +1,10 @@ package validator import ( + "sort" + . "github.com/dgraph-io/gqlparser/v2/ast" "github.com/dgraph-io/gqlparser/v2/gqlerror" - "sort" ) type AddErrFunc func(options ...ErrorOption) From adfb85a9ddd734446abff41362e4f27822f0d2da Mon Sep 17 00:00:00 2001 From: NamanJain8 Date: Thu, 2 Dec 2021 20:40:26 +0530 Subject: [PATCH 24/25] fix(validate): fix race condition in rules sort --- validator/validator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/validator/validator.go b/validator/validator.go index 7955b761..22e12b9f 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -30,15 +30,15 @@ func AddRule(name string, f ruleFunc) { // f is called once each time `Validate` is executed. func AddRuleWithOrder(name string, order int, f ruleFunc) { rules = append(rules, rule{name: name, order: order, rule: f}) + sort.Slice(rules, func(i, j int) bool { + return rules[i].order < rules[j].order + }) } func Validate(schema *Schema, doc *QueryDocument, variables map[string]interface{}) gqlerror.List { var errs gqlerror.List observers := &Events{} - sort.Slice(rules, func(i, j int) bool { - return rules[i].order < rules[j].order - }) for i := range rules { rule := rules[i] rule.rule(observers, func(options ...ErrorOption) { From 7a7d21bf1fdee45dee6646f7c537768890732659 Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Mon, 31 Jan 2022 11:13:48 -0500 Subject: [PATCH 25/25] Replace dgraph-io with vektah Signed-off-by: Steve Coffman --- ast/definition.go | 2 +- ast/document_test.go | 4 ++-- formatter/formatter.go | 4 ++-- formatter/formatter_test.go | 8 ++++---- go.mod | 2 +- gqlerror/error.go | 2 +- gqlerror/error_test.go | 2 +- gqlparser.go | 10 +++++----- lexer/lexer.go | 4 ++-- lexer/lexer_test.go | 4 ++-- lexer/token.go | 2 +- parser/parser.go | 6 +++--- parser/parser_test.go | 4 ++-- parser/query.go | 6 +++--- parser/query_test.go | 4 ++-- parser/schema.go | 6 +++--- parser/schema_test.go | 4 ++-- parser/testrunner/runner.go | 2 +- readme.md | 2 +- validator/error.go | 4 ++-- validator/imported_test.go | 6 +++--- validator/prelude.go | 2 +- validator/rules/fields_on_correct_type.go | 4 ++-- validator/rules/fragments_on_composite_types.go | 4 ++-- validator/rules/known_argument_names.go | 4 ++-- validator/rules/known_directives.go | 4 ++-- validator/rules/known_fragment_names.go | 4 ++-- validator/rules/known_type_names.go | 4 ++-- validator/rules/lone_anonymous_operation.go | 4 ++-- validator/rules/no_fragment_cycles.go | 4 ++-- validator/rules/no_undefined_variables.go | 4 ++-- validator/rules/no_unused_fragments.go | 4 ++-- validator/rules/no_unused_variables.go | 4 ++-- validator/rules/overlapping_fields_can_be_merged.go | 4 ++-- validator/rules/possible_fragment_spreads.go | 4 ++-- validator/rules/provided_required_arguments.go | 4 ++-- validator/rules/scalar_leafs.go | 4 ++-- validator/rules/single_field_subscriptions.go | 4 ++-- validator/rules/unique_argument_names.go | 4 ++-- validator/rules/unique_directives_per_location.go | 4 ++-- validator/rules/unique_fragment_names.go | 4 ++-- validator/rules/unique_input_field_names.go | 4 ++-- validator/rules/unique_operation_names.go | 4 ++-- validator/rules/unique_variable_names.go | 4 ++-- validator/rules/values_of_correct_type.go | 4 ++-- validator/rules/variables_are_input_types.go | 4 ++-- validator/rules/variables_in_allowed_position.go | 4 ++-- validator/schema.go | 6 +++--- validator/schema_test.go | 4 ++-- validator/validator.go | 4 ++-- validator/validator_test.go | 8 ++++---- validator/vars.go | 4 ++-- validator/vars_test.go | 6 +++--- validator/walk.go | 2 +- validator/walk_test.go | 4 ++-- 55 files changed, 114 insertions(+), 114 deletions(-) diff --git a/ast/definition.go b/ast/definition.go index 36076774..f5c8ea37 100644 --- a/ast/definition.go +++ b/ast/definition.go @@ -14,7 +14,7 @@ const ( // ObjectDefinition is the core type definition object, it includes all of the definable types // but does *not* cover schema or directives. // -// @dgraph-io: Javascript implementation has different types for all of these, but they are +// @vektah: Javascript implementation has different types for all of these, but they are // more similar than different and don't define any behaviour. I think this style of // "some hot" struct works better, at least for go. // diff --git a/ast/document_test.go b/ast/document_test.go index 0389b352..b6461594 100644 --- a/ast/document_test.go +++ b/ast/document_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - . "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser" + . "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser" ) func TestQueryDocMethods(t *testing.T) { diff --git a/formatter/formatter.go b/formatter/formatter.go index 66de72b2..3131b70f 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -6,7 +6,7 @@ import ( "sort" "strings" - "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/ast" ) type Formatter interface { @@ -532,7 +532,7 @@ func (f *formatter) FormatVariableDefinition(def *ast.VariableDefinition) { f.FormatValue(def.DefaultValue) } - // TODO https://github.com/dgraph-io/gqlparser/v2/issues/102 + // TODO https://github.com/vektah/gqlparser/v2/issues/102 // VariableDefinition : Variable : Type DefaultValue? Directives[Const]? } diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index cdf2c19c..b14ce3fd 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -9,10 +9,10 @@ import ( "testing" "unicode/utf8" - "github.com/dgraph-io/gqlparser/v2" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/formatter" - "github.com/dgraph-io/gqlparser/v2/parser" + "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/formatter" + "github.com/vektah/gqlparser/v2/parser" "github.com/stretchr/testify/assert" ) diff --git a/go.mod b/go.mod index 0d094d59..afdb99d8 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/dgraph-io/gqlparser/v2 +module github.com/vektah/gqlparser/v2 go 1.12 diff --git a/gqlerror/error.go b/gqlerror/error.go index c2ce8cbd..70a5a6cf 100644 --- a/gqlerror/error.go +++ b/gqlerror/error.go @@ -5,7 +5,7 @@ import ( "fmt" "strconv" - "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/ast" ) // Error is the standard graphql error type described in https://facebook.github.io/graphql/draft/#sec-Errors diff --git a/gqlerror/error_test.go b/gqlerror/error_test.go index e8ee06db..818d6602 100644 --- a/gqlerror/error_test.go +++ b/gqlerror/error_test.go @@ -3,7 +3,7 @@ package gqlerror import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/ast" "github.com/stretchr/testify/require" ) diff --git a/gqlparser.go b/gqlparser.go index 73a5390e..89335b38 100644 --- a/gqlparser.go +++ b/gqlparser.go @@ -1,11 +1,11 @@ package gqlparser import ( - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" - "github.com/dgraph-io/gqlparser/v2/parser" - "github.com/dgraph-io/gqlparser/v2/validator" - _ "github.com/dgraph-io/gqlparser/v2/validator/rules" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/parser" + "github.com/vektah/gqlparser/v2/validator" + _ "github.com/vektah/gqlparser/v2/validator/rules" ) func LoadSchema(str ...*ast.Source) (*ast.Schema, *gqlerror.Error) { diff --git a/lexer/lexer.go b/lexer/lexer.go index f25f7d02..720dd5b4 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -4,8 +4,8 @@ import ( "bytes" "unicode/utf8" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" ) // Lexer turns graphql request and schema strings into tokens diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 5d9f84bf..82510eaf 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -3,8 +3,8 @@ package lexer import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser/testrunner" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser/testrunner" ) func TestLexer(t *testing.T) { diff --git a/lexer/token.go b/lexer/token.go index c6f5eb1e..8985a7ef 100644 --- a/lexer/token.go +++ b/lexer/token.go @@ -3,7 +3,7 @@ package lexer import ( "strconv" - "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/ast" ) const ( diff --git a/parser/parser.go b/parser/parser.go index 724343f8..52b8e684 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -3,9 +3,9 @@ package parser import ( "strconv" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" - "github.com/dgraph-io/gqlparser/v2/lexer" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/lexer" ) type parser struct { diff --git a/parser/parser_test.go b/parser/parser_test.go index 3bda7e12..05a5b152 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/lexer" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/lexer" "github.com/stretchr/testify/require" ) diff --git a/parser/query.go b/parser/query.go index 994be82d..939e8af4 100644 --- a/parser/query.go +++ b/parser/query.go @@ -1,10 +1,10 @@ package parser import ( - "github.com/dgraph-io/gqlparser/v2/gqlerror" - "github.com/dgraph-io/gqlparser/v2/lexer" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/lexer" - . "github.com/dgraph-io/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/ast" ) func ParseQuery(source *Source) (*QueryDocument, *gqlerror.Error) { diff --git a/parser/query_test.go b/parser/query_test.go index b03f94cf..08d2ad15 100644 --- a/parser/query_test.go +++ b/parser/query_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser/testrunner" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser/testrunner" ) func TestQueryDocument(t *testing.T) { diff --git a/parser/schema.go b/parser/schema.go index c3679cfe..7cfdd147 100644 --- a/parser/schema.go +++ b/parser/schema.go @@ -1,9 +1,9 @@ package parser import ( - . "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" - "github.com/dgraph-io/gqlparser/v2/lexer" + . "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/lexer" ) func ParseSchema(source *Source) (*SchemaDocument, *gqlerror.Error) { diff --git a/parser/schema_test.go b/parser/schema_test.go index c66c04ff..5c3d19c0 100644 --- a/parser/schema_test.go +++ b/parser/schema_test.go @@ -3,8 +3,8 @@ package parser import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser/testrunner" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser/testrunner" ) func TestSchemaDocument(t *testing.T) { diff --git a/parser/testrunner/runner.go b/parser/testrunner/runner.go index 6deb4819..4c5d9685 100644 --- a/parser/testrunner/runner.go +++ b/parser/testrunner/runner.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/andreyvit/diff" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/gqlerror" "gopkg.in/yaml.v2" ) diff --git a/readme.md b/readme.md index 6f8c9a5a..bdc9aa95 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -gqlparser [![CircleCI](https://badgen.net/circleci/github/dgraph-io/gqlparser/v2/master)](https://circleci.com/gh/dgraph-io/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/dgraph-io/gqlparser)](https://goreportcard.com/report/github.com/dgraph-io/gqlparser) [![Coverage Status](https://badgen.net/coveralls/c/github/dgraph-io/gqlparser)](https://coveralls.io/github/dgraph-io/gqlparser?branch=master) +gqlparser [![CircleCI](https://badgen.net/circleci/github/vektah/gqlparser/v2/master)](https://circleci.com/gh/vektah/gqlparser) [![Go Report Card](https://goreportcard.com/badge/github.com/vektah/gqlparser)](https://goreportcard.com/report/github.com/vektah/gqlparser) [![Coverage Status](https://badgen.net/coveralls/c/github/vektah/gqlparser)](https://coveralls.io/github/vektah/gqlparser?branch=master) === This is a parser for graphql, written to mirror the graphql-js reference implementation as closely while remaining idiomatic and easy to use. diff --git a/validator/error.go b/validator/error.go index dd916dcc..f8f76055 100644 --- a/validator/error.go +++ b/validator/error.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" ) type ErrorOption func(err *gqlerror.Error) diff --git a/validator/imported_test.go b/validator/imported_test.go index 2f770fa4..a0a0e257 100644 --- a/validator/imported_test.go +++ b/validator/imported_test.go @@ -11,9 +11,9 @@ import ( "strings" "testing" - "github.com/dgraph-io/gqlparser/v2" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" ) diff --git a/validator/prelude.go b/validator/prelude.go index c75d44d2..0c7e9b2d 100644 --- a/validator/prelude.go +++ b/validator/prelude.go @@ -1,6 +1,6 @@ package validator -import "github.com/dgraph-io/gqlparser/v2/ast" +import "github.com/vektah/gqlparser/v2/ast" var Prelude = &ast.Source{ Name: "prelude.graphql", diff --git a/validator/rules/fields_on_correct_type.go b/validator/rules/fields_on_correct_type.go index e9dc25c6..8bfb8cc3 100644 --- a/validator/rules/fields_on_correct_type.go +++ b/validator/rules/fields_on_correct_type.go @@ -4,8 +4,8 @@ import ( "fmt" "sort" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/fragments_on_composite_types.go b/validator/rules/fragments_on_composite_types.go index 4ea69cca..5215f697 100644 --- a/validator/rules/fragments_on_composite_types.go +++ b/validator/rules/fragments_on_composite_types.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_argument_names.go b/validator/rules/known_argument_names.go index cb2949fc..9a53df17 100644 --- a/validator/rules/known_argument_names.go +++ b/validator/rules/known_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_directives.go b/validator/rules/known_directives.go index 0e42e0d5..f3c0f80e 100644 --- a/validator/rules/known_directives.go +++ b/validator/rules/known_directives.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_fragment_names.go b/validator/rules/known_fragment_names.go index c4638c93..b7427d0d 100644 --- a/validator/rules/known_fragment_names.go +++ b/validator/rules/known_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/known_type_names.go b/validator/rules/known_type_names.go index 2901dfec..c228af70 100644 --- a/validator/rules/known_type_names.go +++ b/validator/rules/known_type_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/lone_anonymous_operation.go b/validator/rules/lone_anonymous_operation.go index e6c7beec..d2752854 100644 --- a/validator/rules/lone_anonymous_operation.go +++ b/validator/rules/lone_anonymous_operation.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_fragment_cycles.go b/validator/rules/no_fragment_cycles.go index 727d8e17..81fffa57 100644 --- a/validator/rules/no_fragment_cycles.go +++ b/validator/rules/no_fragment_cycles.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_undefined_variables.go b/validator/rules/no_undefined_variables.go index 82eab4be..4f05f00a 100644 --- a/validator/rules/no_undefined_variables.go +++ b/validator/rules/no_undefined_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_unused_fragments.go b/validator/rules/no_unused_fragments.go index 0dad6c76..dfc89672 100644 --- a/validator/rules/no_unused_fragments.go +++ b/validator/rules/no_unused_fragments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/no_unused_variables.go b/validator/rules/no_unused_variables.go index b71b40ce..df2e5f4b 100644 --- a/validator/rules/no_unused_variables.go +++ b/validator/rules/no_unused_variables.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/overlapping_fields_can_be_merged.go b/validator/rules/overlapping_fields_can_be_merged.go index d95093e2..5cd028df 100644 --- a/validator/rules/overlapping_fields_can_be_merged.go +++ b/validator/rules/overlapping_fields_can_be_merged.go @@ -5,8 +5,8 @@ import ( "fmt" "reflect" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/possible_fragment_spreads.go b/validator/rules/possible_fragment_spreads.go index 8881822d..a3f795c9 100644 --- a/validator/rules/possible_fragment_spreads.go +++ b/validator/rules/possible_fragment_spreads.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/provided_required_arguments.go b/validator/rules/provided_required_arguments.go index 455aad7c..4410288a 100644 --- a/validator/rules/provided_required_arguments.go +++ b/validator/rules/provided_required_arguments.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/scalar_leafs.go b/validator/rules/scalar_leafs.go index 55155fdf..718bc683 100644 --- a/validator/rules/scalar_leafs.go +++ b/validator/rules/scalar_leafs.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/single_field_subscriptions.go b/validator/rules/single_field_subscriptions.go index 4663128b..206e3a6e 100644 --- a/validator/rules/single_field_subscriptions.go +++ b/validator/rules/single_field_subscriptions.go @@ -3,8 +3,8 @@ package validator import ( "strconv" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_argument_names.go b/validator/rules/unique_argument_names.go index 624180ff..fc2b639d 100644 --- a/validator/rules/unique_argument_names.go +++ b/validator/rules/unique_argument_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_directives_per_location.go b/validator/rules/unique_directives_per_location.go index 3b2f4149..2ea4f13d 100644 --- a/validator/rules/unique_directives_per_location.go +++ b/validator/rules/unique_directives_per_location.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_fragment_names.go b/validator/rules/unique_fragment_names.go index 736494c4..8c348aea 100644 --- a/validator/rules/unique_fragment_names.go +++ b/validator/rules/unique_fragment_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_input_field_names.go b/validator/rules/unique_input_field_names.go index f4131d31..092be671 100644 --- a/validator/rules/unique_input_field_names.go +++ b/validator/rules/unique_input_field_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_operation_names.go b/validator/rules/unique_operation_names.go index 8b4681de..4d41b60a 100644 --- a/validator/rules/unique_operation_names.go +++ b/validator/rules/unique_operation_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/unique_variable_names.go b/validator/rules/unique_variable_names.go index c0252db6..64ac5072 100644 --- a/validator/rules/unique_variable_names.go +++ b/validator/rules/unique_variable_names.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/values_of_correct_type.go b/validator/rules/values_of_correct_type.go index 06af3cbb..40dc2194 100644 --- a/validator/rules/values_of_correct_type.go +++ b/validator/rules/values_of_correct_type.go @@ -3,8 +3,8 @@ package validator import ( "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/variables_are_input_types.go b/validator/rules/variables_are_input_types.go index a1353663..4ea94e5a 100644 --- a/validator/rules/variables_are_input_types.go +++ b/validator/rules/variables_are_input_types.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/rules/variables_in_allowed_position.go b/validator/rules/variables_in_allowed_position.go index 0445e847..aba6eb62 100644 --- a/validator/rules/variables_in_allowed_position.go +++ b/validator/rules/variables_in_allowed_position.go @@ -1,8 +1,8 @@ package validator import ( - "github.com/dgraph-io/gqlparser/v2/ast" - . "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2/ast" + . "github.com/vektah/gqlparser/v2/validator" ) func init() { diff --git a/validator/schema.go b/validator/schema.go index 25ee7469..bc093bc7 100644 --- a/validator/schema.go +++ b/validator/schema.go @@ -6,9 +6,9 @@ import ( "strconv" "strings" - . "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" - "github.com/dgraph-io/gqlparser/v2/parser" + . "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/parser" ) func LoadSchema(inputs ...*Source) (*Schema, *gqlerror.Error) { diff --git a/validator/schema_test.go b/validator/schema_test.go index 6eb0324f..0e81f845 100644 --- a/validator/schema_test.go +++ b/validator/schema_test.go @@ -4,8 +4,8 @@ import ( "io/ioutil" "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser/testrunner" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser/testrunner" "github.com/stretchr/testify/require" ) diff --git a/validator/validator.go b/validator/validator.go index 22e12b9f..7a8143f4 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -3,8 +3,8 @@ package validator import ( "sort" - . "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + . "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" ) type AddErrFunc func(options ...ErrorOption) diff --git a/validator/validator_test.go b/validator/validator_test.go index 9ab400c6..d7d2f4f0 100644 --- a/validator/validator_test.go +++ b/validator/validator_test.go @@ -3,10 +3,10 @@ package validator_test import ( "testing" - "github.com/dgraph-io/gqlparser/v2" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser" - "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser" + "github.com/vektah/gqlparser/v2/validator" "github.com/stretchr/testify/require" ) diff --git a/validator/vars.go b/validator/vars.go index 4dfbea1d..4c569045 100644 --- a/validator/vars.go +++ b/validator/vars.go @@ -7,8 +7,8 @@ import ( "strconv" "strings" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/gqlerror" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/gqlerror" ) // VariableValues coerces and validates variable values diff --git a/validator/vars_test.go b/validator/vars_test.go index d063a960..3d1fc317 100644 --- a/validator/vars_test.go +++ b/validator/vars_test.go @@ -6,9 +6,9 @@ import ( "encoding/json" - "github.com/dgraph-io/gqlparser/v2" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/validator" + "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/validator" "github.com/stretchr/testify/require" ) diff --git a/validator/walk.go b/validator/walk.go index e85cd796..b4085e58 100644 --- a/validator/walk.go +++ b/validator/walk.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/dgraph-io/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/ast" ) type Events struct { diff --git a/validator/walk_test.go b/validator/walk_test.go index 9ac9bf5c..fdb25cba 100644 --- a/validator/walk_test.go +++ b/validator/walk_test.go @@ -3,8 +3,8 @@ package validator import ( "testing" - "github.com/dgraph-io/gqlparser/v2/ast" - "github.com/dgraph-io/gqlparser/v2/parser" + "github.com/vektah/gqlparser/v2/ast" + "github.com/vektah/gqlparser/v2/parser" "github.com/stretchr/testify/require" )