Skip to content

Commit

Permalink
Allow @deprecated directive on field args
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbretman authored and sqs committed Dec 18, 2022
1 parent b320b99 commit 05279fa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 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
25 changes: 22 additions & 3 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,8 @@ func TestFragments(t *testing.T) {
`,
},
{
Schema: starwarsSchema,
Query: `
Schema: starwarsSchema,
Query: `
query {
human(id: "1000") {
id
Expand Down Expand Up @@ -1733,6 +1733,24 @@ func TestEnums(t *testing.T) {
})
}

type testDeprecatedArgsResolver struct{}

func (r *testDeprecatedArgsResolver) A(ctx context.Context, 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 @@ -2506,7 +2524,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 05279fa

Please sign in to comment.