Skip to content

Commit 9aa9cd5

Browse files
fix(introspection): support @deprecated directive on field arguments (#3949)
1 parent 9da91b3 commit 9aa9cd5

12 files changed

Lines changed: 284 additions & 1 deletion

File tree

codegen/testserver/followschema/introspection_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,45 @@ func TestIntrospection(t *testing.T) {
6767
require.Equal(t, "id", resp.Type.Fields[0].Name)
6868
require.Nil(t, resp.Type.Fields[0].DeprecationReason)
6969
})
70+
71+
t.Run("deprecated directive on field arguments", func(t *testing.T) {
72+
var resp struct {
73+
Type struct {
74+
Fields []struct {
75+
Name string
76+
Args []struct {
77+
Name string
78+
DeprecationReason *string
79+
}
80+
}
81+
} `json:"__type"`
82+
}
83+
84+
err := c.Post(
85+
`{ __type(name:"Query") { fields { name args { name deprecationReason }}}}`,
86+
&resp,
87+
)
88+
require.NoError(t, err)
89+
90+
var args []struct {
91+
Name string
92+
DeprecationReason *string
93+
}
94+
for _, f := range resp.Type.Fields {
95+
if f.Name == "fieldWithDeprecatedArg" {
96+
args = f.Args
97+
break
98+
}
99+
}
100+
101+
require.Len(t, args, 2)
102+
require.Equal(t, "oldArg", args[0].Name)
103+
require.NotNil(t, args[0].DeprecationReason)
104+
require.Equal(t, "old arg", *args[0].DeprecationReason)
105+
106+
require.Equal(t, "newArg", args[1].Name)
107+
require.Nil(t, args[1].DeprecationReason)
108+
})
70109
})
71110

72111
t.Run("disabled by middleware", func(t *testing.T) {

codegen/testserver/followschema/resolver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func (r *queryResolver) DeprecatedField(ctx context.Context) (string, error) {
192192
panic("not implemented")
193193
}
194194

195+
// FieldWithDeprecatedArg is the resolver for the fieldWithDeprecatedArg field.
196+
func (r *queryResolver) FieldWithDeprecatedArg(ctx context.Context, oldArg *int, newArg *int) (*string, error) {
197+
panic("not implemented")
198+
}
199+
195200
// Overlapping is the resolver for the overlapping field.
196201
func (r *queryResolver) Overlapping(ctx context.Context) (*OverlappingFields, error) {
197202
panic("not implemented")

codegen/testserver/followschema/root_.generated.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/testserver/followschema/schema.generated.go

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/testserver/followschema/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Query {
2929
shapeUnion: ShapeUnion!
3030
autobind: Autobind
3131
deprecatedField: String! @deprecated(reason: "test deprecated directive")
32+
fieldWithDeprecatedArg(oldArg: Int @deprecated(reason: "old arg"), newArg: Int): String
3233
}
3334

3435
type Subscription {

codegen/testserver/followschema/stub.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/testserver/singlefile/generated.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)