Skip to content

Commit d77e137

Browse files
pavelnikolovKNiepok
authored andcommitted
Allow deprecated directive on arguments (graph-gophers#541)
1 parent 9e784f0 commit d77e137

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

example/social/introspect.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"description": "Marks an element of a GraphQL schema as no longer supported.",
1818
"locations": [
1919
"FIELD_DEFINITION",
20-
"ENUM_VALUE"
20+
"ENUM_VALUE",
21+
"ARGUMENT_DEFINITION"
2122
],
2223
"name": "deprecated"
2324
},

example/starwars/introspect.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"description": "Marks an element of a GraphQL schema as no longer supported.",
1818
"locations": [
1919
"FIELD_DEFINITION",
20-
"ENUM_VALUE"
20+
"ENUM_VALUE",
21+
"ARGUMENT_DEFINITION"
2122
],
2223
"name": "deprecated"
2324
},

graphql_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,23 @@ func TestEnums(t *testing.T) {
17021702
})
17031703
}
17041704

1705+
type testDeprecatedArgsResolver struct{}
1706+
1707+
func (r *testDeprecatedArgsResolver) A(args struct{ B *string }) int32 {
1708+
return 0
1709+
}
1710+
1711+
func TestDeprecatedArgs(t *testing.T) {
1712+
graphql.MustParseSchema(`
1713+
schema {
1714+
query: Query
1715+
}
1716+
type Query {
1717+
a(b: String @deprecated): Int!
1718+
}
1719+
`, &testDeprecatedArgsResolver{})
1720+
}
1721+
17051722
func TestInlineFragments(t *testing.T) {
17061723
gqltesting.RunTests(t, []*gqltesting.Test{
17071724
{
@@ -2475,7 +2492,8 @@ func TestIntrospection(t *testing.T) {
24752492
"description": "Marks an element of a GraphQL schema as no longer supported.",
24762493
"locations": [
24772494
"FIELD_DEFINITION",
2478-
"ENUM_VALUE"
2495+
"ENUM_VALUE",
2496+
"ARGUMENT_DEFINITION"
24792497
],
24802498
"args": [
24812499
{

internal/common/values.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ func ParseArgumentList(l *Lexer) types.ArgumentList {
2727
name := l.ConsumeIdentWithLoc()
2828
l.ConsumeToken(':')
2929
value := ParseLiteral(l, false)
30+
directives := ParseDirectives(l)
3031
args = append(args, &types.Argument{
31-
Name: name,
32-
Value: value,
32+
Name: name,
33+
Value: value,
34+
Directives: directives,
3335
})
3436
}
3537
l.ConsumeToken(')')

internal/schema/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var metaSrc = `
5757
# for how to access supported similar data. Formatted in
5858
# [Markdown](https://daringfireball.net/projects/markdown/).
5959
reason: String = "No longer supported"
60-
) on FIELD_DEFINITION | ENUM_VALUE
60+
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION
6161
6262
# Provides a scalar specification URL for specifying the behavior of custom scalar types.
6363
directive @specifiedBy(

types/argument.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ package types
44
//
55
// https://spec.graphql.org/draft/#sec-Language.Arguments
66
type Argument struct {
7-
Name Ident
8-
Value Value
7+
Name Ident
8+
Value Value
9+
Directives DirectiveList
910
}
1011

1112
// ArgumentList is a collection of GraphQL Arguments.

0 commit comments

Comments
 (0)