Skip to content

Commit c91a342

Browse files
feat: Aligns introspection to javascript
Matches with the reference implementation
1 parent e073ade commit c91a342

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Sources/GraphQL/Type/Directives.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum DirectiveLocation: String, Encodable {
88
case field = "FIELD"
99
case fragmentDefinition = "FRAGMENT_DEFINITION"
1010
case fragmentSpread = "FRAGMENT_SPREAD"
11+
case fragmentVariableDefinition = "FRAGMENT_VARIABLE_DEFINITION"
1112
case inlineFragment = "INLINE_FRAGMENT"
1213
case variableDefinition = "VARIABLE_DEFINITION"
1314
// Schema Definitions
@@ -69,7 +70,7 @@ public let GraphQLIncludeDirective = try! GraphQLDirective(
6970
name: "include",
7071
description:
7172
"Directs the executor to include this field or fragment only when " +
72-
"the `if` argument is true.",
73+
"the \\`if\\` argument is true.",
7374
locations: [
7475
.field,
7576
.fragmentSpread,
@@ -89,7 +90,7 @@ public let GraphQLIncludeDirective = try! GraphQLDirective(
8990
public let GraphQLSkipDirective = try! GraphQLDirective(
9091
name: "skip",
9192
description:
92-
"Directs the executor to skip this field or fragment when the `if` " +
93+
"Directs the executor to skip this field or fragment when the \\`if\\` " +
9394
"argument is true.",
9495
locations: [
9596
.field,
@@ -128,7 +129,8 @@ public let GraphQLDeprecatedDirective = try! GraphQLDirective(
128129
description:
129130
"Explains why this element was deprecated, usually also including a " +
130131
"suggestion for how to access supported similar data. Formatted " +
131-
"in [Markdown](https://daringfireball.net/projects/markdown/).",
132+
"using the Markdown syntax, as specified by [CommonMark]" +
133+
"(https://commonmark.org/).",
132134
defaultValue: defaulDeprecationReason
133135
),
134136
]
@@ -154,7 +156,7 @@ public let GraphQLSpecifiedByDirective = try! GraphQLDirective(
154156
*/
155157
public let GraphQLOneOfDirective = try! GraphQLDirective(
156158
name: "oneOf",
157-
description: "Indicates exactly one field must be supplied and this field must not be `null`.",
159+
description: "Indicates exactly one field must be supplied and this field must not be \\`null\\`.",
158160
locations: [.inputObject],
159161
args: [:]
160162
)

Sources/GraphQL/Type/Introspection.swift

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let __Schema = try! GraphQLObjectType(
77
"exposes all available types and directives on the server, as well as " +
88
"the entry points for query, mutation, and subscription operations.",
99
fields: [
10+
"description": GraphQLField(type: GraphQLString),
1011
"types": GraphQLField(
1112
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__Type))),
1213
description: "A list of all types supported by this server.",
@@ -75,7 +76,7 @@ let __Directive = try! GraphQLObjectType(
7576
description:
7677
"A Directive provides a way to describe alternate runtime execution and " +
7778
"type validation behavior in a GraphQL document." +
78-
"\n\nIn some cases, you need to provide options to alter GraphQL\"s " +
79+
"\n\nIn some cases, you need to provide options to alter GraphQL's " +
7980
"execution behavior in ways field arguments will not suffice, such as " +
8081
"conditionally including or skipping a field. Directives provide this by " +
8182
"describing additional information to the executor.",
@@ -86,6 +87,9 @@ let __Directive = try! GraphQLObjectType(
8687
"locations": GraphQLField(type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__DirectiveLocation)))),
8788
"args": GraphQLField(
8889
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
90+
args: [
91+
"includeDeprecated": GraphQLArgument(type: GraphQLBoolean, defaultValue: false),
92+
],
8993
resolve: { directive, _, _, _ -> [GraphQLArgumentDefinition]? in
9094
guard let directive = directive as? GraphQLDirective else {
9195
return nil
@@ -131,6 +135,14 @@ let __DirectiveLocation = try! GraphQLEnumType(
131135
value: Map(DirectiveLocation.inlineFragment.rawValue),
132136
description: "Location adjacent to an inline fragment."
133137
),
138+
"VARIABLE_DEFINITION": GraphQLEnumValue(
139+
value: Map(DirectiveLocation.variableDefinition.rawValue),
140+
description: "Location adjacent to an operation variable definition."
141+
),
142+
"FRAGMENT_VARIABLE_DEFINITION": GraphQLEnumValue(
143+
value: Map(DirectiveLocation.fragmentVariableDefinition.rawValue),
144+
description: "Location adjacent to a fragment variable definition."
145+
),
134146
"SCHEMA": GraphQLEnumValue(
135147
value: Map(DirectiveLocation.schema.rawValue),
136148
description: "Location adjacent to a schema definition."
@@ -183,10 +195,10 @@ let __Type: GraphQLObjectType = {
183195
name: "__Type",
184196
description:
185197
"The fundamental unit of any GraphQL Schema is the type. There are " +
186-
"many kinds of types in GraphQL as represented by the `__TypeKind` enum." +
198+
"many kinds of types in GraphQL as represented by the \\`__TypeKind\\` enum." +
187199
"\n\nDepending on the kind of a type, certain fields describe " +
188200
"information about that type. Scalar types provide no information " +
189-
"beyond a name and description and optional `specifiedByURL`, while Enum types provide their values. " +
201+
"beyond a name, description and optional \\`specifiedByURL\\`, while Enum types provide their values. " +
190202
"Object and Interface types provide the fields they describe. Abstract " +
191203
"types, Union and Interface, provide the Object types possible " +
192204
"at runtime. List and NonNull types compose other types.",
@@ -303,6 +315,12 @@ let __Type: GraphQLObjectType = {
303315
),
304316
"inputFields": GraphQLField(
305317
type: GraphQLList(GraphQLNonNull(__InputValue)),
318+
args: [
319+
"includeDeprecated": GraphQLArgument(
320+
type: GraphQLBoolean,
321+
defaultValue: false
322+
),
323+
],
306324
resolve: { type, _, _, _ -> [InputObjectFieldDefinition]? in
307325
guard let type = type as? GraphQLInputObjectType else {
308326
return nil
@@ -337,6 +355,9 @@ let __Field = try! GraphQLObjectType(
337355
"description": GraphQLField(type: GraphQLString),
338356
"args": GraphQLField(
339357
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
358+
args: [
359+
"includeDeprecated": GraphQLArgument(type: GraphQLBoolean, defaultValue: false),
360+
],
340361
resolve: { field, _, _, _ -> [GraphQLArgumentDefinition]? in
341362
guard let field = field as? GraphQLFieldDefinition else {
342363
return nil
@@ -386,6 +407,8 @@ let __InputValue = try! GraphQLObjectType(
386407
return .string(print(ast: literal))
387408
}
388409
),
410+
"isDeprecated": GraphQLField(type: GraphQLNonNull(GraphQLBoolean)),
411+
"deprecationReason": GraphQLField(type: GraphQLString),
389412
]
390413
)
391414

@@ -417,7 +440,7 @@ public enum TypeKind: String, Encodable {
417440

418441
let __TypeKind = try! GraphQLEnumType(
419442
name: "__TypeKind",
420-
description: "An enum describing what kind of type a given `__Type` is.",
443+
description: "An enum describing what kind of type a given \\`__Type\\` is.",
421444
values: [
422445
"SCALAR": GraphQLEnumValue(
423446
value: Map(TypeKind.scalar.rawValue),
@@ -426,37 +449,37 @@ let __TypeKind = try! GraphQLEnumType(
426449
"OBJECT": GraphQLEnumValue(
427450
value: Map(TypeKind.object.rawValue),
428451
description: "Indicates this type is an object. " +
429-
"`fields` and `interfaces` are valid fields."
452+
"\\`fields\\` and \\`interfaces\\` are valid fields."
430453
),
431454
"INTERFACE": GraphQLEnumValue(
432455
value: Map(TypeKind.interface.rawValue),
433456
description: "Indicates this type is an interface. " +
434-
"`fields`, `interfaces`, and `possibleTypes` are valid fields."
457+
"\\`fields\\`, \\`interfaces\\`, and \\`possibleTypes\\` are valid fields."
435458
),
436459
"UNION": GraphQLEnumValue(
437460
value: Map(TypeKind.union.rawValue),
438461
description: "Indicates this type is a union. " +
439-
"`possibleTypes` is a valid field."
462+
"\\`possibleTypes\\` is a valid field."
440463
),
441464
"ENUM": GraphQLEnumValue(
442465
value: Map(TypeKind.enum.rawValue),
443466
description: "Indicates this type is an enum. " +
444-
"`enumValues` is a valid field."
467+
"\\`enumValues\\` is a valid field."
445468
),
446469
"INPUT_OBJECT": GraphQLEnumValue(
447470
value: Map(TypeKind.inputObject.rawValue),
448471
description: "Indicates this type is an input object. " +
449-
"`inputFields` is a valid field."
472+
"\\`inputFields\\` is a valid field."
450473
),
451474
"LIST": GraphQLEnumValue(
452475
value: Map(TypeKind.list.rawValue),
453476
description: "Indicates this type is a list. " +
454-
"`ofType` is a valid field."
477+
"\\`ofType\\` is a valid field."
455478
),
456479
"NON_NULL": GraphQLEnumValue(
457480
value: Map(TypeKind.nonNull.rawValue),
458481
description: "Indicates this type is a non-null. " +
459-
"`ofType` is a valid field."
482+
"\\`ofType\\` is a valid field."
460483
),
461484
]
462485
)

0 commit comments

Comments
 (0)