Skip to content

Commit b25ae94

Browse files
committed
condense the spec defs appendix
1 parent cd0b8bd commit b25ae94

File tree

2 files changed

+45
-225
lines changed

2 files changed

+45
-225
lines changed
Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
1-
import { writeFile } from 'node:fs/promises';
2-
import { printIntrospectionSchema, buildSchema, specifiedScalarTypes, printType } from 'graphql';
1+
import prettier from "prettier";
2+
import { writeFile } from "node:fs/promises";
3+
import {
4+
printIntrospectionSchema,
5+
buildSchema,
6+
specifiedScalarTypes,
7+
printType,
8+
parse,
9+
print,
10+
visit,
11+
Kind
12+
} from "graphql";
13+
14+
function stripDescriptions(sdl) {
15+
const ast = parse(sdl);
16+
const noDescAst = visit(ast, {
17+
leave: (node) => ({ ...node, description: undefined })
18+
});
19+
return print(noDescAst);
20+
}
321

4-
const FILE = './spec/Appendix D -- Specified Definitions.md';
522
function printSpecifiedScalars() {
623
return specifiedScalarTypes
7-
.map((type) => printType(type))
8-
.join('\n\n');
24+
.map((type) => stripDescriptions(printType(type)))
25+
.join("\n\n");
926
}
1027

11-
const introspectionSchema = printIntrospectionSchema(buildSchema(`type Query { i: Int }`));
12-
const prefix = `
13-
# C. Appendix: Type System Definitions
28+
const introspectionSchema = stripDescriptions(
29+
printIntrospectionSchema(buildSchema(`type Query { i: Int }`))
30+
);
31+
32+
const allSpecifiedTypesSDL = prettier
33+
.format(printSpecifiedScalars() + "\n\n" + introspectionSchema, {
34+
parser: "graphql"
35+
})
36+
.trimEnd();
1437

15-
This appendix lists the specified type system definitions.
38+
await writeFile(
39+
"./spec/Appendix D -- Specified Definitions.md",
40+
`# D. Appendix: Type System Definitions
1641
17-
The descriptions are non-normative. Implementations are recommended to use them
18-
for consistency but different descriptions are allowed.
42+
This appendix lists all type system definitions specified in this document.
1943
2044
The order of types, fields, arguments, values and directives is non-normative.
2145
2246
\`\`\`graphql
23-
`
24-
25-
const suffix = `
47+
${allSpecifiedTypesSDL}
2648
\`\`\`
2749
`
28-
await writeFile(FILE, prefix + printSpecifiedScalars() + '\n\n' + introspectionSchema + suffix);
50+
);
Lines changed: 8 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,41 @@
11
# D. Appendix: Type System Definitions
22

3-
This appendix lists the specified type system definitions.
4-
5-
The descriptions are non-normative. Implementations are recommended to use them
6-
for consistency but different descriptions are allowed.
3+
This appendix lists all type system definitions specified in this document.
74

85
The order of types, fields, arguments, values and directives is non-normative.
96

