Allow @deprecated directive on field args#243
Allow @deprecated directive on field args#243jonbretman wants to merge 1 commit intograph-gophers:masterfrom
Conversation
|
@tonyghita any thoughts? |
|
Is this part of the specification? I'd like to avoid straying too far from the spec. |
|
I believe so. It’s mentioned in the spec under InputValueDefinition - http://facebook.github.io/graphql/draft/#InputValueDefinition |
|
The specification for InputValueDefinition mentions directives, but the introspection specification leaves out deprecations on I think without special I'm going to close this change until the issue in the specification is resolved. |
|
Fair enough, thanks for looking into it. |
|
This is working its way into the spec graphql/graphql-spec#525 |
|
We're open to adding it once it is accepted into the specification 👍 |
|
It is now added into the specification: graphql/graphql-spec#805 (comment) |
|
And here is the diff that seems to work. Happy to submit another PR. diff --git a/example/social/introspect.json b/example/social/introspect.json
index 795803f..e474d79 100644
--- a/example/social/introspect.json
+++ b/example/social/introspect.json
@@ -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"
},
diff --git a/example/starwars/introspect.json b/example/starwars/introspect.json
index a25eace..009799f 100644
--- a/example/starwars/introspect.json
+++ b/example/starwars/introspect.json
@@ -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"
},
diff --git a/graphql_test.go b/graphql_test.go
index 76240d5..cb240d6 100644
--- a/graphql_test.go
+++ b/graphql_test.go
@@ -1180,8 +1180,8 @@ func TestFragments(t *testing.T) {
`,
},
{
- Schema: starwarsSchema,
- Query: `
+ Schema: starwarsSchema,
+ Query: `
query {
human(id: "1000") {
id
@@ -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{
{
@@ -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": [
{
diff --git a/internal/common/values.go b/internal/common/values.go
index 2d6e0b5..33f63d2 100644
--- a/internal/common/values.go
+++ b/internal/common/values.go
@@ -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(')')
diff --git a/internal/schema/meta.go b/internal/schema/meta.go
index 154c07c..7941a63 100644
--- a/internal/schema/meta.go
+++ b/internal/schema/meta.go
@@ -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(
diff --git a/types/argument.go b/types/argument.go
index b2681a2..72329da 100644
--- a/types/argument.go
+++ b/types/argument.go
@@ -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. |
|
@sqs thank you for commenting. Could you, please, open a new PR? I would be happy to review and merge it. |
|
@sqs I took the changes and raised a PR myself. |
Fixes #204