joist-graphql-codegen 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/generateGraphqlCodegen.d.ts.map +1 -1
- package/build/generateGraphqlCodegen.js +8 -0
- package/build/generateGraphqlCodegen.js.map +1 -1
- package/build/generateGraphqlCodegen.test.js +20 -7
- package/build/generateGraphqlCodegen.test.js.map +1 -1
- package/build/generateGraphqlSchemaFiles.d.ts +2 -2
- package/build/generateGraphqlSchemaFiles.d.ts.map +1 -1
- package/build/generateGraphqlSchemaFiles.js +115 -17
- package/build/generateGraphqlSchemaFiles.js.map +1 -1
- package/build/generateGraphqlSchemaFiles.test.js +705 -196
- package/build/generateGraphqlSchemaFiles.test.js.map +1 -1
- package/build/generateQueryPageResolvers.d.ts +5 -0
- package/build/generateQueryPageResolvers.d.ts.map +1 -0
- package/build/generateQueryPageResolvers.js +52 -0
- package/build/generateQueryPageResolvers.js.map +1 -0
- package/build/generateQueryPageResolvers.test.d.ts +2 -0
- package/build/generateQueryPageResolvers.test.d.ts.map +1 -0
- package/build/generateQueryPageResolvers.test.js +46 -0
- package/build/generateQueryPageResolvers.test.js.map +1 -0
- package/build/generateQueryResolvers.d.ts.map +1 -1
- package/build/generateQueryResolvers.js +5 -4
- package/build/generateQueryResolvers.js.map +1 -1
- package/build/generateQueryResolvers.test.js +6 -2
- package/build/generateQueryResolvers.test.js.map +1 -1
- package/build/generateResolverUtils.d.ts +5 -0
- package/build/generateResolverUtils.d.ts.map +1 -0
- package/build/generateResolverUtils.js +36 -0
- package/build/generateResolverUtils.js.map +1 -0
- package/build/generateResolverUtils.test.d.ts +2 -0
- package/build/generateResolverUtils.test.d.ts.map +1 -0
- package/build/generateResolverUtils.test.js +53 -0
- package/build/generateResolverUtils.test.js.map +1 -0
- package/build/graphqlUtils.d.ts +1 -1
- package/build/graphqlUtils.d.ts.map +1 -1
- package/build/graphqlUtils.js +39 -16
- package/build/graphqlUtils.js.map +1 -1
- package/build/history.d.ts.map +1 -1
- package/build/history.js +3 -2
- package/build/history.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -3
- package/build/index.js.map +1 -1
- package/build/testUtils.d.ts +11 -1
- package/build/testUtils.d.ts.map +1 -1
- package/build/testUtils.js +21 -0
- package/build/testUtils.js.map +1 -1
- package/package.json +10 -10
|
@@ -14,24 +14,220 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
14
14
|
await generate(fs, entities);
|
|
15
15
|
// We now have a graphql file
|
|
16
16
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
"extend type Query {
|
|
18
|
+
author(id: ID!): Author!
|
|
19
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
extend type Mutation {
|
|
23
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type AuthorsConnection {
|
|
27
|
+
edges: [AuthorsEdge!]!
|
|
28
|
+
nodes: [Author!]!
|
|
29
|
+
pageInfo: PageInfo!
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type AuthorsEdge {
|
|
33
|
+
node: Author!
|
|
34
|
+
cursor: String!
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Author {
|
|
38
|
+
id: ID!
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
input AuthorFilter {
|
|
42
|
+
id: [ID!]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
input SaveAuthorInput {
|
|
46
|
+
id: ID
|
|
47
|
+
}
|
|
24
48
|
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
type SaveAuthorResult {
|
|
50
|
+
author: Author!
|
|
51
|
+
}
|
|
52
|
+
"
|
|
53
|
+
`);
|
|
54
|
+
expect(await fs.load("pageInfo.graphql")).toMatchInlineSnapshot(`
|
|
55
|
+
"type PageInfo {
|
|
56
|
+
hasNextPage: Boolean!
|
|
57
|
+
hasPreviousPage: Boolean!
|
|
58
|
+
totalCount: Int!
|
|
59
|
+
startCursor: String
|
|
60
|
+
endCursor: String
|
|
27
61
|
}
|
|
62
|
+
"
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
it("generates cursor query fields by default", async () => {
|
|
66
|
+
const entities = [(0, testUtils_1.newEntityMetadata)("Author")];
|
|
67
|
+
const fs = (0, testUtils_1.newFs)({});
|
|
68
|
+
await generate(fs, entities);
|
|
69
|
+
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
70
|
+
"extend type Query {
|
|
71
|
+
author(id: ID!): Author!
|
|
72
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
extend type Mutation {
|
|
76
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type AuthorsConnection {
|
|
80
|
+
edges: [AuthorsEdge!]!
|
|
81
|
+
nodes: [Author!]!
|
|
82
|
+
pageInfo: PageInfo!
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type AuthorsEdge {
|
|
86
|
+
node: Author!
|
|
87
|
+
cursor: String!
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type Author {
|
|
91
|
+
id: ID!
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
input AuthorFilter {
|
|
95
|
+
id: [ID!]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
input SaveAuthorInput {
|
|
99
|
+
id: ID
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type SaveAuthorResult {
|
|
103
|
+
author: Author!
|
|
104
|
+
}
|
|
105
|
+
"
|
|
106
|
+
`);
|
|
107
|
+
});
|
|
108
|
+
it("generates limit query fields", async () => {
|
|
109
|
+
const entities = [(0, testUtils_1.newEntityMetadata)("Author")];
|
|
110
|
+
const fs = (0, testUtils_1.newFs)({});
|
|
111
|
+
await generate(fs, entities, { paginationStyle: "limit" });
|
|
112
|
+
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
113
|
+
"extend type Query {
|
|
114
|
+
author(id: ID!): Author!
|
|
115
|
+
authors(filter: AuthorFilter, limit: Int, offset: Int): AuthorsPage!
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
extend type Mutation {
|
|
119
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
120
|
+
}
|
|
28
121
|
|
|
29
|
-
|
|
30
|
-
|
|
122
|
+
type AuthorsPage {
|
|
123
|
+
entities: [Author!]!
|
|
124
|
+
pageInfo: PageInfo!
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type Author {
|
|
128
|
+
id: ID!
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
input AuthorFilter {
|
|
132
|
+
id: [ID!]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
input SaveAuthorInput {
|
|
136
|
+
id: ID
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type SaveAuthorResult {
|
|
140
|
+
author: Author!
|
|
141
|
+
}
|
|
142
|
+
"
|
|
143
|
+
`);
|
|
144
|
+
expect(await fs.load("pageInfo.graphql")).toMatchInlineSnapshot(`
|
|
145
|
+
"type PageInfo {
|
|
146
|
+
hasNextPage: Boolean!
|
|
147
|
+
hasPreviousPage: Boolean!
|
|
148
|
+
totalCount: Int!
|
|
149
|
+
nextPage: Int
|
|
150
|
+
currentPage: Int
|
|
31
151
|
}
|
|
32
152
|
"
|
|
33
153
|
`);
|
|
34
154
|
});
|
|
155
|
+
it("generates filter fields", async () => {
|
|
156
|
+
const entities = [
|
|
157
|
+
(0, testUtils_1.newEntityMetadata)("Publisher"),
|
|
158
|
+
(0, testUtils_1.newEntityMetadata)("Book"),
|
|
159
|
+
(0, testUtils_1.newEntityMetadata)("Author", {
|
|
160
|
+
primitives: [
|
|
161
|
+
(0, testUtils_1.newPrimitiveField)("firstName"),
|
|
162
|
+
(0, testUtils_1.newPrimitiveField)("nickNames", { isArray: true }),
|
|
163
|
+
(0, testUtils_1.newPrimitiveField)("numberOfAtoms", { columnType: "bigint", fieldType: "bigint", rawFieldType: "bigint" }),
|
|
164
|
+
],
|
|
165
|
+
enums: [(0, testUtils_1.newEnumField)("color")],
|
|
166
|
+
manyToOnes: [(0, testUtils_1.newManyToOneField)("publisher", "Publisher")],
|
|
167
|
+
polymorphics: [(0, testUtils_1.newPolymorphicField)("favorite", ["Book", "Publisher"])],
|
|
168
|
+
}),
|
|
169
|
+
];
|
|
170
|
+
const fs = (0, testUtils_1.newFs)({});
|
|
171
|
+
await generate(fs, entities);
|
|
172
|
+
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
173
|
+
"extend type Query {
|
|
174
|
+
author(id: ID!): Author!
|
|
175
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
extend type Mutation {
|
|
179
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type AuthorsConnection {
|
|
183
|
+
edges: [AuthorsEdge!]!
|
|
184
|
+
nodes: [Author!]!
|
|
185
|
+
pageInfo: PageInfo!
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
type AuthorsEdge {
|
|
189
|
+
node: Author!
|
|
190
|
+
cursor: String!
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type Author {
|
|
194
|
+
id: ID!
|
|
195
|
+
firstName: String!
|
|
196
|
+
nickNames: [String!]!
|
|
197
|
+
numberOfAtoms: BigInt!
|
|
198
|
+
color: ColorDetail!
|
|
199
|
+
publisher: Publisher!
|
|
200
|
+
favorite: FavoriteParent
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
input AuthorFilter {
|
|
204
|
+
id: [ID!]
|
|
205
|
+
firstName: [String!]
|
|
206
|
+
nickNames: [[String!]!]
|
|
207
|
+
numberOfAtoms: [BigInt!]
|
|
208
|
+
color: [Color!]
|
|
209
|
+
publisherId: [ID!]
|
|
210
|
+
favoriteId: [ID!]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
input SaveAuthorInput {
|
|
214
|
+
id: ID
|
|
215
|
+
firstName: String
|
|
216
|
+
nickNames: [String!]
|
|
217
|
+
numberOfAtoms: BigInt
|
|
218
|
+
color: Color
|
|
219
|
+
publisherId: ID
|
|
220
|
+
favoriteId: ID
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
type SaveAuthorResult {
|
|
224
|
+
author: Author!
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
union FavoriteParent = Book | Publisher
|
|
228
|
+
"
|
|
229
|
+
`);
|
|
230
|
+
});
|
|
35
231
|
it("adds a new field to existing file", async () => {
|
|
36
232
|
// Given an author with a primitive field
|
|
37
233
|
const entities = [
|
|
@@ -49,43 +245,88 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
49
245
|
await generate(fs, entities);
|
|
50
246
|
// Then we added the new field
|
|
51
247
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
248
|
+
"extend type Query {
|
|
249
|
+
author(id: ID!): Author!
|
|
250
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
251
|
+
}
|
|
56
252
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
253
|
+
extend type Mutation {
|
|
254
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
255
|
+
}
|
|
61
256
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
257
|
+
type Author {
|
|
258
|
+
id: ID!
|
|
259
|
+
firstName: String!
|
|
260
|
+
}
|
|
65
261
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
262
|
+
input SaveAuthorInput {
|
|
263
|
+
id: ID
|
|
264
|
+
firstName: String
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
type AuthorsConnection {
|
|
268
|
+
edges: [AuthorsEdge!]!
|
|
269
|
+
nodes: [Author!]!
|
|
270
|
+
pageInfo: PageInfo!
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
type AuthorsEdge {
|
|
274
|
+
node: Author!
|
|
275
|
+
cursor: String!
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
input AuthorFilter {
|
|
279
|
+
id: [ID!]
|
|
280
|
+
firstName: [String!]
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type SaveAuthorResult {
|
|
284
|
+
author: Author!
|
|
285
|
+
}
|
|
286
|
+
"
|
|
70
287
|
`);
|
|
71
288
|
// And saved it in the history
|
|
72
289
|
expect(JSON.parse((await fs.load(".history.json")) || "")).toMatchInlineSnapshot(`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
290
|
+
{
|
|
291
|
+
"Author": [
|
|
292
|
+
"firstName",
|
|
293
|
+
"id",
|
|
294
|
+
],
|
|
295
|
+
"AuthorFilter": [
|
|
296
|
+
"firstName",
|
|
297
|
+
"id",
|
|
298
|
+
],
|
|
299
|
+
"AuthorsConnection": [
|
|
300
|
+
"edges",
|
|
301
|
+
"nodes",
|
|
302
|
+
"pageInfo",
|
|
303
|
+
],
|
|
304
|
+
"AuthorsEdge": [
|
|
305
|
+
"cursor",
|
|
306
|
+
"node",
|
|
307
|
+
],
|
|
308
|
+
"Mutation": [
|
|
309
|
+
"saveAuthor",
|
|
310
|
+
],
|
|
311
|
+
"PageInfo": [
|
|
312
|
+
"endCursor",
|
|
313
|
+
"hasNextPage",
|
|
314
|
+
"hasPreviousPage",
|
|
315
|
+
"startCursor",
|
|
316
|
+
"totalCount",
|
|
317
|
+
],
|
|
318
|
+
"Query": [
|
|
319
|
+
"author",
|
|
320
|
+
"authors",
|
|
321
|
+
],
|
|
322
|
+
"SaveAuthorInput": [
|
|
323
|
+
"firstName",
|
|
324
|
+
"id",
|
|
325
|
+
],
|
|
326
|
+
"SaveAuthorResult": [
|
|
327
|
+
"author",
|
|
328
|
+
],
|
|
329
|
+
}
|
|
89
330
|
`);
|
|
90
331
|
});
|
|
91
332
|
it("does not overwrite existing fields", async () => {
|
|
@@ -103,26 +344,92 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
103
344
|
await generate(fs, entities);
|
|
104
345
|
// We added the new field, but did not did the custom field
|
|
105
346
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
347
|
+
"extend type Query {
|
|
348
|
+
author(id: ID!): Author!
|
|
349
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
350
|
+
}
|
|
111
351
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
firstName: String
|
|
116
|
-
}
|
|
352
|
+
extend type Mutation {
|
|
353
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
354
|
+
}
|
|
117
355
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
356
|
+
type Author {
|
|
357
|
+
id: ID!
|
|
358
|
+
customField: String
|
|
359
|
+
firstName: String!
|
|
360
|
+
}
|
|
121
361
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
362
|
+
input SaveAuthorInput {
|
|
363
|
+
id: ID
|
|
364
|
+
customField: String
|
|
365
|
+
firstName: String
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
type AuthorsConnection {
|
|
369
|
+
edges: [AuthorsEdge!]!
|
|
370
|
+
nodes: [Author!]!
|
|
371
|
+
pageInfo: PageInfo!
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
type AuthorsEdge {
|
|
375
|
+
node: Author!
|
|
376
|
+
cursor: String!
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
input AuthorFilter {
|
|
380
|
+
id: [ID!]
|
|
381
|
+
firstName: [String!]
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
type SaveAuthorResult {
|
|
385
|
+
author: Author!
|
|
386
|
+
}
|
|
387
|
+
"
|
|
388
|
+
`);
|
|
389
|
+
});
|
|
390
|
+
it("does not re-add fields from existing type extensions", async () => {
|
|
391
|
+
const entities = [(0, testUtils_1.newEntityMetadata)("Author")];
|
|
392
|
+
const fs = (0, testUtils_1.newFs)({
|
|
393
|
+
"author.graphql": "extend type Query { authors: [Author!]! author(id: ID!): Author } type Author { id: ID! }",
|
|
394
|
+
});
|
|
395
|
+
await generate(fs, entities);
|
|
396
|
+
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
397
|
+
"extend type Query {
|
|
398
|
+
authors: [Author!]!
|
|
399
|
+
author(id: ID!): Author
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
extend type Mutation {
|
|
403
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
type Author {
|
|
407
|
+
id: ID!
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
type AuthorsConnection {
|
|
411
|
+
edges: [AuthorsEdge!]!
|
|
412
|
+
nodes: [Author!]!
|
|
413
|
+
pageInfo: PageInfo!
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
type AuthorsEdge {
|
|
417
|
+
node: Author!
|
|
418
|
+
cursor: String!
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
input AuthorFilter {
|
|
422
|
+
id: [ID!]
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
input SaveAuthorInput {
|
|
426
|
+
id: ID
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
type SaveAuthorResult {
|
|
430
|
+
author: Author!
|
|
431
|
+
}
|
|
432
|
+
"
|
|
126
433
|
`);
|
|
127
434
|
});
|
|
128
435
|
it("does not re-add fields in the history file", async () => {
|
|
@@ -142,23 +449,44 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
142
449
|
await generate(fs, entities);
|
|
143
450
|
// Then we did not re-add it as a new field
|
|
144
451
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
452
|
+
"extend type Query {
|
|
453
|
+
author(id: ID!): Author!
|
|
454
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
455
|
+
}
|
|
148
456
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
457
|
+
extend type Mutation {
|
|
458
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
459
|
+
}
|
|
152
460
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
461
|
+
type Author {
|
|
462
|
+
id: ID!
|
|
463
|
+
}
|
|
157
464
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
465
|
+
type AuthorsConnection {
|
|
466
|
+
edges: [AuthorsEdge!]!
|
|
467
|
+
nodes: [Author!]!
|
|
468
|
+
pageInfo: PageInfo!
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
type AuthorsEdge {
|
|
472
|
+
node: Author!
|
|
473
|
+
cursor: String!
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
input AuthorFilter {
|
|
477
|
+
id: [ID!]
|
|
478
|
+
firstName: [String!]
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
input SaveAuthorInput {
|
|
482
|
+
id: ID
|
|
483
|
+
firstName: String
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
type SaveAuthorResult {
|
|
487
|
+
author: Author!
|
|
488
|
+
}
|
|
489
|
+
"
|
|
162
490
|
`);
|
|
163
491
|
});
|
|
164
492
|
it("keeps comments", async () => {
|
|
@@ -180,26 +508,47 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
180
508
|
await generate(fs, entities);
|
|
181
509
|
// Then we added the new field
|
|
182
510
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
firstName: String!
|
|
188
|
-
}
|
|
511
|
+
"extend type Query {
|
|
512
|
+
author(id: ID!): Author!
|
|
513
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
514
|
+
}
|
|
189
515
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
516
|
+
extend type Mutation {
|
|
517
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
518
|
+
}
|
|
194
519
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
520
|
+
" The author. "
|
|
521
|
+
type Author {
|
|
522
|
+
" The id. "
|
|
523
|
+
id: ID!
|
|
524
|
+
firstName: String!
|
|
525
|
+
}
|
|
198
526
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
527
|
+
input SaveAuthorInput {
|
|
528
|
+
id: ID
|
|
529
|
+
firstName: String
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
type AuthorsConnection {
|
|
533
|
+
edges: [AuthorsEdge!]!
|
|
534
|
+
nodes: [Author!]!
|
|
535
|
+
pageInfo: PageInfo!
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
type AuthorsEdge {
|
|
539
|
+
node: Author!
|
|
540
|
+
cursor: String!
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
input AuthorFilter {
|
|
544
|
+
id: [ID!]
|
|
545
|
+
firstName: [String!]
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
type SaveAuthorResult {
|
|
549
|
+
author: Author!
|
|
550
|
+
}
|
|
551
|
+
"
|
|
203
552
|
`);
|
|
204
553
|
});
|
|
205
554
|
it("does not add derived fields to inputs", async () => {
|
|
@@ -219,25 +568,47 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
219
568
|
await generate(fs, entities);
|
|
220
569
|
// Then the input does not have the createdAt field
|
|
221
570
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
571
|
+
"extend type Query {
|
|
572
|
+
author(id: ID!): Author!
|
|
573
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
574
|
+
}
|
|
225
575
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
createdAt: String!
|
|
230
|
-
}
|
|
576
|
+
extend type Mutation {
|
|
577
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
578
|
+
}
|
|
231
579
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
580
|
+
type AuthorsConnection {
|
|
581
|
+
edges: [AuthorsEdge!]!
|
|
582
|
+
nodes: [Author!]!
|
|
583
|
+
pageInfo: PageInfo!
|
|
584
|
+
}
|
|
236
585
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
586
|
+
type AuthorsEdge {
|
|
587
|
+
node: Author!
|
|
588
|
+
cursor: String!
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
type Author {
|
|
592
|
+
id: ID!
|
|
593
|
+
firstName: String!
|
|
594
|
+
createdAt: String!
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
input AuthorFilter {
|
|
598
|
+
id: [ID!]
|
|
599
|
+
firstName: [String!]
|
|
600
|
+
createdAt: [String!]
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
input SaveAuthorInput {
|
|
604
|
+
id: ID
|
|
605
|
+
firstName: String
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
type SaveAuthorResult {
|
|
609
|
+
author: Author!
|
|
610
|
+
}
|
|
611
|
+
"
|
|
241
612
|
`);
|
|
242
613
|
});
|
|
243
614
|
it("can output both Date and DateTime types for Temporal types", async () => {
|
|
@@ -261,30 +632,54 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
261
632
|
await generate(fs, entities);
|
|
262
633
|
// Then the input has both types of fields as appropriate
|
|
263
634
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
635
|
+
"extend type Query {
|
|
636
|
+
author(id: ID!): Author!
|
|
637
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
638
|
+
}
|
|
267
639
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
createdAt: DateTime!
|
|
272
|
-
startTime: DateTime!
|
|
273
|
-
startDate: Date!
|
|
274
|
-
}
|
|
640
|
+
extend type Mutation {
|
|
641
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
642
|
+
}
|
|
275
643
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
startDate: Date
|
|
282
|
-
}
|
|
644
|
+
type AuthorsConnection {
|
|
645
|
+
edges: [AuthorsEdge!]!
|
|
646
|
+
nodes: [Author!]!
|
|
647
|
+
pageInfo: PageInfo!
|
|
648
|
+
}
|
|
283
649
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
650
|
+
type AuthorsEdge {
|
|
651
|
+
node: Author!
|
|
652
|
+
cursor: String!
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
type Author {
|
|
656
|
+
id: ID!
|
|
657
|
+
firstName: String!
|
|
658
|
+
createdAt: DateTime!
|
|
659
|
+
startTime: DateTime!
|
|
660
|
+
startDate: Date!
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
input AuthorFilter {
|
|
664
|
+
id: [ID!]
|
|
665
|
+
firstName: [String!]
|
|
666
|
+
createdAt: [DateTime!]
|
|
667
|
+
startTime: [DateTime!]
|
|
668
|
+
startDate: [Date!]
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
input SaveAuthorInput {
|
|
672
|
+
id: ID
|
|
673
|
+
firstName: String
|
|
674
|
+
createdAt: DateTime
|
|
675
|
+
startTime: DateTime
|
|
676
|
+
startDate: Date
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
type SaveAuthorResult {
|
|
680
|
+
author: Author!
|
|
681
|
+
}
|
|
682
|
+
"
|
|
288
683
|
`);
|
|
289
684
|
});
|
|
290
685
|
it("can output both Date and DateTime types for legacy Date fields", async () => {
|
|
@@ -306,28 +701,51 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
306
701
|
await generate(fs, entities);
|
|
307
702
|
// Then the Author links to a PublisherLike
|
|
308
703
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
704
|
+
"extend type Query {
|
|
705
|
+
author(id: ID!): Author!
|
|
706
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
707
|
+
}
|
|
312
708
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
createdAt: DateTime!
|
|
317
|
-
startDate: Date!
|
|
318
|
-
}
|
|
709
|
+
extend type Mutation {
|
|
710
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
711
|
+
}
|
|
319
712
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
713
|
+
type AuthorsConnection {
|
|
714
|
+
edges: [AuthorsEdge!]!
|
|
715
|
+
nodes: [Author!]!
|
|
716
|
+
pageInfo: PageInfo!
|
|
717
|
+
}
|
|
326
718
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
719
|
+
type AuthorsEdge {
|
|
720
|
+
node: Author!
|
|
721
|
+
cursor: String!
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
type Author {
|
|
725
|
+
id: ID!
|
|
726
|
+
firstName: String!
|
|
727
|
+
createdAt: DateTime!
|
|
728
|
+
startDate: Date!
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
input AuthorFilter {
|
|
732
|
+
id: [ID!]
|
|
733
|
+
firstName: [String!]
|
|
734
|
+
createdAt: [DateTime!]
|
|
735
|
+
startDate: [Date!]
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
input SaveAuthorInput {
|
|
739
|
+
id: ID
|
|
740
|
+
firstName: String
|
|
741
|
+
createdAt: DateTime
|
|
742
|
+
startDate: Date
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
type SaveAuthorResult {
|
|
746
|
+
author: Author!
|
|
747
|
+
}
|
|
748
|
+
"
|
|
331
749
|
`);
|
|
332
750
|
});
|
|
333
751
|
it("adds enum details", async () => {
|
|
@@ -343,24 +761,45 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
343
761
|
await generate(fs, entities);
|
|
344
762
|
// Then the input has both types of fields as appropriate
|
|
345
763
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
764
|
+
"extend type Query {
|
|
765
|
+
author(id: ID!): Author!
|
|
766
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
767
|
+
}
|
|
349
768
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
769
|
+
extend type Mutation {
|
|
770
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
771
|
+
}
|
|
354
772
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
773
|
+
type AuthorsConnection {
|
|
774
|
+
edges: [AuthorsEdge!]!
|
|
775
|
+
nodes: [Author!]!
|
|
776
|
+
pageInfo: PageInfo!
|
|
777
|
+
}
|
|
359
778
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
779
|
+
type AuthorsEdge {
|
|
780
|
+
node: Author!
|
|
781
|
+
cursor: String!
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
type Author {
|
|
785
|
+
id: ID!
|
|
786
|
+
color: ColorDetail!
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
input AuthorFilter {
|
|
790
|
+
id: [ID!]
|
|
791
|
+
color: [Color!]
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
input SaveAuthorInput {
|
|
795
|
+
id: ID
|
|
796
|
+
color: Color
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
type SaveAuthorResult {
|
|
800
|
+
author: Author!
|
|
801
|
+
}
|
|
802
|
+
"
|
|
364
803
|
`);
|
|
365
804
|
});
|
|
366
805
|
it("can enum array types", async () => {
|
|
@@ -376,24 +815,45 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
376
815
|
await generate(fs, entities);
|
|
377
816
|
// Then the input has both types of fields as appropriate
|
|
378
817
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
818
|
+
"extend type Query {
|
|
819
|
+
author(id: ID!): Author!
|
|
820
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
821
|
+
}
|
|
382
822
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
823
|
+
extend type Mutation {
|
|
824
|
+
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
825
|
+
}
|
|
387
826
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
827
|
+
type AuthorsConnection {
|
|
828
|
+
edges: [AuthorsEdge!]!
|
|
829
|
+
nodes: [Author!]!
|
|
830
|
+
pageInfo: PageInfo!
|
|
831
|
+
}
|
|
392
832
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
833
|
+
type AuthorsEdge {
|
|
834
|
+
node: Author!
|
|
835
|
+
cursor: String!
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
type Author {
|
|
839
|
+
id: ID!
|
|
840
|
+
color: [Color!]!
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
input AuthorFilter {
|
|
844
|
+
id: [ID!]
|
|
845
|
+
color: [[Color!]!]
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
input SaveAuthorInput {
|
|
849
|
+
id: ID
|
|
850
|
+
color: [Color!]
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
type SaveAuthorResult {
|
|
854
|
+
author: Author!
|
|
855
|
+
}
|
|
856
|
+
"
|
|
397
857
|
`);
|
|
398
858
|
});
|
|
399
859
|
it("adds inherited fields", async () => {
|
|
@@ -412,26 +872,54 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
412
872
|
await generate(fs, entities);
|
|
413
873
|
// Then the input has both types of fields as appropriate
|
|
414
874
|
expect(await fs.load("smallPublisher.graphql")).toMatchInlineSnapshot(`
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
875
|
+
"extend type Query {
|
|
876
|
+
smallPublisher(id: ID!): SmallPublisher!
|
|
877
|
+
smallPublishers(
|
|
878
|
+
filter: SmallPublisherFilter
|
|
879
|
+
first: Int
|
|
880
|
+
after: String
|
|
881
|
+
last: Int
|
|
882
|
+
before: String
|
|
883
|
+
): SmallPublishersConnection!
|
|
884
|
+
}
|
|
418
885
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
city: String!
|
|
423
|
-
}
|
|
886
|
+
extend type Mutation {
|
|
887
|
+
saveSmallPublisher(input: SaveSmallPublisherInput!): SaveSmallPublisherResult!
|
|
888
|
+
}
|
|
424
889
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
890
|
+
type SmallPublishersConnection {
|
|
891
|
+
edges: [SmallPublishersEdge!]!
|
|
892
|
+
nodes: [SmallPublisher!]!
|
|
893
|
+
pageInfo: PageInfo!
|
|
894
|
+
}
|
|
430
895
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
896
|
+
type SmallPublishersEdge {
|
|
897
|
+
node: SmallPublisher!
|
|
898
|
+
cursor: String!
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
type SmallPublisher {
|
|
902
|
+
id: ID!
|
|
903
|
+
name: String!
|
|
904
|
+
city: String!
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
input SmallPublisherFilter {
|
|
908
|
+
id: [ID!]
|
|
909
|
+
name: [String!]
|
|
910
|
+
city: [String!]
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
input SaveSmallPublisherInput {
|
|
914
|
+
id: ID
|
|
915
|
+
name: String
|
|
916
|
+
city: String
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
type SaveSmallPublisherResult {
|
|
920
|
+
smallPublisher: SmallPublisher!
|
|
921
|
+
}
|
|
922
|
+
"
|
|
435
923
|
`);
|
|
436
924
|
});
|
|
437
925
|
it("assumes a Like interface for subclassed & concrete base types", async () => {
|
|
@@ -453,15 +941,36 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
453
941
|
await generate(fs, entities);
|
|
454
942
|
// Then the input has both types of fields as appropriate
|
|
455
943
|
expect(await fs.load("author.graphql")).toMatchInlineSnapshot(`
|
|
456
|
-
"extend type
|
|
944
|
+
"extend type Query {
|
|
945
|
+
author(id: ID!): Author!
|
|
946
|
+
authors(filter: AuthorFilter, first: Int, after: String, last: Int, before: String): AuthorsConnection!
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
extend type Mutation {
|
|
457
950
|
saveAuthor(input: SaveAuthorInput!): SaveAuthorResult!
|
|
458
951
|
}
|
|
459
952
|
|
|
953
|
+
type AuthorsConnection {
|
|
954
|
+
edges: [AuthorsEdge!]!
|
|
955
|
+
nodes: [Author!]!
|
|
956
|
+
pageInfo: PageInfo!
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
type AuthorsEdge {
|
|
960
|
+
node: Author!
|
|
961
|
+
cursor: String!
|
|
962
|
+
}
|
|
963
|
+
|
|
460
964
|
type Author {
|
|
461
965
|
id: ID!
|
|
462
966
|
publisher: PublisherLike!
|
|
463
967
|
}
|
|
464
968
|
|
|
969
|
+
input AuthorFilter {
|
|
970
|
+
id: [ID!]
|
|
971
|
+
publisherId: [ID!]
|
|
972
|
+
}
|
|
973
|
+
|
|
465
974
|
input SaveAuthorInput {
|
|
466
975
|
id: ID
|
|
467
976
|
publisherId: ID
|
|
@@ -474,7 +983,7 @@ describe("generateGraphqlSchemaFiles", () => {
|
|
|
474
983
|
`);
|
|
475
984
|
});
|
|
476
985
|
});
|
|
477
|
-
async function generate(fs, opt) {
|
|
986
|
+
async function generate(fs, opt, config = {}) {
|
|
478
987
|
const entities = Array.isArray(opt) ? opt : (opt.entities ?? []);
|
|
479
988
|
const entitiesByName = (0, joist_utils_1.keyBy)(entities, "name");
|
|
480
989
|
// Hook up baseType/subTypes
|
|
@@ -494,6 +1003,6 @@ async function generate(fs, opt) {
|
|
|
494
1003
|
totalTables: 10,
|
|
495
1004
|
entitiesByName,
|
|
496
1005
|
};
|
|
497
|
-
return (0, generateGraphqlSchemaFiles_1.generateGraphqlSchemaFiles)(fs, dbMeta);
|
|
1006
|
+
return (0, generateGraphqlSchemaFiles_1.generateGraphqlSchemaFiles)(config, fs, dbMeta);
|
|
498
1007
|
}
|
|
499
1008
|
//# sourceMappingURL=generateGraphqlSchemaFiles.test.js.map
|