107
```graphql
11-
"""
12-
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
13-
"""
148
scalar String
159

16-
"""
17-
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
18-
"""
1910
scalar Int
2011

21-
"""
22-
The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point).
23-
"""
2412
scalar Float
2513

26-
"""
27-
The `Boolean` scalar type represents `true` or `false`.
28-
"""
2914
scalar Boolean
3015

31-
"""
32-
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
33-
"""
3416
scalar ID
3517

36-
"""
37-
Directs the executor to include this field or fragment only when the `if` argument is true.
38-
"""
39-
directive @include(
40-
"""
41-
Included when true.
42-
"""
43-
if: Boolean!
44-
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
18+
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
4519

46-
"""
47-
Directs the executor to skip this field or fragment when the `if` argument is true.
48-
"""
49-
directive @skip(
50-
"""
51-
Skipped when true.
52-
"""
53-
if: Boolean!
54-
) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
20+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
5521

56-
"""
57-
Marks an element of a GraphQL schema as no longer supported.
58-
"""
5922
directive @deprecated(
60-
"""
61-
Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
62-
"""
6323
reason: String! = "No longer supported"
6424
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE
6525

66-
"""
67-
Exposes a URL that specifies the behavior of this scalar.
68-
"""
69-
directive @specifiedBy(
70-
"""
71-
The URL that specifies the behavior of this scalar.
72-
"""
73-
url: String!
74-
) on SCALAR
26+
directive @specifiedBy(url: String!) on SCALAR
27+
28+
directive @oneOf on INPUT_OBJECT
7529

76-
"""
77-
A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.
78-
"""
7930
type __Schema {
8031
description: String
81-
82-
"""
83-
A list of all types supported by this server.
84-
"""
8532
types: [__Type!]!
86-
87-
"""
88-
The type that query operations will be rooted at.
89-
"""
9033
queryType: __Type!
91-
92-
"""
93-
If this server supports mutation, the type that mutation operations will be rooted at.
94-
"""
9534
mutationType: __Type
96-
97-
"""
98-
If this server support subscription, the type that subscription operations will be rooted at.
99-
"""
10035
subscriptionType: __Type
101-
102-
"""
103-
A list of all directives supported by this server.
104-
"""
10536
directives: [__Directive!]!
10637
}
10738

108-
"""
109-
The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.
110-
111-
Depending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByURL`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.
112-
"""
11339
type __Type {
11440
kind: __TypeKind!
11541
name: String
@@ -121,56 +47,20 @@ type __Type {
12147
enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
12248
inputFields(includeDeprecated: Boolean = false): [__InputValue!]
12349
ofType: __Type
50+
isOneOf: Boolean
12451
}
12552

126-
"""
127-
An enum describing what kind of type a given `__Type` is.
128-
"""
12953
enum __TypeKind {
130-
"""
131-
Indicates this type is a scalar.
132-
"""
13354
SCALAR
134-
135-
"""
136-
Indicates this type is an object. `fields` and `interfaces` are valid fields.
137-
"""
13855
OBJECT
139-
140-
"""
141-
Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.
142-
"""
14356
INTERFACE
144-
145-
"""
146-
Indicates this type is a union. `possibleTypes` is a valid field.
147-
"""
14857
UNION
149-
150-
"""
151-
Indicates this type is an enum. `enumValues` is a valid field.
152-
"""
15358
ENUM
154-
155-
"""
156-
Indicates this type is an input object. `inputFields` is a valid field.
157-
"""
15859
INPUT_OBJECT
159-
160-
"""
161-
Indicates this type is a list. `ofType` is a valid field.
162-
"""
16360
LIST
164-
165-
"""
166-
Indicates this type is a non-null. `ofType` is a valid field.
167-
"""
16861
NON_NULL
16962
}
17063

171-
"""
172-
Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
173-
"""
17464
type __Field {
17565
name: String!
17666
description: String
@@ -180,37 +70,22 @@ type __Field {
18070
deprecationReason: String
18171
}
18272

183-
"""
184-
Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
185-
"""
18673
type __InputValue {
18774
name: String!
18875
description: String
18976
type: __Type!
190-
191-
"""
192-
A GraphQL-formatted string representing the default value for this input value.
193-
"""
19477
defaultValue: String
19578
isDeprecated: Boolean!
19679
deprecationReason: String
19780
}
19881

199-
"""
200-
One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
201-
"""
20282
type __EnumValue {
20383
name: String!
20484
description: String
20585
isDeprecated: Boolean!
20686
deprecationReason: String
20787
}
20888

209-
"""
210-
A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.
211-
212-
In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
213-
"""
21489
type __Directive {
21590
name: String!
21691
description: String
@@ -219,103 +94,26 @@ type __Directive {
21994
args(includeDeprecated: Boolean = false): [__InputValue!]!
22095
}
22196

222-
"""
223-
A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
224-
"""
22597
enum __DirectiveLocation {
226-
"""
227-
Location adjacent to a query operation.
228-
"""
22998
QUERY
230-
231-
"""
232-
Location adjacent to a mutation operation.
233-
"""
23499
MUTATION
235-
236-
"""
237-
Location adjacent to a subscription operation.
238-
"""
239100
SUBSCRIPTION
240-
241-
"""
242-
Location adjacent to a field.
243-
"""
244101
FIELD
245-
246-
"""
247-
Location adjacent to a fragment definition.
248-
"""
249102
FRAGMENT_DEFINITION
250-
251-
"""
252-
Location adjacent to a fragment spread.
253-
"""
254103
FRAGMENT_SPREAD
255-
256-
"""
257-
Location adjacent to an inline fragment.
258-
"""
259104
INLINE_FRAGMENT
260-
261-
"""
262-
Location adjacent to an operation variable definition.
263-
"""
264105
VARIABLE_DEFINITION
265-
266-
"""
267-
Location adjacent to a schema definition.
268-
"""
106+
FRAGMENT_VARIABLE_DEFINITION
269107
SCHEMA
270-
271-
"""
272-
Location adjacent to a scalar definition.
273-
"""
274108
SCALAR
275-
276-
"""
277-
Location adjacent to an object type definition.
278-
"""
279109
OBJECT
280-
281-
"""
282-
Location adjacent to a field definition.
283-
"""
284110
FIELD_DEFINITION
285-
286-
"""
287-
Location adjacent to an argument definition.
288-
"""
289111
ARGUMENT_DEFINITION
290-
291-
"""
292-
Location adjacent to an interface definition.
293-
"""
294112
INTERFACE
295-
296-
"""
297-
Location adjacent to a union definition.
298-
"""
299113
UNION
300-
301-
"""
302-
Location adjacent to an enum definition.
303-
"""
304114
ENUM
305-
306-
"""
307-
Location adjacent to an enum value definition.
308-
"""
309115
ENUM_VALUE
310-
311-
"""
312-
Location adjacent to an input object type definition.
313-
"""
314116
INPUT_OBJECT
315-
316-
"""
317-
Location adjacent to an input object field definition.
318-
"""
319117
INPUT_FIELD_DEFINITION
320118
}
321119
```

0 commit comments

Comments
 (0)