Skip to content

Commit 4c8e56e

Browse files
committed
add deprecated fields to __Directive
1 parent 66d3de1 commit 4c8e56e

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Sources/GraphQL/Type/Introspection.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,45 @@ let __Directive = try! GraphQLObjectType(
9393
return directive.args
9494
}
9595
),
96+
// NOTE: the following three fields are deprecated and are no longer part
97+
// of the GraphQL specification.
98+
"onOperation": GraphQLField(
99+
type: GraphQLNonNull(GraphQLBoolean),
100+
deprecationReason: "Use `locations`.",
101+
resolve: { directive, _, _, _ in
102+
guard let d = directive as? GraphQLDirective else {
103+
return nil
104+
}
105+
106+
return d.locations.contains(.query) ||
107+
d.locations.contains(.mutation) ||
108+
d.locations.contains(.subscription)
109+
}
110+
),
111+
"onFragment": GraphQLField(
112+
type: GraphQLNonNull(GraphQLBoolean),
113+
deprecationReason: "Use `locations`.",
114+
resolve: { directive, _, _, _ in
115+
guard let d = directive as? GraphQLDirective else {
116+
return nil
117+
}
118+
119+
return d.locations.contains(.fragmentSpread) ||
120+
d.locations.contains(.inlineFragment) ||
121+
d.locations.contains(.fragmentDefinition)
122+
}
123+
),
124+
"onField": GraphQLField(
125+
type: GraphQLNonNull(GraphQLBoolean),
126+
deprecationReason: "Use `locations`.",
127+
resolve: { directive, _, _, _ in
128+
guard let d = directive as? GraphQLDirective else {
129+
return nil
130+
}
131+
132+
return d.locations.contains(.field)
133+
}
134+
),
96135
]
97136
)
98137

@@ -274,7 +313,7 @@ let __Type: GraphQLObjectType = try! GraphQLObjectType(
274313
if !arguments["includeDeprecated"].bool! {
275314
values = values.filter({ !$0.isDeprecated })
276315
}
277-
316+
278317
return values
279318
}
280319

@@ -288,7 +327,7 @@ let __Type: GraphQLObjectType = try! GraphQLObjectType(
288327
let fieldMap = type.fields
289328
return Array(fieldMap.values).sorted(by: { $0.name < $1.name })
290329
}
291-
330+
292331
return nil
293332
}
294333
),

0 commit comments

Comments
 (0)