From 0e4b18cab93504383dcb5b2475cb950ddd3174c6 Mon Sep 17 00:00:00 2001 From: Kevin Mulvey Date: Fri, 13 May 2016 09:10:22 -0400 Subject: [PATCH] correct misspellings, gofmt --- abstract_test.go | 4 +- definition_test.go | 46 +++++------ directives.go | 4 +- enum_type_test.go | 12 +-- executor.go | 8 +- executor_test.go | 10 +-- graphql_test.go | 4 +- introspection.go | 2 +- introspection_test.go | 4 +- language/lexer/lexer_test.go | 122 +++++++++++++-------------- language/visitor/visitor_test.go | 4 +- lists_test.go | 32 ++++---- mutations_test.go | 8 +- nonnull_test.go | 136 +++++++++++++++---------------- rules.go | 86 +++++++++---------- schema.go | 2 +- validator.go | 2 +- values.go | 4 +- variables_test.go | 48 +++++------ 19 files changed, 269 insertions(+), 269 deletions(-) diff --git a/abstract_test.go b/abstract_test.go index 37f2eb3d..bd983db3 100644 --- a/abstract_test.go +++ b/abstract_test.go @@ -405,7 +405,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Runtime Object type "Human" is not a possible type for "Pet".`, Locations: []location.SourceLocation{}, }, @@ -523,7 +523,7 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Runtime Object type "Human" is not a possible type for "Pet".`, Locations: []location.SourceLocation{}, }, diff --git a/definition_test.go b/definition_test.go index 6664feab..419492e3 100644 --- a/definition_test.go +++ b/definition_test.go @@ -366,17 +366,17 @@ func TestTypeSystem_DefinitionExample_StringifiesSimpleTypes(t *testing.T) { expected string } tests := []Test{ - Test{graphql.Int, "Int"}, - Test{blogArticle, "Article"}, - Test{interfaceType, "Interface"}, - Test{unionType, "Union"}, - Test{enumType, "Enum"}, - Test{inputObjectType, "InputObject"}, - Test{graphql.NewNonNull(graphql.Int), "Int!"}, - Test{graphql.NewList(graphql.Int), "[Int]"}, - Test{graphql.NewNonNull(graphql.NewList(graphql.Int)), "[Int]!"}, - Test{graphql.NewList(graphql.NewNonNull(graphql.Int)), "[Int!]"}, - Test{graphql.NewList(graphql.NewList(graphql.Int)), "[[Int]]"}, + {graphql.Int, "Int"}, + {blogArticle, "Article"}, + {interfaceType, "Interface"}, + {unionType, "Union"}, + {enumType, "Enum"}, + {inputObjectType, "InputObject"}, + {graphql.NewNonNull(graphql.Int), "Int!"}, + {graphql.NewList(graphql.Int), "[Int]"}, + {graphql.NewNonNull(graphql.NewList(graphql.Int)), "[Int]!"}, + {graphql.NewList(graphql.NewNonNull(graphql.Int)), "[Int!]"}, + {graphql.NewList(graphql.NewList(graphql.Int)), "[[Int]]"}, } for _, test := range tests { ttypeStr := fmt.Sprintf("%v", test.ttype) @@ -392,12 +392,12 @@ func TestTypeSystem_DefinitionExample_IdentifiesInputTypes(t *testing.T) { expected bool } tests := []Test{ - Test{graphql.Int, true}, - Test{objectType, false}, - Test{interfaceType, false}, - Test{unionType, false}, - Test{enumType, true}, - Test{inputObjectType, true}, + {graphql.Int, true}, + {objectType, false}, + {interfaceType, false}, + {unionType, false}, + {enumType, true}, + {inputObjectType, true}, } for _, test := range tests { ttypeStr := fmt.Sprintf("%v", test.ttype) @@ -419,12 +419,12 @@ func TestTypeSystem_DefinitionExample_IdentifiesOutputTypes(t *testing.T) { expected bool } tests := []Test{ - Test{graphql.Int, true}, - Test{objectType, true}, - Test{interfaceType, true}, - Test{unionType, true}, - Test{enumType, true}, - Test{inputObjectType, false}, + {graphql.Int, true}, + {objectType, true}, + {interfaceType, true}, + {unionType, true}, + {enumType, true}, + {inputObjectType, false}, } for _, test := range tests { ttypeStr := fmt.Sprintf("%v", test.ttype) diff --git a/directives.go b/directives.go index 67a1aa0d..ac37e877 100644 --- a/directives.go +++ b/directives.go @@ -35,7 +35,7 @@ var IncludeDirective *Directive = NewDirective(&Directive{ Description: "Directs the executor to include this field or fragment only when " + "the `if` argument is true.", Args: []*Argument{ - &Argument{ + { PrivateName: "if", Type: NewNonNull(Boolean), PrivateDescription: "Included when true.", @@ -54,7 +54,7 @@ var SkipDirective *Directive = NewDirective(&Directive{ Description: "Directs the executor to skip this field or fragment when the `if` " + "argument is true.", Args: []*Argument{ - &Argument{ + { PrivateName: "if", Type: NewNonNull(Boolean), PrivateDescription: "Skipped when true.", diff --git a/enum_type_test.go b/enum_type_test.go index 7187a686..e784d70f 100644 --- a/enum_type_test.go +++ b/enum_type_test.go @@ -155,7 +155,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptStringLiterals(t *testing.T) { expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Argument "fromEnum" expected type "Color" but got: "GREEN".`, }, }, @@ -182,7 +182,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptInternalValueInPlaceOfEnumLiteral(t expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Argument "fromEnum" expected type "Color" but got: 1.`, }, }, @@ -198,7 +198,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptEnumLiteralInPlaceOfInt(t *testing.T expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Argument "fromInt" expected type "Int" but got: GREEN.`, }, }, @@ -248,7 +248,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptInternalValueAsEnumVariable(t *testi expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$color" expected value of type "Color!" but got: 2.`, }, }, @@ -266,7 +266,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptStringVariablesAsEnumInput(t *testin expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$color" of type "String!" used in position expecting type "Color".`, }, }, @@ -284,7 +284,7 @@ func TestTypeSystem_EnumValues_DoesNotAcceptInternalValueVariableAsEnumInput(t * expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$color" of type "Int!" used in position expecting type "Color".`, }, }, diff --git a/executor.go b/executor.go index fb4e14c1..7230be2b 100644 --- a/executor.go +++ b/executor.go @@ -110,7 +110,7 @@ func buildExecutionContext(p BuildExecutionCtxParams) (*ExecutionContext, error) opName := p.OperationName if opName == "" { // get first opName - for k, _ := range operations { + for k := range operations { opName = k break } @@ -397,10 +397,10 @@ func doesFragmentConditionMatch(eCtx *ExecutionContext, fragment ast.Node, ttype if conditionalType == ttype { return true } - if conditionalType.Name() == ttype.Name() { + if conditionalType.Name() == ttype.Name() { return true } - + if conditionalType, ok := conditionalType.(Abstract); ok { return conditionalType.IsPossibleType(ttype) } @@ -739,7 +739,7 @@ func defaultResolveFn(p ResolveParams) (interface{}, error) { } /** - * This method looks up the field on the given type defintion. + * This method looks up the field on the given type definition. * It has special casing for the two introspection fields, __schema * and __typename. __typename is special because it can always be * queried as a field, even in situations where no other fields diff --git a/executor_test.go b/executor_test.go index 7922d8c8..cbcf7709 100644 --- a/executor_test.go +++ b/executor_test.go @@ -465,10 +465,10 @@ func TestNullsOutErrorSubtrees(t *testing.T) { "syncError": nil, } expectedErrors := []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Error getting syncError", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 3, Column: 7, }, }, @@ -619,7 +619,7 @@ func TestThrowsIfNoOperationIsProvidedWithMultipleOperations(t *testing.T) { } expectedErrors := []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Must provide operation name if query contains multiple operations.", Locations: []location.SourceLocation{}, }, @@ -1050,7 +1050,7 @@ func TestFailsWhenAnIsTypeOfCheckIsNotMet(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Expected value of type "SpecialType" but got: graphql_test.testNotSpecialType.`, Locations: []location.SourceLocation{}, }, @@ -1119,7 +1119,7 @@ func TestFailsToExecuteQueryContainingATypeDefinition(t *testing.T) { expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "GraphQL cannot execute a request containing a ObjectDefinition", Locations: []location.SourceLocation{}, }, diff --git a/graphql_test.go b/graphql_test.go index d7d59105..365d11bd 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -19,7 +19,7 @@ var Tests = []T{} func init() { Tests = []T{ - T{ + { Query: ` query HeroNameQuery { hero { @@ -36,7 +36,7 @@ func init() { }, }, }, - T{ + { Query: ` query HeroNameAndFriendsQuery { hero { diff --git a/introspection.go b/introspection.go index 81bc61f4..266a145c 100644 --- a/introspection.go +++ b/introspection.go @@ -440,7 +440,7 @@ mutation operations.`, Type: __Type, Description: "Request the type information of a single type.", Args: []*Argument{ - &Argument{ + { PrivateName: "name", Type: NewNonNull(String), }, diff --git a/introspection_test.go b/introspection_test.go index eabcfc62..4304fa86 100644 --- a/introspection_test.go +++ b/introspection_test.go @@ -1211,11 +1211,11 @@ func TestIntrospection_FailsAsExpectedOnThe__TypeRootFieldWithoutAnArg(t *testin ` expected := &graphql.Result{ Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Field "__type" argument "name" of type "String!" ` + `is required but not provided.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 3, Column: 9}, + {Line: 3, Column: 9}, }, }, }, diff --git a/language/lexer/lexer_test.go b/language/lexer/lexer_test.go index 1db38bcf..dc2b3dc6 100644 --- a/language/lexer/lexer_test.go +++ b/language/lexer/lexer_test.go @@ -18,7 +18,7 @@ func createSource(body string) *source.Source { func TestSkipsWhiteSpace(t *testing.T) { tests := []Test{ - Test{ + { Body: ` foo @@ -31,7 +31,7 @@ func TestSkipsWhiteSpace(t *testing.T) { Value: "foo", }, }, - Test{ + { Body: ` #comment foo#comment @@ -43,7 +43,7 @@ func TestSkipsWhiteSpace(t *testing.T) { Value: "foo", }, }, - Test{ + { Body: `,,,foo,,,`, Expected: Token{ Kind: TokenKind[NAME], @@ -82,7 +82,7 @@ func TestErrorsRespectWhitespace(t *testing.T) { func TestLexesStrings(t *testing.T) { tests := []Test{ - Test{ + { Body: "\"simple\"", Expected: Token{ Kind: TokenKind[STRING], @@ -91,7 +91,7 @@ func TestLexesStrings(t *testing.T) { Value: "simple", }, }, - Test{ + { Body: "\" white space \"", Expected: Token{ Kind: TokenKind[STRING], @@ -100,7 +100,7 @@ func TestLexesStrings(t *testing.T) { Value: " white space ", }, }, - Test{ + { Body: "\"quote \\\"\"", Expected: Token{ Kind: TokenKind[STRING], @@ -109,7 +109,7 @@ func TestLexesStrings(t *testing.T) { Value: `quote "`, }, }, - Test{ + { Body: "\"escaped \\n\\r\\b\\t\\f\"", Expected: Token{ Kind: TokenKind[STRING], @@ -118,7 +118,7 @@ func TestLexesStrings(t *testing.T) { Value: "escaped \n\r\b\t\f", }, }, - Test{ + { Body: "\"slashes \\\\ \\/\"", Expected: Token{ Kind: TokenKind[STRING], @@ -127,7 +127,7 @@ func TestLexesStrings(t *testing.T) { Value: "slashes \\ \\/", }, }, - Test{ + { Body: "\"unicode \\u1234\\u5678\\u90AB\\uCDEF\"", Expected: Token{ Kind: TokenKind[STRING], @@ -150,7 +150,7 @@ func TestLexesStrings(t *testing.T) { func TestLexReportsUsefulStringErrors(t *testing.T) { tests := []Test{ - Test{ + { Body: "\"no end quote", Expected: `Syntax Error GraphQL (1:14) Unterminated string. @@ -158,7 +158,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"multi\nline\"", Expected: `Syntax Error GraphQL (1:7) Unterminated string. @@ -167,7 +167,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { 2: line" `, }, - Test{ + { Body: "\"multi\rline\"", Expected: `Syntax Error GraphQL (1:7) Unterminated string. @@ -176,7 +176,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { 2: line" `, }, - Test{ + { Body: "\"multi\u2028line\"", Expected: `Syntax Error GraphQL (1:7) Unterminated string. @@ -185,7 +185,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { 2: line" `, }, - Test{ + { Body: "\"multi\u2029line\"", Expected: `Syntax Error GraphQL (1:7) Unterminated string. @@ -194,7 +194,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { 2: line" `, }, - Test{ + { Body: "\"bad \\z esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -202,7 +202,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\x esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -210,7 +210,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\u1 esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -218,7 +218,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\u0XX1 esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -226,7 +226,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\uXXXX esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -234,7 +234,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\uFXXX esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -242,7 +242,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "\"bad \\uXXXF esc\"", Expected: `Syntax Error GraphQL (1:7) Bad character escape sequence. @@ -264,7 +264,7 @@ func TestLexReportsUsefulStringErrors(t *testing.T) { func TestLexesNumbers(t *testing.T) { tests := []Test{ - Test{ + { Body: "4", Expected: Token{ Kind: TokenKind[INT], @@ -273,7 +273,7 @@ func TestLexesNumbers(t *testing.T) { Value: "4", }, }, - Test{ + { Body: "4.123", Expected: Token{ Kind: TokenKind[FLOAT], @@ -282,7 +282,7 @@ func TestLexesNumbers(t *testing.T) { Value: "4.123", }, }, - Test{ + { Body: "-4", Expected: Token{ Kind: TokenKind[INT], @@ -291,7 +291,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-4", }, }, - Test{ + { Body: "9", Expected: Token{ Kind: TokenKind[INT], @@ -300,7 +300,7 @@ func TestLexesNumbers(t *testing.T) { Value: "9", }, }, - Test{ + { Body: "0", Expected: Token{ Kind: TokenKind[INT], @@ -309,7 +309,7 @@ func TestLexesNumbers(t *testing.T) { Value: "0", }, }, - Test{ + { Body: "-4.123", Expected: Token{ Kind: TokenKind[FLOAT], @@ -318,7 +318,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-4.123", }, }, - Test{ + { Body: "0.123", Expected: Token{ Kind: TokenKind[FLOAT], @@ -327,7 +327,7 @@ func TestLexesNumbers(t *testing.T) { Value: "0.123", }, }, - Test{ + { Body: "123e4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -336,7 +336,7 @@ func TestLexesNumbers(t *testing.T) { Value: "123e4", }, }, - Test{ + { Body: "123E4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -345,7 +345,7 @@ func TestLexesNumbers(t *testing.T) { Value: "123E4", }, }, - Test{ + { Body: "123e-4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -354,7 +354,7 @@ func TestLexesNumbers(t *testing.T) { Value: "123e-4", }, }, - Test{ + { Body: "123e+4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -363,7 +363,7 @@ func TestLexesNumbers(t *testing.T) { Value: "123e+4", }, }, - Test{ + { Body: "-1.123e4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -372,7 +372,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-1.123e4", }, }, - Test{ + { Body: "-1.123E4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -381,7 +381,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-1.123E4", }, }, - Test{ + { Body: "-1.123e-4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -390,7 +390,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-1.123e-4", }, }, - Test{ + { Body: "-1.123e+4", Expected: Token{ Kind: TokenKind[FLOAT], @@ -399,7 +399,7 @@ func TestLexesNumbers(t *testing.T) { Value: "-1.123e+4", }, }, - Test{ + { Body: "-1.123e4567", Expected: Token{ Kind: TokenKind[FLOAT], @@ -422,7 +422,7 @@ func TestLexesNumbers(t *testing.T) { func TestLexReportsUsefulNumbeErrors(t *testing.T) { tests := []Test{ - Test{ + { Body: "00", Expected: `Syntax Error GraphQL (1:2) Invalid number, unexpected digit after 0: "0". @@ -430,7 +430,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "+1", Expected: `Syntax Error GraphQL (1:1) Unexpected character "+". @@ -438,7 +438,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "1.", Expected: `Syntax Error GraphQL (1:3) Invalid number, expected digit but got: EOF. @@ -446,7 +446,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: ".123", Expected: `Syntax Error GraphQL (1:1) Unexpected character ".". @@ -454,7 +454,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "1.A", Expected: `Syntax Error GraphQL (1:3) Invalid number, expected digit but got: "A". @@ -462,7 +462,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "-A", Expected: `Syntax Error GraphQL (1:2) Invalid number, expected digit but got: "A". @@ -470,7 +470,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "1.0e", Expected: `Syntax Error GraphQL (1:5) Invalid number, expected digit but got: EOF. @@ -478,7 +478,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { ^ `, }, - Test{ + { Body: "1.0eA", Expected: `Syntax Error GraphQL (1:5) Invalid number, expected digit but got: "A". @@ -500,7 +500,7 @@ func TestLexReportsUsefulNumbeErrors(t *testing.T) { func TestLexesPunctuation(t *testing.T) { tests := []Test{ - Test{ + { Body: "!", Expected: Token{ Kind: TokenKind[BANG], @@ -509,7 +509,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "$", Expected: Token{ Kind: TokenKind[DOLLAR], @@ -518,7 +518,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "(", Expected: Token{ Kind: TokenKind[PAREN_L], @@ -527,7 +527,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: ")", Expected: Token{ Kind: TokenKind[PAREN_R], @@ -536,7 +536,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "...", Expected: Token{ Kind: TokenKind[SPREAD], @@ -545,7 +545,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: ":", Expected: Token{ Kind: TokenKind[COLON], @@ -554,7 +554,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "=", Expected: Token{ Kind: TokenKind[EQUALS], @@ -563,7 +563,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "@", Expected: Token{ Kind: TokenKind[AT], @@ -572,7 +572,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "[", Expected: Token{ Kind: TokenKind[BRACKET_L], @@ -581,7 +581,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "]", Expected: Token{ Kind: TokenKind[BRACKET_R], @@ -590,7 +590,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "{", Expected: Token{ Kind: TokenKind[BRACE_L], @@ -599,7 +599,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "|", Expected: Token{ Kind: TokenKind[PIPE], @@ -608,7 +608,7 @@ func TestLexesPunctuation(t *testing.T) { Value: "", }, }, - Test{ + { Body: "}", Expected: Token{ Kind: TokenKind[BRACE_R], @@ -631,7 +631,7 @@ func TestLexesPunctuation(t *testing.T) { func TestLexReportsUsefulUnknownCharacterError(t *testing.T) { tests := []Test{ - Test{ + { Body: "..", Expected: `Syntax Error GraphQL (1:1) Unexpected character ".". @@ -639,7 +639,7 @@ func TestLexReportsUsefulUnknownCharacterError(t *testing.T) { ^ `, }, - Test{ + { Body: "?", Expected: `Syntax Error GraphQL (1:1) Unexpected character "?". @@ -647,7 +647,7 @@ func TestLexReportsUsefulUnknownCharacterError(t *testing.T) { ^ `, }, - Test{ + { Body: "\u203B", Expected: `Syntax Error GraphQL (1:1) Unexpected character "※". diff --git a/language/visitor/visitor_test.go b/language/visitor/visitor_test.go index 412f96c0..b792ce8d 100644 --- a/language/visitor/visitor_test.go +++ b/language/visitor/visitor_test.go @@ -253,7 +253,7 @@ func TestVisitor_AllowsANamedFunctionsVisitorAPI(t *testing.T) { v := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - "Name": visitor.NamedVisitFuncs{ + "Name": { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { switch node := p.Node.(type) { case *ast.Name: @@ -262,7 +262,7 @@ func TestVisitor_AllowsANamedFunctionsVisitorAPI(t *testing.T) { return visitor.ActionNoChange, nil }, }, - "SelectionSet": visitor.NamedVisitFuncs{ + "SelectionSet": { Enter: func(p visitor.VisitFuncParams) (string, interface{}) { switch node := p.Node.(type) { case *ast.SelectionSet: diff --git a/lists_test.go b/lists_test.go index 4bc47cd7..9639512b 100644 --- a/lists_test.go +++ b/lists_test.go @@ -255,10 +255,10 @@ func TestLists_NonNullListOfNullableObjectsReturnsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -325,10 +325,10 @@ func TestLists_NonNullListOfNullableFunc_ReturnsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -421,10 +421,10 @@ func TestLists_NullableListOfNonNullObjects_ContainsNull(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -486,10 +486,10 @@ func TestLists_NullableListOfNonNullFunc_ContainsNull(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -597,10 +597,10 @@ func TestLists_NonNullListOfNonNullObjects_ContainsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -618,10 +618,10 @@ func TestLists_NonNullListOfNonNullObjects_ReturnsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -669,10 +669,10 @@ func TestLists_NonNullListOfNonNullFunc_ContainsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, @@ -695,10 +695,10 @@ func TestLists_NonNullListOfNonNullFunc_ReturnsNull(t *testing.T) { "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: "Cannot return null for non-nullable field DataType.test.", Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 1, Column: 10, }, diff --git a/mutations_test.go b/mutations_test.go index 0a52d136..a97dda52 100644 --- a/mutations_test.go +++ b/mutations_test.go @@ -218,16 +218,16 @@ func TestMutations_EvaluatesMutationsCorrectlyInThePresenceOfAFailedMutation(t * "sixth": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot change the number`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 8, Column: 7}, + {Line: 8, Column: 7}, }, }, - gqlerrors.FormattedError{ + { Message: `Cannot change the number`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 17, Column: 7}, + {Line: 17, Column: 7}, }, }, }, diff --git a/nonnull_test.go b/nonnull_test.go index b52c6829..75b3f6cb 100644 --- a/nonnull_test.go +++ b/nonnull_test.go @@ -121,10 +121,10 @@ func TestNonNull_NullsANullableFieldThatThrowsSynchronously(t *testing.T) { "sync": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 3, Column: 9, }, }, @@ -159,10 +159,10 @@ func TestNonNull_NullsANullableFieldThatThrowsInAPromise(t *testing.T) { "promise": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 3, Column: 9, }, }, @@ -199,10 +199,10 @@ func TestNonNull_NullsASynchronouslyReturnedObjectThatContainsANullableFieldThat "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullSyncError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 4, Column: 11, }, }, @@ -239,10 +239,10 @@ func TestNonNull_NullsASynchronouslyReturnedObjectThatContainsANonNullableFieldT "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullPromiseError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 4, Column: 11, }, }, @@ -279,10 +279,10 @@ func TestNonNull_NullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldTha "promiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullSyncError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 4, Column: 11, }, }, @@ -319,10 +319,10 @@ func TestNonNull_NullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldTha "promiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullPromiseError, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 4, Column: 11, }, }, @@ -404,76 +404,76 @@ func TestNonNull_NullsAComplexTreeOfNullableFieldsThatThrow(t *testing.T) { }, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 4, Column: 11}, + {Line: 4, Column: 11}, }, }, - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 7, Column: 13}, + {Line: 7, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 11, Column: 13}, + {Line: 11, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 16, Column: 11}, + {Line: 16, Column: 11}, }, }, - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 19, Column: 13}, + {Line: 19, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: syncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 23, Column: 13}, + {Line: 23, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 5, Column: 11}, + {Line: 5, Column: 11}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 8, Column: 13}, + {Line: 8, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 12, Column: 13}, + {Line: 12, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 17, Column: 11}, + {Line: 17, Column: 11}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 20, Column: 13}, + {Line: 20, Column: 13}, }, }, - gqlerrors.FormattedError{ + { Message: promiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 24, Column: 13}, + {Line: 24, Column: 13}, }, }, }, @@ -557,28 +557,28 @@ func TestNonNull_NullsTheFirstNullableObjectAfterAFieldThrowsInALongChainOfField "anotherPromiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullSyncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 8, Column: 19}, + {Line: 8, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: nonNullSyncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 19, Column: 19}, + {Line: 19, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: nonNullPromiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 30, Column: 19}, + {Line: 30, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: nonNullPromiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 41, Column: 19}, + {Line: 41, Column: 19}, }, }, }, @@ -681,10 +681,10 @@ func TestNonNull_NullsASynchronouslyReturnedObjectThatContainsANonNullableFieldT "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 4, Column: 11}, + {Line: 4, Column: 11}, }, }, }, @@ -719,10 +719,10 @@ func TestNonNull_NullsASynchronouslyReturnedObjectThatContainsANonNullableFieldT "nest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 4, Column: 11}, + {Line: 4, Column: 11}, }, }, }, @@ -758,10 +758,10 @@ func TestNonNull_NullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldTha "promiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 4, Column: 11}, + {Line: 4, Column: 11}, }, }, }, @@ -796,10 +796,10 @@ func TestNonNull_NullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldTha "promiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 4, Column: 11}, + {Line: 4, Column: 11}, }, }, }, @@ -955,28 +955,28 @@ func TestNonNull_NullsTheFirstNullableObjectAfterAFieldReturnsNullInALongChainOf "anotherPromiseNest": nil, }, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 8, Column: 19}, + {Line: 8, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 19, Column: 19}, + {Line: 19, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 30, Column: 19}, + {Line: 30, Column: 19}, }, }, - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 41, Column: 19}, + {Line: 41, Column: 19}, }, }, }, @@ -1011,10 +1011,10 @@ func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldThrows(t *testing.T) { expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullSyncError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 2, Column: 17}, + {Line: 2, Column: 17}, }, }, }, @@ -1043,10 +1043,10 @@ func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldErrors(t *testing.T) { expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: nonNullPromiseError, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 2, Column: 17}, + {Line: 2, Column: 17}, }, }, }, @@ -1075,10 +1075,10 @@ func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldReturnsNull(t *testing.T) expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullSync.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 2, Column: 17}, + {Line: 2, Column: 17}, }, }, }, @@ -1107,10 +1107,10 @@ func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull(t *testing.T expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`, Locations: []location.SourceLocation{ - location.SourceLocation{Line: 2, Column: 17}, + {Line: 2, Column: 17}, }, }, }, diff --git a/rules.go b/rules.go index 80f10754..534ad216 100644 --- a/rules.go +++ b/rules.go @@ -65,7 +65,7 @@ func newValidationRuleError(message string, nodes []ast.Node) (string, error) { func ArgumentsOfCorrectTypeRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Argument: visitor.NamedVisitFuncs{ + kinds.Argument: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -104,7 +104,7 @@ func ArgumentsOfCorrectTypeRule(context *ValidationContext) *ValidationRuleInsta func DefaultValuesOfCorrectTypeRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.VariableDefinition: visitor.NamedVisitFuncs{ + kinds.VariableDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -151,7 +151,7 @@ func DefaultValuesOfCorrectTypeRule(context *ValidationContext) *ValidationRuleI func FieldsOnCorrectTypeRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Field: visitor.NamedVisitFuncs{ + kinds.Field: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -194,7 +194,7 @@ func FieldsOnCorrectTypeRule(context *ValidationContext) *ValidationRuleInstance func FragmentsOnCompositeTypesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.InlineFragment: visitor.NamedVisitFuncs{ + kinds.InlineFragment: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.InlineFragment); ok { ttype := context.Type() @@ -208,7 +208,7 @@ func FragmentsOnCompositeTypesRule(context *ValidationContext) *ValidationRuleIn return visitor.ActionNoChange, nil }, }, - kinds.FragmentDefinition: visitor.NamedVisitFuncs{ + kinds.FragmentDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentDefinition); ok { ttype := context.Type() @@ -243,7 +243,7 @@ func FragmentsOnCompositeTypesRule(context *ValidationContext) *ValidationRuleIn func KnownArgumentNamesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Argument: visitor.NamedVisitFuncs{ + kinds.Argument: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -324,7 +324,7 @@ func KnownArgumentNamesRule(context *ValidationContext) *ValidationRuleInstance func KnownDirectivesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Directive: visitor.NamedVisitFuncs{ + kinds.Directive: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -398,7 +398,7 @@ func KnownDirectivesRule(context *ValidationContext) *ValidationRuleInstance { func KnownFragmentNamesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { var action = visitor.ActionNoChange var result interface{} @@ -437,7 +437,7 @@ func KnownFragmentNamesRule(context *ValidationContext) *ValidationRuleInstance func KnownTypeNamesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Named: visitor.NamedVisitFuncs{ + kinds.Named: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.Named); ok { typeNameValue := "" @@ -474,7 +474,7 @@ func LoneAnonymousOperationRule(context *ValidationContext) *ValidationRuleInsta var operationCount = 0 visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Document: visitor.NamedVisitFuncs{ + kinds.Document: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.Document); ok { operationCount = 0 @@ -487,7 +487,7 @@ func LoneAnonymousOperationRule(context *ValidationContext) *ValidationRuleInsta return visitor.ActionNoChange, nil }, }, - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.OperationDefinition); ok { if node.Name == nil && operationCount > 1 { @@ -553,7 +553,7 @@ func NoFragmentCyclesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.FragmentDefinition: visitor.NamedVisitFuncs{ + kinds.FragmentDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentDefinition); ok && node != nil { errors := []error{} @@ -641,7 +641,7 @@ func NoUndefinedVariablesRule(context *ValidationContext) *ValidationRuleInstanc var definedVariableNames = map[string]bool{} visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.OperationDefinition); ok && node != nil { operation = node @@ -651,7 +651,7 @@ func NoUndefinedVariablesRule(context *ValidationContext) *ValidationRuleInstanc return visitor.ActionNoChange, nil }, }, - kinds.VariableDefinition: visitor.NamedVisitFuncs{ + kinds.VariableDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.VariableDefinition); ok && node != nil { variableName := "" @@ -663,7 +663,7 @@ func NoUndefinedVariablesRule(context *ValidationContext) *ValidationRuleInstanc return visitor.ActionNoChange, nil }, }, - kinds.Variable: visitor.NamedVisitFuncs{ + kinds.Variable: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if variable, ok := p.Node.(*ast.Variable); ok && variable != nil { variableName := "" @@ -693,7 +693,7 @@ func NoUndefinedVariablesRule(context *ValidationContext) *ValidationRuleInstanc return visitor.ActionNoChange, nil }, }, - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentSpread); ok && node != nil { // Only visit fragments of a particular name once per operation @@ -733,7 +733,7 @@ func NoUnusedFragmentsRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.OperationDefinition); ok && node != nil { spreadNames = map[string]bool{} @@ -742,7 +742,7 @@ func NoUnusedFragmentsRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionNoChange, nil }, }, - kinds.FragmentDefinition: visitor.NamedVisitFuncs{ + kinds.FragmentDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if def, ok := p.Node.(*ast.FragmentDefinition); ok && def != nil { defName := "" @@ -757,7 +757,7 @@ func NoUnusedFragmentsRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionNoChange, nil }, }, - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if spread, ok := p.Node.(*ast.FragmentSpread); ok && spread != nil { spreadName := "" @@ -769,14 +769,14 @@ func NoUnusedFragmentsRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionNoChange, nil }, }, - kinds.Document: visitor.NamedVisitFuncs{ + kinds.Document: { Leave: func(p visitor.VisitFuncParams) (string, interface{}) { fragmentNameUsed := map[string]interface{}{} var reduceSpreadFragments func(spreads map[string]bool) reduceSpreadFragments = func(spreads map[string]bool) { - for fragName, _ := range spreads { + for fragName := range spreads { if isFragNameUsed, _ := fragmentNameUsed[fragName]; isFragNameUsed != true { fragmentNameUsed[fragName] = true @@ -834,7 +834,7 @@ func NoUnusedVariablesRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Enter: func(p visitor.VisitFuncParams) (string, interface{}) { visitedFragmentNames = map[string]bool{} variableDefs = []*ast.VariableDefinition{} @@ -862,7 +862,7 @@ func NoUnusedVariablesRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionNoChange, nil }, }, - kinds.VariableDefinition: visitor.NamedVisitFuncs{ + kinds.VariableDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if def, ok := p.Node.(*ast.VariableDefinition); ok && def != nil { variableDefs = append(variableDefs, def) @@ -871,7 +871,7 @@ func NoUnusedVariablesRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionSkip, nil }, }, - kinds.Variable: visitor.NamedVisitFuncs{ + kinds.Variable: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if variable, ok := p.Node.(*ast.Variable); ok && variable != nil { if variable.Name != nil { @@ -881,7 +881,7 @@ func NoUnusedVariablesRule(context *ValidationContext) *ValidationRuleInstance { return visitor.ActionNoChange, nil }, }, - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if spreadAST, ok := p.Node.(*ast.FragmentSpread); ok && spreadAST != nil { // Only visit fragments of a particular name once per operation @@ -1232,7 +1232,7 @@ func OverlappingFieldsCanBeMergedRule(context *ValidationContext) *ValidationRul // ensure field traversal orderedName := sort.StringSlice{} - for responseName, _ := range fieldMap { + for responseName := range fieldMap { orderedName = append(orderedName, responseName) } orderedName.Sort() @@ -1274,7 +1274,7 @@ func OverlappingFieldsCanBeMergedRule(context *ValidationContext) *ValidationRul visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.SelectionSet: visitor.NamedVisitFuncs{ + kinds.SelectionSet: { Leave: func(p visitor.VisitFuncParams) (string, interface{}) { if selectionSet, ok := p.Node.(*ast.SelectionSet); ok && selectionSet != nil { parentType, _ := context.ParentType().(Named) @@ -1378,7 +1378,7 @@ func PossibleFragmentSpreadsRule(context *ValidationContext) *ValidationRuleInst visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.InlineFragment: visitor.NamedVisitFuncs{ + kinds.InlineFragment: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.InlineFragment); ok && node != nil { fragType := context.Type() @@ -1395,7 +1395,7 @@ func PossibleFragmentSpreadsRule(context *ValidationContext) *ValidationRuleInst return visitor.ActionNoChange, nil }, }, - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentSpread); ok && node != nil { fragName := "" @@ -1433,7 +1433,7 @@ func ProvidedNonNullArgumentsRule(context *ValidationContext) *ValidationRuleIns visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Field: visitor.NamedVisitFuncs{ + kinds.Field: { Leave: func(p visitor.VisitFuncParams) (string, interface{}) { // Validate on leave to allow for deeper errors to appear first. if fieldAST, ok := p.Node.(*ast.Field); ok && fieldAST != nil { @@ -1477,7 +1477,7 @@ func ProvidedNonNullArgumentsRule(context *ValidationContext) *ValidationRuleIns return visitor.ActionNoChange, nil }, }, - kinds.Directive: visitor.NamedVisitFuncs{ + kinds.Directive: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { // Validate on leave to allow for deeper errors to appear first. @@ -1540,7 +1540,7 @@ func ScalarLeafsRule(context *ValidationContext) *ValidationRuleInstance { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Field: visitor.NamedVisitFuncs{ + kinds.Field: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.Field); ok && node != nil { nodeName := "" @@ -1586,19 +1586,19 @@ func UniqueArgumentNamesRule(context *ValidationContext) *ValidationRuleInstance visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.Field: visitor.NamedVisitFuncs{ + kinds.Field: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { knownArgNames = map[string]*ast.Name{} return visitor.ActionNoChange, nil }, }, - kinds.Directive: visitor.NamedVisitFuncs{ + kinds.Directive: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { knownArgNames = map[string]*ast.Name{} return visitor.ActionNoChange, nil }, }, - kinds.Argument: visitor.NamedVisitFuncs{ + kinds.Argument: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.Argument); ok { argName := "" @@ -1634,7 +1634,7 @@ func UniqueFragmentNamesRule(context *ValidationContext) *ValidationRuleInstance visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.FragmentDefinition: visitor.NamedVisitFuncs{ + kinds.FragmentDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentDefinition); ok && node != nil { fragmentName := "" @@ -1670,7 +1670,7 @@ func UniqueOperationNamesRule(context *ValidationContext) *ValidationRuleInstanc visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.OperationDefinition); ok && node != nil { operationName := "" @@ -1706,7 +1706,7 @@ func VariablesAreInputTypesRule(context *ValidationContext) *ValidationRuleInsta visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.VariableDefinition: visitor.NamedVisitFuncs{ + kinds.VariableDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.VariableDefinition); ok && node != nil { ttype, _ := typeFromAST(*context.Schema(), node.Type) @@ -1778,14 +1778,14 @@ func VariablesInAllowedPositionRule(context *ValidationContext) *ValidationRuleI visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.OperationDefinition: visitor.NamedVisitFuncs{ + kinds.OperationDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { varDefMap = map[string]*ast.VariableDefinition{} visitedFragmentNames = map[string]bool{} return visitor.ActionNoChange, nil }, }, - kinds.VariableDefinition: visitor.NamedVisitFuncs{ + kinds.VariableDefinition: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if varDefAST, ok := p.Node.(*ast.VariableDefinition); ok { defName := "" @@ -1797,7 +1797,7 @@ func VariablesInAllowedPositionRule(context *ValidationContext) *ValidationRuleI return visitor.ActionNoChange, nil }, }, - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { // Only visit fragments of a particular name once per operation if spreadAST, ok := p.Node.(*ast.FragmentSpread); ok { @@ -1813,7 +1813,7 @@ func VariablesInAllowedPositionRule(context *ValidationContext) *ValidationRuleI return visitor.ActionNoChange, nil }, }, - kinds.Variable: visitor.NamedVisitFuncs{ + kinds.Variable: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if variableAST, ok := p.Node.(*ast.Variable); ok && variableAST != nil { varName := "" @@ -1946,7 +1946,7 @@ func isValidLiteralValue(ttype Input, valueAST ast.Value) bool { func gatherSpreads(node ast.Node) (spreadNodes []*ast.FragmentSpread) { visitorOpts := &visitor.VisitorOptions{ KindFuncMap: map[string]visitor.NamedVisitFuncs{ - kinds.FragmentSpread: visitor.NamedVisitFuncs{ + kinds.FragmentSpread: { Kind: func(p visitor.VisitFuncParams) (string, interface{}) { if node, ok := p.Node.(*ast.FragmentSpread); ok && node != nil { spreadNodes = append(spreadNodes, node) diff --git a/schema.go b/schema.go index b2be7bba..4e1c37a6 100644 --- a/schema.go +++ b/schema.go @@ -258,7 +258,7 @@ func assertObjectImplementsInterface(object *Object, iface *Interface) error { ifaceFieldMap := iface.Fields() // Assert each interface field is implemented. - for fieldName, _ := range ifaceFieldMap { + for fieldName := range ifaceFieldMap { objectField := objectFieldMap[fieldName] ifaceField := ifaceFieldMap[fieldName] diff --git a/validator.go b/validator.go index 2873fd64..785aeb92 100644 --- a/validator.go +++ b/validator.go @@ -94,7 +94,7 @@ func visitUsingRules(schema *Schema, astDoc *ast.Document, rules []ValidationRul } } - // If the result is "false" (ie action === Action.Skip), we're not visiting any descendent nodes, + // If the result is "false" (ie action === Action.Skip), we're not visiting any descendant nodes, // but need to update typeInfo. if action == visitor.ActionSkip { typeInfo.Leave(node) diff --git a/values.go b/values.go index 6b3ff169..e228db14 100644 --- a/values.go +++ b/values.go @@ -246,13 +246,13 @@ func isValidInputValue(value interface{}, ttype Input) bool { fields := ttype.Fields() // Ensure every provided field is defined. - for fieldName, _ := range valueMap { + for fieldName := range valueMap { if _, ok := fields[fieldName]; !ok { return false } } // Ensure every defined field is valid. - for fieldName, _ := range fields { + for fieldName := range fields { isValid := isValidInputValue(valueMap[fieldName], fields[fieldName].Type) if !isValid { return false diff --git a/variables_test.go b/variables_test.go index b8e118f2..a5bf594c 100644 --- a/variables_test.go +++ b/variables_test.go @@ -368,11 +368,11 @@ func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnNullForNestedNon expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "TestInputObject" but ` + `got: {"a":"foo","b":"bar","c":null}.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -403,11 +403,11 @@ func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnIncorrectType(t expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "TestInputObject" but ` + `got: "foo bar".`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -441,11 +441,11 @@ func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnOmissionOfNested expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "TestInputObject" but ` + `got: {"a":"foo","b":"bar"}.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -481,11 +481,11 @@ func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnAdditionOfUnknow expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "TestInputObject" but ` + `got: {"a":"foo","b":"bar","c":"baz","d":"dog"}.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -692,10 +692,10 @@ func TestVariables_NonNullableScalars_DoesNotAllowNonNullableInputsToBeOmittedIn expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$value" of required type "String!" was not provided.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 31, }, }, @@ -731,10 +731,10 @@ func TestVariables_NonNullableScalars_DoesNotAllowNonNullableInputsToBeSetToNull expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$value" of required type "String!" was not provided.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 31, }, }, @@ -959,10 +959,10 @@ func TestVariables_ListsAndNullability_DoesNotAllowNonNullListsToBeNull(t *testi expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" of required type "[String]!" was not provided.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -1116,11 +1116,11 @@ func TestVariables_ListsAndNullability_DoesNotAllowListOfNonNullsToContainNull(t expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "[String!]" but got: ` + `["A",null,"B"].`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -1155,10 +1155,10 @@ func TestVariables_ListsAndNullability_DoesNotAllowNonNullListOfNonNullsToBeNull expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" of required type "[String!]!" was not provided.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -1223,11 +1223,11 @@ func TestVariables_ListsAndNullability_DoesNotAllowNonNullListOfNonNullsToContai expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "[String!]!" but got: ` + `["A",null,"B"].`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -1264,10 +1264,10 @@ func TestVariables_ListsAndNullability_DoesNotAllowInvalidTypesToBeUsedAsValues( expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "TestType!" which cannot be used as an input type.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, }, @@ -1302,10 +1302,10 @@ func TestVariables_ListsAndNullability_DoesNotAllowUnknownTypesToBeUsedAsValues( expected := &graphql.Result{ Data: nil, Errors: []gqlerrors.FormattedError{ - gqlerrors.FormattedError{ + { Message: `Variable "$input" expected value of type "UnknownType!" which cannot be used as an input type.`, Locations: []location.SourceLocation{ - location.SourceLocation{ + { Line: 2, Column: 17, }, },