Skip to content

Commit 05279fa

Browse files
jonbretmansqs
authored andcommitted
Allow @deprecated directive on field args
graph-gophers#243
1 parent b320b99 commit 05279fa

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
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: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,8 @@ func TestFragments(t *testing.T) {
11801180
`,
11811181
},
11821182
{
1183-
Schema: starwarsSchema,
1184-
Query: `
1183+
Schema: starwarsSchema,
1184+
Query: `
11851185
query {
11861186
human(id: "1000") {
11871187
id
@@ -1733,6 +1733,24 @@ func TestEnums(t *testing.T) {
17331733
})
17341734
}
17351735

1736+
type testDeprecatedArgsResolver struct{}
1737+
1738+
func (r *testDeprecatedArgsResolver) A(ctx context.Context, args struct{ B *string }) int32 {
1739+
return 0
1740+
}
1741+
1742+
func TestDeprecatedArgs(t *testing.T) {
1743+
graphql.MustParseSchema(`
1744+
schema {
1745+
query: Query
1746+
}
1747+
1748+
type Query {
1749+
a(b: String @deprecated): Int!
1750+
}
1751+
`, &testDeprecatedArgsResolver{})
1752+
}
1753+
17361754
func TestInlineFragments(t *testing.T) {
17371755
gqltesting.RunTests(t, []*gqltesting.Test{
17381756
{
@@ -2506,7 +2524,8 @@ func TestIntrospection(t *testing.T) {
25062524
"description": "Marks an element of a GraphQL schema as no longer supported.",
25072525
"locations": [
25082526
"FIELD_DEFINITION",
2509-
"ENUM_VALUE"
2527+
"ENUM_VALUE",
2528+
"ARGUMENT_DEFINITION"
25102529
],
25112530
"args": [
25122531
{

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)