Skip to content

Commit

Permalink
Allow deprecated directive on arguments (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelnikolov authored Dec 19, 2022
1 parent e892575 commit 3951ad4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/social/introspect.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"description": "Marks an element of a GraphQL schema as no longer supported.",
"locations": [
"FIELD_DEFINITION",
"ENUM_VALUE"
"ENUM_VALUE",
"ARGUMENT_DEFINITION"
],
"name": "deprecated"
},
Expand Down
3 changes: 2 additions & 1 deletion example/starwars/introspect.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"description": "Marks an element of a GraphQL schema as no longer supported.",
"locations": [
"FIELD_DEFINITION",
"ENUM_VALUE"
"ENUM_VALUE",
"ARGUMENT_DEFINITION"
],
"name": "deprecated"
},
Expand Down
20 changes: 19 additions & 1 deletion graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,23 @@ func TestEnums(t *testing.T) {
})
}

type testDeprecatedArgsResolver struct{}

func (r *testDeprecatedArgsResolver) A(args struct{ B *string }) int32 {
return 0
}

func TestDeprecatedArgs(t *testing.T) {
graphql.MustParseSchema(`
schema {
query: Query
}
type Query {
a(b: String @deprecated): Int!
}
`, &testDeprecatedArgsResolver{})
}

func TestInlineFragments(t *testing.T) {
gqltesting.RunTests(t, []*gqltesting.Test{
{
Expand Down Expand Up @@ -2474,7 +2491,8 @@ func TestIntrospection(t *testing.T) {
"description": "Marks an element of a GraphQL schema as no longer supported.",
"locations": [
"FIELD_DEFINITION",
"ENUM_VALUE"
"ENUM_VALUE",
"ARGUMENT_DEFINITION"
],
"args": [
{
Expand Down
6 changes: 4 additions & 2 deletions internal/common/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ func ParseArgumentList(l *Lexer) types.ArgumentList {
name := l.ConsumeIdentWithLoc()
l.ConsumeToken(':')
value := ParseLiteral(l, false)
directives := ParseDirectives(l)
args = append(args, &types.Argument{
Name: name,
Value: value,
Name: name,
Value: value,
Directives: directives,
})
}
l.ConsumeToken(')')
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var metaSrc = `
# for how to access supported similar data. Formatted in
# [Markdown](https://daringfireball.net/projects/markdown/).
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION
# Provides a scalar specification URL for specifying the behavior of custom scalar types.
directive @specifiedBy(
Expand Down
5 changes: 3 additions & 2 deletions types/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ package types
//
// https://spec.graphql.org/draft/#sec-Language.Arguments
type Argument struct {
Name Ident
Value Value
Name Ident
Value Value
Directives DirectiveList
}

// ArgumentList is a collection of GraphQL Arguments.
Expand Down

0 comments on commit 3951ad4

Please sign in to comment.