houdini 0.17.8 → 0.17.10
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/README.md +33 -0
- package/build/cmd-cjs/index.js +124 -38
- package/build/cmd-esm/index.js +124 -38
- package/build/codegen-cjs/index.js +112 -36
- package/build/codegen-esm/index.js +112 -36
- package/build/lib/config.d.ts +3 -0
- package/build/lib-cjs/index.js +31 -12
- package/build/lib-esm/index.js +31 -12
- package/build/runtime/cache/cache.d.ts +1 -1
- package/build/runtime/cache/lists.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +10 -2
- package/build/runtime/lib/types.d.ts +1 -0
- package/build/runtime-cjs/cache/cache.d.ts +1 -1
- package/build/runtime-cjs/cache/cache.js +6 -6
- package/build/runtime-cjs/cache/lists.d.ts +1 -1
- package/build/runtime-cjs/cache/lists.js +15 -6
- package/build/runtime-cjs/cache/tests/list.test.js +160 -70
- package/build/runtime-cjs/lib/config.d.ts +10 -2
- package/build/runtime-cjs/lib/types.d.ts +1 -0
- package/build/runtime-esm/cache/cache.d.ts +1 -1
- package/build/runtime-esm/cache/cache.js +6 -6
- package/build/runtime-esm/cache/lists.d.ts +1 -1
- package/build/runtime-esm/cache/lists.js +15 -6
- package/build/runtime-esm/cache/tests/list.test.js +160 -70
- package/build/runtime-esm/lib/config.d.ts +10 -2
- package/build/runtime-esm/lib/types.d.ts +1 -0
- package/build/test-cjs/index.js +122 -36
- package/build/test-esm/index.js +122 -36
- package/build/vite-cjs/index.js +122 -36
- package/build/vite-esm/index.js +122 -36
- package/package.json +16 -1
- package/.turbo/turbo-compile.log +0 -5
- package/.turbo/turbo-typedefs.log +0 -5
- package/CHANGELOG.md +0 -367
- package/src/cmd/generate.ts +0 -54
- package/src/cmd/index.ts +0 -60
- package/src/cmd/init.ts +0 -637
- package/src/cmd/pullSchema.ts +0 -40
- package/src/codegen/generators/artifacts/artifacts.test.ts +0 -2978
- package/src/codegen/generators/artifacts/fieldKey.ts +0 -60
- package/src/codegen/generators/artifacts/index.ts +0 -330
- package/src/codegen/generators/artifacts/indexFile.ts +0 -24
- package/src/codegen/generators/artifacts/inputs.ts +0 -81
- package/src/codegen/generators/artifacts/operations.ts +0 -263
- package/src/codegen/generators/artifacts/pagination.test.ts +0 -664
- package/src/codegen/generators/artifacts/policy.test.ts +0 -298
- package/src/codegen/generators/artifacts/selection.ts +0 -208
- package/src/codegen/generators/artifacts/utils.test.ts +0 -118
- package/src/codegen/generators/artifacts/utils.ts +0 -108
- package/src/codegen/generators/definitions/enums.test.ts +0 -61
- package/src/codegen/generators/definitions/enums.ts +0 -68
- package/src/codegen/generators/definitions/index.ts +0 -11
- package/src/codegen/generators/definitions/schema.test.ts +0 -227
- package/src/codegen/generators/index.ts +0 -6
- package/src/codegen/generators/indexFile/index.ts +0 -63
- package/src/codegen/generators/indexFile/indexFile.test.ts +0 -72
- package/src/codegen/generators/persistedQueries/index.ts +0 -55
- package/src/codegen/generators/persistedQueries/persistedQuery.test.ts +0 -26
- package/src/codegen/generators/runtime/index.test.ts +0 -74
- package/src/codegen/generators/runtime/index.ts +0 -64
- package/src/codegen/generators/runtime/runtime.test.ts +0 -25
- package/src/codegen/generators/typescript/addReferencedInputTypes.ts +0 -77
- package/src/codegen/generators/typescript/index.ts +0 -412
- package/src/codegen/generators/typescript/inlineType.ts +0 -409
- package/src/codegen/generators/typescript/typeReference.ts +0 -44
- package/src/codegen/generators/typescript/types.ts +0 -81
- package/src/codegen/generators/typescript/typescript.test.ts +0 -1434
- package/src/codegen/index.ts +0 -406
- package/src/codegen/transforms/addID.test.ts +0 -93
- package/src/codegen/transforms/addID.ts +0 -86
- package/src/codegen/transforms/composeQueries.test.ts +0 -50
- package/src/codegen/transforms/composeQueries.ts +0 -154
- package/src/codegen/transforms/fragmentVariables.test.ts +0 -636
- package/src/codegen/transforms/fragmentVariables.ts +0 -417
- package/src/codegen/transforms/index.ts +0 -7
- package/src/codegen/transforms/list.ts +0 -485
- package/src/codegen/transforms/lists.test.ts +0 -530
- package/src/codegen/transforms/paginate.test.ts +0 -1481
- package/src/codegen/transforms/paginate.ts +0 -750
- package/src/codegen/transforms/schema.test.ts +0 -136
- package/src/codegen/transforms/schema.ts +0 -104
- package/src/codegen/transforms/typename.test.ts +0 -125
- package/src/codegen/transforms/typename.ts +0 -55
- package/src/codegen/utils/commonjs.ts +0 -26
- package/src/codegen/utils/flattenSelections.ts +0 -179
- package/src/codegen/utils/graphql.test.ts +0 -35
- package/src/codegen/utils/graphql.ts +0 -79
- package/src/codegen/utils/index.ts +0 -5
- package/src/codegen/utils/moduleExport.ts +0 -27
- package/src/codegen/utils/murmur.ts +0 -79
- package/src/codegen/validators/index.ts +0 -4
- package/src/codegen/validators/noIDAlias.test.ts +0 -71
- package/src/codegen/validators/noIDAlias.ts +0 -39
- package/src/codegen/validators/plugins.ts +0 -25
- package/src/codegen/validators/typeCheck.test.ts +0 -904
- package/src/codegen/validators/typeCheck.ts +0 -1031
- package/src/codegen/validators/uniqueNames.test.ts +0 -59
- package/src/codegen/validators/uniqueNames.ts +0 -39
- package/src/lib/cleanupFiles.ts +0 -20
- package/src/lib/config.test.ts +0 -13
- package/src/lib/config.ts +0 -943
- package/src/lib/constants.ts +0 -11
- package/src/lib/error.ts +0 -24
- package/src/lib/fs.ts +0 -285
- package/src/lib/graphql.test.ts +0 -211
- package/src/lib/graphql.ts +0 -200
- package/src/lib/imports.ts +0 -82
- package/src/lib/index.ts +0 -17
- package/src/lib/introspection.ts +0 -39
- package/src/lib/parse.test.ts +0 -75
- package/src/lib/parse.ts +0 -23
- package/src/lib/path.ts +0 -49
- package/src/lib/pipeline.ts +0 -17
- package/src/lib/types.ts +0 -34
- package/src/lib/walk.ts +0 -104
- package/src/runtime/cache/cache.ts +0 -1023
- package/src/runtime/cache/gc.ts +0 -56
- package/src/runtime/cache/index.ts +0 -3
- package/src/runtime/cache/lists.ts +0 -502
- package/src/runtime/cache/storage.ts +0 -574
- package/src/runtime/cache/stuff.ts +0 -77
- package/src/runtime/cache/subscription.ts +0 -329
- package/src/runtime/cache/tests/availability.test.ts +0 -408
- package/src/runtime/cache/tests/gc.test.ts +0 -319
- package/src/runtime/cache/tests/keys.test.ts +0 -36
- package/src/runtime/cache/tests/list.test.ts +0 -3747
- package/src/runtime/cache/tests/readwrite.test.ts +0 -1201
- package/src/runtime/cache/tests/scalars.test.ts +0 -218
- package/src/runtime/cache/tests/storage.test.ts +0 -426
- package/src/runtime/cache/tests/subscriptions.test.ts +0 -1757
- package/src/runtime/index.ts +0 -29
- package/src/runtime/lib/config.ts +0 -201
- package/src/runtime/lib/constants.ts +0 -17
- package/src/runtime/lib/deepEquals.ts +0 -32
- package/src/runtime/lib/errors.ts +0 -8
- package/src/runtime/lib/index.ts +0 -8
- package/src/runtime/lib/log.ts +0 -69
- package/src/runtime/lib/network.ts +0 -303
- package/src/runtime/lib/networkUtils.ts +0 -151
- package/src/runtime/lib/scalars.test.ts +0 -877
- package/src/runtime/lib/scalars.ts +0 -195
- package/src/runtime/lib/types.ts +0 -194
- package/src/test/index.ts +0 -294
- package/src/vite/ast.ts +0 -107
- package/src/vite/houdini.ts +0 -113
- package/src/vite/imports.ts +0 -129
- package/src/vite/index.ts +0 -55
- package/src/vite/schema.ts +0 -80
package/src/lib/constants.ts
DELETED
package/src/lib/error.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// any error that the compiler could fire
|
|
2
|
-
export class HoudiniError extends Error {
|
|
3
|
-
filepath: string | null = null
|
|
4
|
-
description: string | null = null
|
|
5
|
-
|
|
6
|
-
constructor({
|
|
7
|
-
filepath,
|
|
8
|
-
message,
|
|
9
|
-
description,
|
|
10
|
-
}: {
|
|
11
|
-
filepath?: string | null
|
|
12
|
-
message: string
|
|
13
|
-
description?: string | null
|
|
14
|
-
}) {
|
|
15
|
-
super(message)
|
|
16
|
-
|
|
17
|
-
if (filepath) {
|
|
18
|
-
this.filepath = filepath
|
|
19
|
-
}
|
|
20
|
-
if (description) {
|
|
21
|
-
this.description = description
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/lib/fs.ts
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import fsExtra from 'fs-extra'
|
|
2
|
-
import fs from 'fs/promises'
|
|
3
|
-
import { glob as G } from 'glob'
|
|
4
|
-
import { fs as memfs, vol } from 'memfs'
|
|
5
|
-
import { promisify } from 'util'
|
|
6
|
-
|
|
7
|
-
import { houdini_mode } from './constants'
|
|
8
|
-
import * as path from './path'
|
|
9
|
-
|
|
10
|
-
export function copyFileSync(src: string, dest: string): void | null {
|
|
11
|
-
if (houdini_mode.is_testing) {
|
|
12
|
-
try {
|
|
13
|
-
if (src.includes('build/runtime') || dest.includes('build/runtime')) {
|
|
14
|
-
fsExtra.copyFileSync(src, dest)
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
memfs.copyFileSync(src, dest)
|
|
19
|
-
return
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
fsExtra.copyFileSync(src, dest)
|
|
26
|
-
return
|
|
27
|
-
} catch (e) {}
|
|
28
|
-
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function copyFile(src: string, dest: string): Promise<void | null> {
|
|
33
|
-
if (houdini_mode.is_testing) {
|
|
34
|
-
try {
|
|
35
|
-
if (src.includes('build/runtime') || dest.includes('build/runtime')) {
|
|
36
|
-
await fs.copyFile(src, dest)
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await memfs.copyFile(src, dest, (err) => {
|
|
41
|
-
throw err
|
|
42
|
-
})
|
|
43
|
-
return
|
|
44
|
-
} catch (e) {
|
|
45
|
-
return null
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
try {
|
|
49
|
-
await fs.copyFile(src, dest)
|
|
50
|
-
return
|
|
51
|
-
} catch (e) {}
|
|
52
|
-
|
|
53
|
-
return null
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function readFile(filepath: string): Promise<string | null> {
|
|
57
|
-
if (houdini_mode.is_testing) {
|
|
58
|
-
try {
|
|
59
|
-
if (filepath.includes('build/runtime')) {
|
|
60
|
-
return await fs.readFile(filepath, 'utf-8')
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return memfs.readFileSync(filepath, 'utf-8')!.toString()
|
|
64
|
-
} catch (e) {
|
|
65
|
-
return null
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
return await fs.readFile(filepath, 'utf8')
|
|
71
|
-
} catch (error) {}
|
|
72
|
-
|
|
73
|
-
return null
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function readFileSync(filepath: string): string | null {
|
|
77
|
-
if (houdini_mode.is_testing) {
|
|
78
|
-
try {
|
|
79
|
-
if (filepath.includes('build/runtime')) {
|
|
80
|
-
return fsExtra.readFileSync(filepath, 'utf-8')
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return memfs.readFileSync(filepath, 'utf-8')!.toString()
|
|
84
|
-
} catch (e) {
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
return fsExtra.readFileSync(filepath, 'utf-8')
|
|
91
|
-
} catch (error) {}
|
|
92
|
-
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function writeFile(filepath: string, data: string) {
|
|
97
|
-
const existingFileData = await readFile(filepath)
|
|
98
|
-
if (data === existingFileData) {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// no mock in tests
|
|
103
|
-
if (houdini_mode.is_testing) {
|
|
104
|
-
return memfs.writeFileSync(filepath, data)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return await fs.writeFile(filepath, data, 'utf8')
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function access(filepath: string) {
|
|
111
|
-
// no mock in production
|
|
112
|
-
if (!houdini_mode.is_testing) {
|
|
113
|
-
return await fs.access(filepath)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (filepath.includes('build/runtime')) {
|
|
117
|
-
return await fs.access(filepath)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// split up the path in accessors and keep going until we get undefined
|
|
121
|
-
// or we get a value
|
|
122
|
-
return memfs.statSync(filepath)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function mkdirp(filepath: string) {
|
|
126
|
-
// no mock in production
|
|
127
|
-
if (!houdini_mode.is_testing) {
|
|
128
|
-
return await fsExtra.mkdirp(filepath)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return memfs.mkdirpSync(filepath)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export async function mkdirpSync(filepath: string) {
|
|
135
|
-
// no mock in production
|
|
136
|
-
if (!houdini_mode.is_testing) {
|
|
137
|
-
return fsExtra.mkdirpSync(filepath)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return memfs.mkdirpSync(filepath)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function mkdir(filepath: string) {
|
|
144
|
-
// no mock in production
|
|
145
|
-
if (!houdini_mode.is_testing) {
|
|
146
|
-
return await fs.mkdir(filepath)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return memfs.mkdirSync(filepath)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export async function rmdir(filepath: string) {
|
|
153
|
-
// no mock in production
|
|
154
|
-
if (!houdini_mode.is_testing) {
|
|
155
|
-
return await fs.rm(filepath, {
|
|
156
|
-
recursive: true,
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return await promisify(memfs.rmdir)(filepath)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function stat(filepath: string) {
|
|
164
|
-
// no mock in production
|
|
165
|
-
if (!houdini_mode.is_testing) {
|
|
166
|
-
return await fs.stat(filepath)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// if the filepath points to a built package, use the real filesystem
|
|
170
|
-
if (filepath.includes('build/runtime')) {
|
|
171
|
-
return await fs.stat(filepath)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return memfs.statSync(filepath)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function existsSync(dirPath: string) {
|
|
178
|
-
// no mock in production
|
|
179
|
-
if (!houdini_mode.is_testing) {
|
|
180
|
-
return fsExtra.existsSync(dirPath)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return memfs.existsSync(dirPath)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export async function readdir(filepath: string): Promise<string[]> {
|
|
187
|
-
// no mock in production
|
|
188
|
-
if (!houdini_mode.is_testing) {
|
|
189
|
-
return await fs.readdir(filepath)
|
|
190
|
-
}
|
|
191
|
-
if (filepath.includes('build/runtime')) {
|
|
192
|
-
return await fs.readdir(filepath)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
return memfs.readdirSync(filepath) as string[]
|
|
197
|
-
} catch {
|
|
198
|
-
return []
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export async function remove(filepath: string) {
|
|
203
|
-
// no mock in production
|
|
204
|
-
if (!houdini_mode.is_testing) {
|
|
205
|
-
return await fs.rm(filepath)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return vol.rmSync(filepath)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
type MockFilesystem = { [key: string]: string | MockFilesystem }
|
|
212
|
-
|
|
213
|
-
export async function mock(target: MockFilesystem[string], filepath: string = '') {
|
|
214
|
-
// assuming mock is always called with an object, process every key
|
|
215
|
-
await Promise.all(
|
|
216
|
-
Object.entries(target).map(async ([key, value]) => {
|
|
217
|
-
const childPath = path.join(filepath, key)
|
|
218
|
-
// if our value is a string, we need to write the contents
|
|
219
|
-
if (typeof value === 'string') {
|
|
220
|
-
await writeFile(childPath, value)
|
|
221
|
-
} else {
|
|
222
|
-
// the key is the new directory name
|
|
223
|
-
await mkdirp(childPath)
|
|
224
|
-
return await mock(value, childPath)
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export async function recursiveCopy(
|
|
231
|
-
source: string,
|
|
232
|
-
target: string,
|
|
233
|
-
transforms?: Record<string, (content: string) => string>,
|
|
234
|
-
notRoot?: boolean
|
|
235
|
-
) {
|
|
236
|
-
// if the folder containing the target doesn't exist, then we need to create it
|
|
237
|
-
let parentDir = path.join(target, path.basename(source))
|
|
238
|
-
// if we are at the root, then go up one
|
|
239
|
-
if (!notRoot) {
|
|
240
|
-
parentDir = path.join(parentDir, '..')
|
|
241
|
-
}
|
|
242
|
-
try {
|
|
243
|
-
await access(parentDir)
|
|
244
|
-
// the parent directory does not exist
|
|
245
|
-
} catch (e) {
|
|
246
|
-
await mkdirp(parentDir)
|
|
247
|
-
}
|
|
248
|
-
// check if we are copying a directory
|
|
249
|
-
if ((await stat(source)).isDirectory()) {
|
|
250
|
-
// look in the contents of the source directory
|
|
251
|
-
await Promise.all(
|
|
252
|
-
(
|
|
253
|
-
await readdir(source)
|
|
254
|
-
).map(async (child) => {
|
|
255
|
-
// figure out the full path of the source
|
|
256
|
-
const childPath = path.join(source, child)
|
|
257
|
-
|
|
258
|
-
// if the child is a directory
|
|
259
|
-
if ((await stat(childPath)).isDirectory()) {
|
|
260
|
-
// keep walking down
|
|
261
|
-
await recursiveCopy(childPath, parentDir, transforms, true)
|
|
262
|
-
}
|
|
263
|
-
// the child is a file, copy it to the parent directory
|
|
264
|
-
else {
|
|
265
|
-
const targetPath = path.join(parentDir, child)
|
|
266
|
-
|
|
267
|
-
// we might have to transform the value before copying it
|
|
268
|
-
let original = (await readFile(childPath)) || ''
|
|
269
|
-
if (transforms?.[childPath]) {
|
|
270
|
-
original = transforms[childPath](original)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
await writeFile(targetPath, original)
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
)
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// wrap glob in a promise and enforce that the paths are always posix-style
|
|
281
|
-
export async function glob(pattern: string) {
|
|
282
|
-
return await promisify(G)(path.posixify(pattern))
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
glob.hasMagic = G.hasMagic
|
package/src/lib/graphql.test.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import * as graphql from 'graphql'
|
|
2
|
-
import { test, expect } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { parentTypeFromAncestors } from './graphql'
|
|
5
|
-
|
|
6
|
-
test('can find ancestor from type', function () {
|
|
7
|
-
// define a schema we'll test against
|
|
8
|
-
const schema = graphql.buildSchema(`
|
|
9
|
-
type User {
|
|
10
|
-
id: ID!
|
|
11
|
-
name: String!
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type Query {
|
|
15
|
-
users: [User!]!
|
|
16
|
-
}
|
|
17
|
-
`)
|
|
18
|
-
|
|
19
|
-
const doc = graphql.parse(`
|
|
20
|
-
query {
|
|
21
|
-
users {
|
|
22
|
-
id
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
`)
|
|
26
|
-
|
|
27
|
-
// we should
|
|
28
|
-
let foundType = ''
|
|
29
|
-
|
|
30
|
-
graphql.visit(doc, {
|
|
31
|
-
Field(node, key, parent, path, ancestors) {
|
|
32
|
-
if (node.name.value === 'id') {
|
|
33
|
-
foundType = parentTypeFromAncestors(schema, '', ancestors).name
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
expect(foundType).toEqual('User')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('inline fragments', function () {
|
|
42
|
-
// define a schema we'll test against
|
|
43
|
-
const schema = graphql.buildSchema(`
|
|
44
|
-
type User implements Node {
|
|
45
|
-
id: ID!
|
|
46
|
-
name: String!
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface Node {
|
|
50
|
-
id: ID!
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type Query {
|
|
54
|
-
nodes: [Node!]!
|
|
55
|
-
}
|
|
56
|
-
`)
|
|
57
|
-
|
|
58
|
-
const doc = graphql.parse(`
|
|
59
|
-
query {
|
|
60
|
-
nodes {
|
|
61
|
-
... on User {
|
|
62
|
-
id
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
`)
|
|
67
|
-
|
|
68
|
-
// we should
|
|
69
|
-
let foundType = ''
|
|
70
|
-
|
|
71
|
-
graphql.visit(doc, {
|
|
72
|
-
Field(node, key, parent, path, ancestors) {
|
|
73
|
-
if (node.name.value === 'id') {
|
|
74
|
-
foundType = parentTypeFromAncestors(schema, '', ancestors).name
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
expect(foundType).toEqual('User')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('nested inline fragments', function () {
|
|
83
|
-
// define a schema we'll test against
|
|
84
|
-
const schema = graphql.buildSchema(`
|
|
85
|
-
type User implements Node {
|
|
86
|
-
id: ID!
|
|
87
|
-
name: String!
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface Node {
|
|
91
|
-
id: ID!
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
type Query {
|
|
95
|
-
nodes: [Node!]!
|
|
96
|
-
}
|
|
97
|
-
`)
|
|
98
|
-
|
|
99
|
-
const doc = graphql.parse(`
|
|
100
|
-
query {
|
|
101
|
-
nodes {
|
|
102
|
-
... on User {
|
|
103
|
-
... on Node {
|
|
104
|
-
id
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
`)
|
|
110
|
-
|
|
111
|
-
// we should
|
|
112
|
-
let foundType = ''
|
|
113
|
-
|
|
114
|
-
graphql.visit(doc, {
|
|
115
|
-
Field(node, key, parent, path, ancestors) {
|
|
116
|
-
if (node.name.value === 'id') {
|
|
117
|
-
foundType = parentTypeFromAncestors(schema, '', ancestors).name
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
expect(foundType).toEqual('Node')
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
test('can find interface ancestor from type', function () {
|
|
126
|
-
// define a schema we'll test against
|
|
127
|
-
const schema = graphql.buildSchema(`
|
|
128
|
-
type User implements Node {
|
|
129
|
-
id: ID!
|
|
130
|
-
name: String!
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
interface Node {
|
|
134
|
-
id: ID!
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
type Query {
|
|
138
|
-
nodes: [Node!]!
|
|
139
|
-
}
|
|
140
|
-
`)
|
|
141
|
-
|
|
142
|
-
const doc = graphql.parse(`
|
|
143
|
-
query {
|
|
144
|
-
nodes {
|
|
145
|
-
id
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
`)
|
|
149
|
-
|
|
150
|
-
// we should
|
|
151
|
-
let foundType = ''
|
|
152
|
-
|
|
153
|
-
graphql.visit(doc, {
|
|
154
|
-
Field(node, key, parent, path, ancestors) {
|
|
155
|
-
if (node.name.value === 'id') {
|
|
156
|
-
foundType = parentTypeFromAncestors(schema, '', ancestors).name
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
expect(foundType).toEqual('Node')
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
test('union ancestor', function () {
|
|
165
|
-
const schema = graphql.buildSchema(`
|
|
166
|
-
union UnionType = TypeB | TypeA
|
|
167
|
-
|
|
168
|
-
type TypeA {
|
|
169
|
-
id: String
|
|
170
|
-
objective: TypeB
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
type TypeB {
|
|
174
|
-
family: TypeA
|
|
175
|
-
objective: TypeB
|
|
176
|
-
id: String
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
type Query {
|
|
181
|
-
types: [UnionType]
|
|
182
|
-
}
|
|
183
|
-
`)
|
|
184
|
-
|
|
185
|
-
const doc = graphql.parse(`
|
|
186
|
-
query Friends {
|
|
187
|
-
types {
|
|
188
|
-
... on TypeA {
|
|
189
|
-
objective {
|
|
190
|
-
id
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
`)
|
|
196
|
-
|
|
197
|
-
let foundType = ''
|
|
198
|
-
|
|
199
|
-
// make sure its valid first
|
|
200
|
-
expect(graphql.validate(schema, doc)).toHaveLength(0)
|
|
201
|
-
|
|
202
|
-
graphql.visit(doc, {
|
|
203
|
-
Field(node, key, parent, path, ancestors) {
|
|
204
|
-
if (node.name.value === 'id') {
|
|
205
|
-
foundType = parentTypeFromAncestors(schema, '', ancestors).name
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
expect(foundType).toEqual('TypeB')
|
|
211
|
-
})
|