goatly 0.1.0 → 0.1.2
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 +874 -1
- package/bin/goatly.js +99 -0
- package/dist/cli/index.js +234 -0
- package/dist/compat/gatsby-node-entry.js +16 -0
- package/dist/compat/gatsby-package.json +6 -0
- package/dist/compat/md5-file.js +47 -0
- package/dist/compat-apis.json +72 -0
- package/dist/compat-apis.json.js +62 -0
- package/dist/graphql.js +3 -0
- package/dist/node/actions/index.js +619 -0
- package/dist/node/actions/job-store.js +180 -0
- package/dist/node/actions/jobs.js +174 -0
- package/dist/node/api-runner.js +258 -0
- package/dist/node/bootstrap.js +569 -0
- package/dist/node/build/assets.js +110 -0
- package/dist/node/build/incremental.js +208 -0
- package/dist/node/build/index.js +763 -0
- package/dist/node/build/memory-governor.js +450 -0
- package/dist/node/build/output-dirs.js +70 -0
- package/dist/node/build/page-data.js +40 -0
- package/dist/node/build/page-files.js +186 -0
- package/dist/node/build/partitioned-state.js +258 -0
- package/dist/node/build/query-worker.js +626 -0
- package/dist/node/build/query-workers.js +863 -0
- package/dist/node/build/render-thread.js +103 -0
- package/dist/node/build/render-worker.js +162 -0
- package/dist/node/build/state.js +24 -0
- package/dist/node/build/timing-breakdown.js +216 -0
- package/dist/node/build/work-clock.js +75 -0
- package/dist/node/build/worker-pool.js +242 -0
- package/dist/node/cache-layout.js +99 -0
- package/dist/node/cache.js +1430 -0
- package/dist/node/compat/chokidar-shim.js +148 -0
- package/dist/node/compat/core-utils-lmdb.js +145 -0
- package/dist/node/compat/create-node-id-shim.js +1 -0
- package/dist/node/compat/module-hooks.js +245 -0
- package/dist/node/compat/redux-shim.js +1 -0
- package/dist/node/config/index.js +162 -0
- package/dist/node/config/not-found-pages.js +95 -0
- package/dist/node/datastore/codec.js +144 -0
- package/dist/node/datastore/index.js +127 -0
- package/dist/node/datastore/logfile/cache.js +89 -0
- package/dist/node/datastore/logfile/index.js +1329 -0
- package/dist/node/datastore/logfile/record.js +71 -0
- package/dist/node/datastore/types.js +1 -0
- package/dist/node/develop/express-compat.js +207 -0
- package/dist/node/develop/graphiql.js +22 -0
- package/dist/node/develop/hydration-report.js +41 -0
- package/dist/node/develop/index.js +618 -0
- package/dist/node/develop/local-url.js +10 -0
- package/dist/node/develop/ssr-runner.js +66 -0
- package/dist/node/gql.js +5 -0
- package/dist/node/index.js +15 -0
- package/dist/node/info.js +270 -0
- package/dist/node/internal-plugins/data-bridge.js +196 -0
- package/dist/node/internal-plugins/page-creator.js +318 -0
- package/dist/node/loader/import-module.js +160 -0
- package/dist/node/node-helpers.js +66 -0
- package/dist/node/not-found-pages.js +220 -0
- package/dist/node/plugins/api-list.js +12 -0
- package/dist/node/plugins/load-plugins.js +427 -0
- package/dist/node/plugins/resolve-plugin.js +79 -0
- package/dist/node/plugins/static-exports.js +64 -0
- package/dist/node/query/compile.js +326 -0
- package/dist/node/query/dependencies.js +45 -0
- package/dist/node/query/execute.js +417 -0
- package/dist/node/query/extract.js +372 -0
- package/dist/node/query/gql-tada-introspection.js +124 -0
- package/dist/node/query/graphql-env.js +231 -0
- package/dist/node/query/graphql-runner.js +79 -0
- package/dist/node/redux/actions.js +1 -0
- package/dist/node/redux/index.js +133 -0
- package/dist/node/redux/node-changes.js +128 -0
- package/dist/node/redux/reducers.js +193 -0
- package/dist/node/redux/state.js +71 -0
- package/dist/node/renderer.js +124 -0
- package/dist/node/reporter-transports.js +259 -0
- package/dist/node/reporter.js +497 -0
- package/dist/node/schema/date.js +539 -0
- package/dist/node/schema/extensions.js +315 -0
- package/dist/node/schema/index.js +542 -0
- package/dist/node/schema/infer.js +388 -0
- package/dist/node/schema/inline-objects.js +128 -0
- package/dist/node/schema/naming.js +20 -0
- package/dist/node/schema/node-model.js +207 -0
- package/dist/node/schema/query-engine.js +1808 -0
- package/dist/node/schema/resolver-kinds.js +7 -0
- package/dist/node/schema/resolvers.js +273 -0
- package/dist/node/schema/type-builders.js +45 -0
- package/dist/node/schema/types.js +241 -0
- package/dist/node/serve.js +90 -0
- package/dist/node/site-page-nodes.js +277 -0
- package/dist/node/types.js +1 -0
- package/dist/node/utils/content-digest.js +107 -0
- package/dist/node/utils/cpus.js +104 -0
- package/dist/node/utils/create-node-id.js +51 -0
- package/dist/node/utils/env.js +25 -0
- package/dist/node/utils/fs-retry.js +74 -0
- package/dist/node/utils/memory-signals.js +441 -0
- package/dist/node/utils/memory.js +657 -0
- package/dist/node/utils/murmurhash.js +32 -0
- package/dist/node/utils/parser.js +33 -0
- package/dist/node/utils/partition-hash.js +19 -0
- package/dist/node/utils/paths.js +122 -0
- package/dist/node/utils/resolver.js +48 -0
- package/dist/node/utils/runtime.js +5 -0
- package/dist/node/utils/serializable.js +41 -0
- package/dist/node/utils/strings.js +41 -0
- package/dist/node/vite/config.js +289 -0
- package/dist/node/vite/paths.js +12 -0
- package/dist/node/vite/plugin-deps.js +232 -0
- package/dist/node/vite/plugin.js +283 -0
- package/dist/node/vite/react-compiler.js +362 -0
- package/dist/node/vite/source-files.js +83 -0
- package/dist/node/vite/static-image.js +136 -0
- package/dist/node/vite/styled-components.js +73 -0
- package/dist/node/vite/transforms.js +330 -0
- package/dist/node/wasm-data/host.js +406 -0
- package/dist/node/wasm-data/lower.js +406 -0
- package/dist/node/wasm-data/runner.js +79 -0
- package/dist/node/wasm-data/worker.js +95 -0
- package/dist/reporter.js +5 -0
- package/dist/runtime/api-runner.js +81 -0
- package/dist/runtime/app.js +256 -0
- package/dist/runtime/client-entry.js +4 -0
- package/dist/runtime/client.js +383 -0
- package/dist/runtime/default-html.js +31 -0
- package/dist/runtime/head-markup.js +100 -0
- package/dist/runtime/head-sync.js +101 -0
- package/dist/runtime/head-tags.js +45 -0
- package/dist/runtime/hydration-report.js +111 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/link.js +293 -0
- package/dist/runtime/loader.js +449 -0
- package/dist/runtime/not-found.js +61 -0
- package/dist/runtime/page-renderer.js +35 -0
- package/dist/runtime/preamble.js +47 -0
- package/dist/runtime/react-compat.js +14 -0
- package/dist/runtime/renderer-shared.js +10 -0
- package/dist/runtime/renderers/react-client.js +14 -0
- package/dist/runtime/renderers/react-server.js +99 -0
- package/dist/runtime/renderers/react.js +17 -0
- package/dist/runtime/renderers/types.js +1 -0
- package/dist/runtime/root-error-handlers.js +29 -0
- package/dist/runtime/router/history.js +132 -0
- package/dist/runtime/router/index.js +240 -0
- package/dist/runtime/router/utils.js +118 -0
- package/dist/runtime/script.js +110 -0
- package/dist/runtime/scroll.js +40 -0
- package/dist/runtime/slice.js +11 -0
- package/dist/runtime/ssr.js +240 -0
- package/dist/runtime/static-query.js +47 -0
- package/dist/utils.js +4 -0
- package/package.json +105 -3
- package/types/graphql-tada.d.ts +223 -0
- package/types/graphql.d.ts +2 -0
- package/types/index.d.ts +2287 -0
- package/types/node.d.ts +389 -0
- package/types/reporter.d.ts +187 -0
- package/types/router.d.ts +102 -0
- package/types/vendor/gql-tada.d.ts +2529 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { getNamedType, getNullableType, isListType } from "../gql.js";
|
|
2
|
+
import { formatDate } from "./date.js";
|
|
3
|
+
import { getValueAt } from "./query-engine.js";
|
|
4
|
+
import { slash } from "../utils/paths.js";
|
|
5
|
+
import reporter from "../reporter.js";
|
|
6
|
+
import { isRootFree, ownField, rootFree, sharedArgsIf, syncVariantOf, withSyncVariant } from "./inline-objects.js";
|
|
7
|
+
import { tagResolver } from "./resolver-kinds.js";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
// src/node/schema/extensions.ts
|
|
10
|
+
/** Gatsby's default field resolver – supports `info.from` / `info.fromNode` set by `@proxy`. */
|
|
11
|
+
const defaultFieldResolver = function defaultFieldResolver(source, _args, context, info) {
|
|
12
|
+
if (!source || typeof source !== "object") return null;
|
|
13
|
+
if (info.from) {
|
|
14
|
+
if (info.fromNode) {
|
|
15
|
+
const node = context?.nodeModel?.findRootNodeAncestor(source);
|
|
16
|
+
if (!node) return null;
|
|
17
|
+
return getValueAt(node, info.from);
|
|
18
|
+
}
|
|
19
|
+
return getValueAt(source, info.from);
|
|
20
|
+
}
|
|
21
|
+
return source[info.fieldName];
|
|
22
|
+
};
|
|
23
|
+
const withFrom = (info, options) => ({
|
|
24
|
+
...info,
|
|
25
|
+
from: options.from || info.from,
|
|
26
|
+
fromNode: options.from ? options.fromNode : info.fromNode
|
|
27
|
+
});
|
|
28
|
+
function createSelector(by, value) {
|
|
29
|
+
const parts = by.split(".");
|
|
30
|
+
let filter = value;
|
|
31
|
+
for (let i = parts.length - 1; i >= 0; i--) filter = { [parts[i]]: filter };
|
|
32
|
+
return filter;
|
|
33
|
+
}
|
|
34
|
+
/** what a resolver returns: a value or a promise of one (graphql-js' `isPromise`) */
|
|
35
|
+
function isPromiseLike(value) {
|
|
36
|
+
return (typeof value === "object" && value !== null || typeof value === "function") && typeof value.then === "function";
|
|
37
|
+
}
|
|
38
|
+
function linkResolver(options, fieldConfig) {
|
|
39
|
+
const by = options.by ?? "id";
|
|
40
|
+
const linked = (fieldValue, context, info) => {
|
|
41
|
+
if (fieldValue == null) return null;
|
|
42
|
+
const returnType = getNullableType(options.type || info.returnType);
|
|
43
|
+
const type = typeof returnType === "string" ? returnType : getNamedType(returnType);
|
|
44
|
+
if (by === "id") {
|
|
45
|
+
if (Array.isArray(fieldValue)) return context.nodeModel.getNodesByIds({
|
|
46
|
+
ids: fieldValue,
|
|
47
|
+
type
|
|
48
|
+
});
|
|
49
|
+
return context.nodeModel.getNodeById({
|
|
50
|
+
id: fieldValue,
|
|
51
|
+
type
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return linkedBy(fieldValue, returnType, type, context);
|
|
55
|
+
};
|
|
56
|
+
const linkedBy = async (fieldValue, returnType, type, context) => {
|
|
57
|
+
if (Array.isArray(fieldValue) && fieldValue.length === 0) return fieldValue;
|
|
58
|
+
if (typeof returnType !== "string" && isListType(returnType) || Array.isArray(fieldValue)) {
|
|
59
|
+
const values = [].concat(fieldValue);
|
|
60
|
+
const { entries } = await context.nodeModel.findAll({
|
|
61
|
+
type,
|
|
62
|
+
query: { filter: createSelector(by, { in: values }) }
|
|
63
|
+
});
|
|
64
|
+
const byValue = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const n of entries) {
|
|
66
|
+
const nv = getValueAt(n, by);
|
|
67
|
+
if (!Array.isArray(nv) && nv !== nv) continue;
|
|
68
|
+
for (const x of Array.isArray(nv) ? new Set(nv) : [nv]) {
|
|
69
|
+
let list = byValue.get(x);
|
|
70
|
+
if (!list) byValue.set(x, list = []);
|
|
71
|
+
list.push(n);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return values.flatMap((v) => byValue.get(v) ?? []);
|
|
75
|
+
}
|
|
76
|
+
return context.nodeModel.findOne({
|
|
77
|
+
type,
|
|
78
|
+
query: { filter: createSelector(by, { eq: fieldValue }) }
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const resolveLink = async function resolveLink(source, args, context, info) {
|
|
82
|
+
const resolver = fieldConfig.resolve || defaultFieldResolver;
|
|
83
|
+
return linked(await resolver(source, args, context, withFrom(info, options)), context, info);
|
|
84
|
+
};
|
|
85
|
+
const inner = syncVariantOf(fieldConfig.resolve);
|
|
86
|
+
const copyInfo = !!options.from || !!inner;
|
|
87
|
+
withSyncVariant(resolveLink, function resolveLinkSync(source, args, context, info) {
|
|
88
|
+
const fieldValue = (inner || defaultFieldResolver)(source, args, context, copyInfo ? withFrom(info, options) : info);
|
|
89
|
+
return isPromiseLike(fieldValue) ? Promise.resolve(fieldValue).then((value) => linked(value, context, info)) : linked(fieldValue, context, info);
|
|
90
|
+
});
|
|
91
|
+
sharedArgsIf(resolveLink, fieldConfig.resolve);
|
|
92
|
+
tagResolver(resolveLink, {
|
|
93
|
+
k: "link",
|
|
94
|
+
by,
|
|
95
|
+
from: options.from,
|
|
96
|
+
fromNode: options.fromNode,
|
|
97
|
+
on: options.type,
|
|
98
|
+
inner: fieldConfig.resolve
|
|
99
|
+
});
|
|
100
|
+
if (!options.from && !fieldConfig.resolve) ownField(resolveLink);
|
|
101
|
+
return options.from && options.fromNode ? resolveLink : rootFreeIf(resolveLink, fieldConfig);
|
|
102
|
+
}
|
|
103
|
+
/** marks a wrapping resolver root free when the resolver it calls is */
|
|
104
|
+
function rootFreeIf(resolve, fieldConfig) {
|
|
105
|
+
return isRootFree(fieldConfig.resolve) ? rootFree(resolve) : resolve;
|
|
106
|
+
}
|
|
107
|
+
function fileByPathResolver(options, fieldConfig) {
|
|
108
|
+
return async function resolveFileByPath(source, args, context, info) {
|
|
109
|
+
const fieldValue = await (fieldConfig.resolve || defaultFieldResolver)(source, args, context, withFrom(info, options));
|
|
110
|
+
if (fieldValue == null) return null;
|
|
111
|
+
const findLinkedFileNode = async (relativePath) => {
|
|
112
|
+
if (typeof relativePath !== "string") return null;
|
|
113
|
+
const fileNode = context.nodeModel.findRootNodeAncestor(source, (node) => node.internal?.type === "File");
|
|
114
|
+
if (!fileNode) return null;
|
|
115
|
+
const absolutePath = slash(path.join(fileNode.dir, relativePath));
|
|
116
|
+
return context.nodeModel.findOne({
|
|
117
|
+
type: "File",
|
|
118
|
+
query: { filter: { absolutePath: { eq: absolutePath } } }
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
const resolve = (value) => Array.isArray(value) ? Promise.all(value.map(resolve)) : findLinkedFileNode(value);
|
|
122
|
+
return resolve(fieldValue);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function dateResolver(options, prevFieldConfig) {
|
|
126
|
+
const { locale, formatString, fromNow, difference } = options;
|
|
127
|
+
const format = (date, args) => date == null ? null : formatDate(date, args ?? {});
|
|
128
|
+
const resolve = async function resolveDate(source, args, context, info) {
|
|
129
|
+
const resolver = prevFieldConfig.resolve || defaultFieldResolver;
|
|
130
|
+
return format(await resolver(source, args, context, withFrom(info, options)), args);
|
|
131
|
+
};
|
|
132
|
+
const inner = syncVariantOf(prevFieldConfig.resolve);
|
|
133
|
+
const copyInfo = !!options.from || !!inner;
|
|
134
|
+
withSyncVariant(resolve, function resolveDateSync(source, args, context, info) {
|
|
135
|
+
const date = (inner || defaultFieldResolver)(source, args, context, copyInfo ? withFrom(info, options) : info);
|
|
136
|
+
return isPromiseLike(date) ? Promise.resolve(date).then((value) => format(value, args)) : format(date, args);
|
|
137
|
+
});
|
|
138
|
+
sharedArgsIf(resolve, prevFieldConfig.resolve);
|
|
139
|
+
tagResolver(resolve, {
|
|
140
|
+
k: "date",
|
|
141
|
+
from: options.from,
|
|
142
|
+
fromNode: options.fromNode,
|
|
143
|
+
inner: prevFieldConfig.resolve
|
|
144
|
+
});
|
|
145
|
+
if (!prevFieldConfig.resolve && !formatString && !fromNow && !difference && !options.from) resolve.__goatlyPassthrough = true;
|
|
146
|
+
if (!(options.from && options.fromNode)) rootFreeIf(resolve, prevFieldConfig);
|
|
147
|
+
if (!options.from && !prevFieldConfig.resolve) ownField(resolve);
|
|
148
|
+
return {
|
|
149
|
+
args: {
|
|
150
|
+
...prevFieldConfig.args,
|
|
151
|
+
formatString: {
|
|
152
|
+
type: "String",
|
|
153
|
+
description: "Format the date using Moment.js' date tokens, e.g. `date(formatString: \"YYYY MMMM DD\")`. See https://momentjs.com/docs/#/displaying/format/ for documentation for different tokens.",
|
|
154
|
+
defaultValue: formatString
|
|
155
|
+
},
|
|
156
|
+
fromNow: {
|
|
157
|
+
type: "Boolean",
|
|
158
|
+
description: "Returns a string generated with Moment.js' `fromNow` function",
|
|
159
|
+
defaultValue: fromNow
|
|
160
|
+
},
|
|
161
|
+
difference: {
|
|
162
|
+
type: "String",
|
|
163
|
+
description: "Returns the difference between this date and the current time.",
|
|
164
|
+
defaultValue: difference
|
|
165
|
+
},
|
|
166
|
+
locale: {
|
|
167
|
+
type: "String",
|
|
168
|
+
description: "Configures the locale Moment.js will use to format the date.",
|
|
169
|
+
defaultValue: locale
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
resolve
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const builtInFieldExtensions = {
|
|
176
|
+
dateformat: {
|
|
177
|
+
name: "dateformat",
|
|
178
|
+
description: "Add date formatting options.",
|
|
179
|
+
args: {
|
|
180
|
+
formatString: "String",
|
|
181
|
+
locale: "String",
|
|
182
|
+
fromNow: "Boolean",
|
|
183
|
+
difference: "String"
|
|
184
|
+
},
|
|
185
|
+
extend(args = {}, fieldConfig) {
|
|
186
|
+
return dateResolver(args, fieldConfig);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
link: {
|
|
190
|
+
name: "link",
|
|
191
|
+
description: "Link to node by foreign-key relation.",
|
|
192
|
+
args: {
|
|
193
|
+
by: {
|
|
194
|
+
type: "String!",
|
|
195
|
+
defaultValue: "id"
|
|
196
|
+
},
|
|
197
|
+
from: "String",
|
|
198
|
+
on: "String"
|
|
199
|
+
},
|
|
200
|
+
extend(args = {}, fieldConfig) {
|
|
201
|
+
return { resolve: linkResolver({
|
|
202
|
+
...args,
|
|
203
|
+
type: args.on
|
|
204
|
+
}, fieldConfig) };
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
fileByRelativePath: {
|
|
208
|
+
name: "fileByRelativePath",
|
|
209
|
+
description: "Link to File node by relative path.",
|
|
210
|
+
args: { from: "String" },
|
|
211
|
+
extend(args = {}, fieldConfig) {
|
|
212
|
+
return { resolve: fileByPathResolver(args, fieldConfig) };
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
proxy: {
|
|
216
|
+
name: "proxy",
|
|
217
|
+
description: "Proxy resolver from another field.",
|
|
218
|
+
args: {
|
|
219
|
+
from: "String!",
|
|
220
|
+
fromNode: {
|
|
221
|
+
type: "Boolean!",
|
|
222
|
+
defaultValue: false
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
extend(options = {}, fieldConfig) {
|
|
226
|
+
const resolve = (source, args, context, info) => {
|
|
227
|
+
return (fieldConfig.resolve || defaultFieldResolver)(source, args, context, {
|
|
228
|
+
...info,
|
|
229
|
+
from: options.from,
|
|
230
|
+
fromNode: options.fromNode
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
sharedArgsIf(resolve, fieldConfig.resolve);
|
|
234
|
+
return { resolve: options.fromNode ? resolve : rootFreeIf(resolve, fieldConfig) };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
/** Type-level directives (no extend function). */
|
|
239
|
+
const typeExtensionDirectiveSDL = `
|
|
240
|
+
directive @infer on OBJECT
|
|
241
|
+
directive @dontInfer on OBJECT
|
|
242
|
+
directive @mimeTypes(types: [String!]! = []) on OBJECT
|
|
243
|
+
directive @childOf(types: [String!]! = [], mimeTypes: [String!]! = [], many: Boolean! = false) on OBJECT
|
|
244
|
+
directive @nodeInterface on INTERFACE
|
|
245
|
+
`;
|
|
246
|
+
const INTERNAL_EXTENSION_NAMES = /* @__PURE__ */ new Set([
|
|
247
|
+
"createdFrom",
|
|
248
|
+
"default",
|
|
249
|
+
"directives",
|
|
250
|
+
"infer",
|
|
251
|
+
"plugin",
|
|
252
|
+
"dontInfer",
|
|
253
|
+
"mimeTypes",
|
|
254
|
+
"childOf",
|
|
255
|
+
"nodeInterface",
|
|
256
|
+
"deprecated"
|
|
257
|
+
]);
|
|
258
|
+
function argToSDL(name, config) {
|
|
259
|
+
return `${name}: ${typeof config === "string" ? config : config.type}${typeof config === "object" && config.defaultValue !== void 0 ? ` = ${JSON.stringify(config.defaultValue)}` : ""}`;
|
|
260
|
+
}
|
|
261
|
+
function registerFieldExtensionDirectives(sc, extensions) {
|
|
262
|
+
sc.addTypeDefs(typeExtensionDirectiveSDL);
|
|
263
|
+
for (const [name, ext] of Object.entries(extensions)) {
|
|
264
|
+
if (sc.hasDirective(name)) continue;
|
|
265
|
+
const args = Object.entries(ext.args ?? {}).map(([n, c]) => argToSDL(n, c));
|
|
266
|
+
try {
|
|
267
|
+
sc.addTypeDefs(`directive @${name}${args.length ? `(${args.join(", ")})` : ""} on FIELD_DEFINITION`);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
reporter.error({
|
|
270
|
+
context: { sourceMessage: `Invalid field extension "${name}"` },
|
|
271
|
+
error: e
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Applies field extensions (from SDL directives or `extensions` in type builders) to all fields of a type.
|
|
278
|
+
*/
|
|
279
|
+
function processFieldExtensions(tc, extensions) {
|
|
280
|
+
for (const fieldName of tc.getFieldNames()) {
|
|
281
|
+
const fieldExtensions = { ...tc.getFieldExtensions(fieldName) };
|
|
282
|
+
for (const directive of tc.getFieldDirectives(fieldName)) {
|
|
283
|
+
if (directive.name === "deprecated") continue;
|
|
284
|
+
fieldExtensions[directive.name] = directive.args ?? {};
|
|
285
|
+
}
|
|
286
|
+
const names = Object.keys(fieldExtensions).filter((n) => !INTERNAL_EXTENSION_NAMES.has(n)).sort((a) => a === "proxy" ? -1 : 0);
|
|
287
|
+
for (const name of names) {
|
|
288
|
+
const ext = extensions[name];
|
|
289
|
+
if (!ext) continue;
|
|
290
|
+
if (typeof ext.extend === "function") {
|
|
291
|
+
const options = {
|
|
292
|
+
...defaultsFor(ext),
|
|
293
|
+
...fieldExtensions[name] === true ? {} : fieldExtensions[name]
|
|
294
|
+
};
|
|
295
|
+
const prevFieldConfig = tc.getFieldConfig(fieldName);
|
|
296
|
+
try {
|
|
297
|
+
tc.extendField(fieldName, ext.extend(options, prevFieldConfig));
|
|
298
|
+
} catch (e) {
|
|
299
|
+
reporter.error({
|
|
300
|
+
context: { sourceMessage: `Error applying field extension "@${name}" on ${tc.getTypeName()}.${fieldName}` },
|
|
301
|
+
error: e
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const remaining = tc.getFieldDirectives(fieldName).filter((d) => !extensions[d.name] || d.name === "deprecated");
|
|
307
|
+
tc.setFieldDirectives(fieldName, remaining);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function defaultsFor(ext) {
|
|
311
|
+
const out = {};
|
|
312
|
+
for (const [name, config] of Object.entries(ext.args ?? {})) if (config && typeof config === "object" && "defaultValue" in config) out[name] = config.defaultValue;
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
export { builtInFieldExtensions, defaultFieldResolver, fileByPathResolver, linkResolver, processFieldExtensions, registerFieldExtensionDirectives, typeExtensionDirectiveSDL };
|