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
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import * as graphql from 'graphql'
|
|
2
|
-
|
|
3
|
-
import { Config, HoudiniError, parentTypeFromAncestors } from '../../../lib'
|
|
4
|
-
import { MutationOperation } from '../../../runtime/lib/types'
|
|
5
|
-
import { convertValue } from './utils'
|
|
6
|
-
|
|
7
|
-
// return the list of operations that are part of a mutation
|
|
8
|
-
export function operationsByPath(
|
|
9
|
-
config: Config,
|
|
10
|
-
filepath: string,
|
|
11
|
-
definition: graphql.OperationDefinitionNode,
|
|
12
|
-
filterTypes: FilterMap
|
|
13
|
-
): { [path: string]: MutationOperation[] } {
|
|
14
|
-
if (!definition) {
|
|
15
|
-
return {}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// map the path in the response to the list of operations that treat it as the source
|
|
19
|
-
const pathOperations: { [path: string]: MutationOperation[] } = {}
|
|
20
|
-
|
|
21
|
-
// we need to look for three different things in the operation:
|
|
22
|
-
// - insert fragments
|
|
23
|
-
// - remove fragments
|
|
24
|
-
// - delete directives
|
|
25
|
-
//
|
|
26
|
-
// note: for now, we're going to ignore the possibility that fragments
|
|
27
|
-
// inside of the mutation could contain operations
|
|
28
|
-
graphql.visit(definition, {
|
|
29
|
-
FragmentSpread(node, _, __, ___, ancestors) {
|
|
30
|
-
// if the fragment is not a list operation, we don't care about it now
|
|
31
|
-
if (!config.isListFragment(node.name.value)) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// if this is the first time we've seen this path give us a home
|
|
36
|
-
const path = ancestorKey(ancestors)
|
|
37
|
-
if (!pathOperations[path]) {
|
|
38
|
-
pathOperations[path] = []
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// add the operation object to the list
|
|
42
|
-
pathOperations[path].push(
|
|
43
|
-
operationObject({
|
|
44
|
-
config,
|
|
45
|
-
filepath,
|
|
46
|
-
listName: config.listNameFromFragment(node.name.value),
|
|
47
|
-
operationKind: config.listOperationFromFragment(node.name.value),
|
|
48
|
-
type: parentTypeFromAncestors(config.schema, filepath, ancestors).name,
|
|
49
|
-
selection: node,
|
|
50
|
-
})
|
|
51
|
-
)
|
|
52
|
-
},
|
|
53
|
-
Directive(node, _, __, ___, ancestors) {
|
|
54
|
-
// we only care about delete directives
|
|
55
|
-
if (!config.isDeleteDirective(node.name.value)) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// if this is the first time we've seen this path give us a home
|
|
60
|
-
const path = ancestorKey(ancestors)
|
|
61
|
-
if (!pathOperations[path]) {
|
|
62
|
-
pathOperations[path] = []
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// add the operation object to the list
|
|
66
|
-
pathOperations[path].push(
|
|
67
|
-
operationObject({
|
|
68
|
-
config,
|
|
69
|
-
filepath,
|
|
70
|
-
listName: node.name.value,
|
|
71
|
-
operationKind: 'delete',
|
|
72
|
-
type: config.listNameFromDirective(node.name.value),
|
|
73
|
-
selection: ancestors[ancestors.length - 1] as graphql.FieldNode,
|
|
74
|
-
})
|
|
75
|
-
)
|
|
76
|
-
},
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
return pathOperations
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function operationObject({
|
|
83
|
-
config,
|
|
84
|
-
listName,
|
|
85
|
-
operationKind,
|
|
86
|
-
type,
|
|
87
|
-
selection,
|
|
88
|
-
filepath,
|
|
89
|
-
}: {
|
|
90
|
-
config: Config
|
|
91
|
-
filepath: string
|
|
92
|
-
listName: string
|
|
93
|
-
operationKind: MutationOperation['action']
|
|
94
|
-
type: string
|
|
95
|
-
selection: graphql.SelectionNode
|
|
96
|
-
}): MutationOperation {
|
|
97
|
-
// look at the directives applies to the spread for meta data about the mutation
|
|
98
|
-
let parentID
|
|
99
|
-
let parentKind: 'Variable' | 'String' = 'String'
|
|
100
|
-
|
|
101
|
-
let position: MutationOperation['position'] = 'last'
|
|
102
|
-
let operationWhen: MutationOperation['when'] | undefined
|
|
103
|
-
|
|
104
|
-
const internalDirectives = selection.directives?.filter((directive) =>
|
|
105
|
-
config.isInternalDirective(directive)
|
|
106
|
-
)
|
|
107
|
-
if (internalDirectives && internalDirectives.length > 0) {
|
|
108
|
-
// is prepend applied?
|
|
109
|
-
const prepend = internalDirectives.find(
|
|
110
|
-
({ name }) => name.value === config.listPrependDirective
|
|
111
|
-
)
|
|
112
|
-
// is append applied?
|
|
113
|
-
const append = internalDirectives.find(
|
|
114
|
-
({ name }) => name.value === config.listAppendDirective
|
|
115
|
-
)
|
|
116
|
-
// is when applied?
|
|
117
|
-
const when = internalDirectives.find(({ name }) => name.value === 'when')
|
|
118
|
-
// is when_not applied?
|
|
119
|
-
const when_not = internalDirectives.find(({ name }) => name.value === 'when_not')
|
|
120
|
-
// look for the parentID directive
|
|
121
|
-
let parent = internalDirectives.find(
|
|
122
|
-
({ name }) => name.value === config.listParentDirective
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
// if both are applied, there's a problem
|
|
126
|
-
if (append && prepend) {
|
|
127
|
-
throw new HoudiniError({ filepath, message: 'you have both applied' })
|
|
128
|
-
}
|
|
129
|
-
position = prepend ? 'first' : 'last'
|
|
130
|
-
|
|
131
|
-
// the parent ID can be provided a few ways, either as an argument to the prepend
|
|
132
|
-
// and append directives or with the parentID directive.
|
|
133
|
-
|
|
134
|
-
let parentIDArg = parent?.arguments?.find((argument) => argument.name.value === 'value')
|
|
135
|
-
// if there is no parent id argument, it could have been provided by one of the list directives
|
|
136
|
-
if (!parentIDArg) {
|
|
137
|
-
parentIDArg = (append || prepend)?.arguments?.find(
|
|
138
|
-
({ name }) => name.value === config.listDirectiveParentIDArg
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (parentIDArg) {
|
|
143
|
-
// if the argument is a string
|
|
144
|
-
if (parentIDArg.value.kind === 'StringValue') {
|
|
145
|
-
// use its value
|
|
146
|
-
parentID = parentIDArg.value.value
|
|
147
|
-
parentKind = 'String'
|
|
148
|
-
} else if (parentIDArg.value.kind === 'Variable') {
|
|
149
|
-
parentKind = 'Variable'
|
|
150
|
-
parentID = parentIDArg.value.name.value
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// look for a when arguments on the operation directives
|
|
155
|
-
const whenArg = (append || prepend)?.arguments?.find(({ name }) => name.value === 'when')
|
|
156
|
-
// look for a when_not condition on the operation
|
|
157
|
-
const whenNotArg = (append || prepend)?.arguments?.find(
|
|
158
|
-
({ name }) => name.value === 'when_not'
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
for (const [i, arg] of [whenArg, whenNotArg].entries()) {
|
|
162
|
-
// we may not have the argument
|
|
163
|
-
if (!arg || arg.value.kind !== 'ObjectValue') {
|
|
164
|
-
continue
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// make sure we have a place to record the when condition
|
|
168
|
-
if (!operationWhen) {
|
|
169
|
-
operationWhen = {}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// the kind of `value` is always going to be a string because the directive
|
|
173
|
-
// can only take one type as its argument so we'll worry about parsing when
|
|
174
|
-
// generating the artifact
|
|
175
|
-
operationWhen[i ? 'must_not' : 'must'] = arg.value.fields.reduce(
|
|
176
|
-
(obj, arg) => ({
|
|
177
|
-
...obj,
|
|
178
|
-
[arg.name.value]: convertValue(arg.value).value,
|
|
179
|
-
}),
|
|
180
|
-
{}
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// look at the when and when_not directives
|
|
185
|
-
for (const [i, directive] of [when, when_not].entries()) {
|
|
186
|
-
// we may not have the directive applied
|
|
187
|
-
if (!directive) {
|
|
188
|
-
continue
|
|
189
|
-
}
|
|
190
|
-
// which are we looking at
|
|
191
|
-
const which = i ? 'must_not' : 'must'
|
|
192
|
-
|
|
193
|
-
// make sure we have a place to record the when condition
|
|
194
|
-
if (!operationWhen) {
|
|
195
|
-
operationWhen = {}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// look for the argument field
|
|
199
|
-
operationWhen[which] = directive.arguments?.reduce(
|
|
200
|
-
(filters, argument) => ({
|
|
201
|
-
...filters,
|
|
202
|
-
[argument.name.value]: convertValue(argument.value).value,
|
|
203
|
-
}),
|
|
204
|
-
{}
|
|
205
|
-
)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const operation: MutationOperation = {
|
|
210
|
-
action: operationKind,
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// delete doesn't have a target
|
|
214
|
-
if (operationKind !== 'delete') {
|
|
215
|
-
operation.list = listName
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// add the target type to delete operations
|
|
219
|
-
if (operationKind === 'delete' && type) {
|
|
220
|
-
operation.type = type
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// only add the position argument if we are inserting something
|
|
224
|
-
if (operationKind === 'insert' || operationKind === 'toggle') {
|
|
225
|
-
operation.position = position || 'last'
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// if there is a parent id
|
|
229
|
-
if (parentID) {
|
|
230
|
-
// add it to the object
|
|
231
|
-
operation.parentID = {
|
|
232
|
-
kind: parentKind,
|
|
233
|
-
value: parentID,
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// if there is a conditional
|
|
238
|
-
if (operationWhen) {
|
|
239
|
-
operation.when = operationWhen
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return operation
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// TODO: find a way to reference the actual type for ancestors, using any as escape hatch
|
|
246
|
-
function ancestorKey(ancestors: any): string {
|
|
247
|
-
return (
|
|
248
|
-
ancestors
|
|
249
|
-
.filter(
|
|
250
|
-
// @ts-ignore
|
|
251
|
-
(entry) => !Array.isArray(entry) && entry.kind === 'Field'
|
|
252
|
-
)
|
|
253
|
-
// @ts-ignore
|
|
254
|
-
.map((field) => field.name.value)
|
|
255
|
-
.join(',')
|
|
256
|
-
)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export type FilterMap = {
|
|
260
|
-
[listName: string]: {
|
|
261
|
-
[filterName: string]: 'String' | 'Float' | 'Int' | 'Boolean'
|
|
262
|
-
}
|
|
263
|
-
}
|