nitro-graphql 0.0.4 → 0.0.6
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 +1 -30
- package/dist/_virtual/rolldown_runtime.js +37 -0
- package/dist/ecosystem/nuxt.d.ts +7 -0
- package/dist/ecosystem/nuxt.js +30 -0
- package/dist/graphql/index.d.ts +5 -0
- package/dist/graphql/server.d.ts +5 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +125 -135
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/config.js +9 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/index.js +17 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_import-types-preset@3.0.1_graphql@16.11.0/node_modules/@graphql-codegen/import-types-preset/esm/index.js +38 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/federation.js +22 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/getCachedDocumentNodeFromSchema.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/helpers.js +79 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/index.js +6 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/oldVisit.js +1 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/resolve-external-module-and-fn.js +7 -0
- package/dist/node_modules/.pnpm/@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/utils.js +13 -0
- package/dist/node_modules/.pnpm/camel-case@4.1.2/node_modules/camel-case/dist/index.js +33 -0
- package/dist/node_modules/.pnpm/capital-case@1.0.4/node_modules/capital-case/dist/index.js +32 -0
- package/dist/node_modules/.pnpm/change-case-all@1.0.15/node_modules/change-case-all/dist/index.js +56 -0
- package/dist/node_modules/.pnpm/change-case@4.1.2/node_modules/change-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/constant-case@3.0.4/node_modules/constant-case/dist/index.js +28 -0
- package/dist/node_modules/.pnpm/dot-case@3.0.4/node_modules/dot-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/header-case@2.0.4/node_modules/header-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/is-lower-case@2.0.2/node_modules/is-lower-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/is-upper-case@2.0.2/node_modules/is-upper-case/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Hash.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_ListCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Map.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_MapCache.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Stack.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Uint8Array.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_apply.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayLikeKeys.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignMergeValue.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignValue.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseAssignValue.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseCreate.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFor.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsArguments.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +44 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsTypedArray.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseKeysIn.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMerge.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseMergeDeep.js +75 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseRest.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSetToString.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseTimes.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseUnary.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneArrayBuffer.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneBuffer.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_cloneTypedArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyArray.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_copyObject.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_coreJsData.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createAssigner.js +37 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createBaseFor.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_defineProperty.js +20 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getMapData.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getNative.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getPrototype.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getValue.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashDelete.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashGet.js +36 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashHas.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_initCloneObject.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIndex.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIterateeCall.js +32 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKeyable.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js +28 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isPrototype.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +26 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +31 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeKeysIn.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nodeUtil.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +29 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overArg.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overRest.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_safeGet.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_setToString.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_shortOut.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackClear.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackDelete.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackGet.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackHas.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stackSet.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toSource.js +33 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/constant.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/eq.js +46 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/identity.js +30 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArguments.js +43 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArray.js +35 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLike.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArrayLikeObject.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isBuffer.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isFunction.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isLength.js +42 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +40 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +38 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isPlainObject.js +60 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isTypedArray.js +34 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/keysIn.js +41 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/merge.js +48 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/stubFalse.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toPlainObject.js +41 -0
- package/dist/node_modules/.pnpm/lower-case-first@2.0.2/node_modules/lower-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/lower-case@2.0.2/node_modules/lower-case/dist/index.js +64 -0
- package/dist/node_modules/.pnpm/no-case@3.0.4/node_modules/no-case/dist/index.js +41 -0
- package/dist/node_modules/.pnpm/param-case@3.0.4/node_modules/param-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/pascal-case@3.1.2/node_modules/pascal-case/dist/index.js +37 -0
- package/dist/node_modules/.pnpm/path-case@3.0.4/node_modules/path-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sentence-case@3.0.4/node_modules/sentence-case/dist/index.js +34 -0
- package/dist/node_modules/.pnpm/snake-case@3.0.4/node_modules/snake-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/sponge-case@1.0.1/node_modules/sponge-case/dist/index.js +20 -0
- package/dist/node_modules/.pnpm/swap-case@2.0.2/node_modules/swap-case/dist/index.js +23 -0
- package/dist/node_modules/.pnpm/title-case@3.0.3/node_modules/title-case/dist/index.js +35 -0
- package/dist/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.js +547 -0
- package/dist/node_modules/.pnpm/upper-case-first@2.0.2/node_modules/upper-case-first/dist/index.js +21 -0
- package/dist/node_modules/.pnpm/upper-case@2.0.2/node_modules/upper-case/dist/index.js +56 -0
- package/dist/rollup.js +87 -0
- package/dist/routes/apollo-server.d.ts +6 -0
- package/dist/routes/apollo-server.js +39 -0
- package/dist/routes/graphql-yoga.d.ts +6 -0
- package/dist/routes/graphql-yoga.js +56 -0
- package/dist/routes/health.d.ts +10 -0
- package/dist/routes/health.js +44 -0
- package/dist/types/index.d.ts +67 -0
- package/dist/types/standard-schema.d.ts +59 -0
- package/dist/utils/apollo.js +62 -0
- package/dist/{client-codegen.js → utils/client-codegen.js} +52 -16
- package/dist/utils/define.d.ts +17 -0
- package/dist/utils/define.js +25 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +107 -0
- package/dist/{codegen.js → utils/server-codegen.js} +55 -35
- package/dist/utils/server-type-generation.js +52 -0
- package/package.json +37 -13
- package/dist/client-watcher.d.ts +0 -7
- package/dist/client-watcher.js +0 -100
- package/dist/codegen.d.ts +0 -13
- package/dist/context.d.ts +0 -10
- package/dist/dev.js +0 -95
- package/dist/prerender.js +0 -279
- package/dist/scanner.js +0 -118
- package/dist/types.d.ts +0 -46
- package/dist/utils.d.ts +0 -13
- package/dist/utils.js +0 -23
- /package/dist/{context.js → graphql/index.js} +0 -0
- /package/dist/{types.js → graphql/server.js} +0 -0
package/README.md
CHANGED
|
@@ -46,21 +46,6 @@ export default defineNitroConfig({
|
|
|
46
46
|
endpoint: '/api/graphql', // default
|
|
47
47
|
playground: true, // default (Apollo Sandbox)
|
|
48
48
|
cors: false, // default
|
|
49
|
-
cacheHeaders: {
|
|
50
|
-
enabled: true, // default
|
|
51
|
-
maxAge: 604800, // default (1 week)
|
|
52
|
-
},
|
|
53
|
-
client: {
|
|
54
|
-
enabled: false, // default
|
|
55
|
-
outputPath: undefined, // Will default to .nitro/types/graphql-client.generated.ts
|
|
56
|
-
watchPatterns: undefined, // Will default to src/**/*.{graphql,gql} excluding server/graphql
|
|
57
|
-
config: {
|
|
58
|
-
documentMode: 'string',
|
|
59
|
-
emitLegacyCommonJSImports: false,
|
|
60
|
-
useTypeImports: true,
|
|
61
|
-
enumsAsTypes: true,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
49
|
}
|
|
65
50
|
})
|
|
66
51
|
```
|
|
@@ -173,7 +158,7 @@ The module automatically generates TypeScript types from your GraphQL schema:
|
|
|
173
158
|
These types are automatically available in your resolvers:
|
|
174
159
|
|
|
175
160
|
```ts
|
|
176
|
-
import type { QueryResolvers } from '#
|
|
161
|
+
import type { QueryResolvers } from '#graphql/server'
|
|
177
162
|
// server/graphql/users/user-queries.ts
|
|
178
163
|
import { defineResolver } from 'nitro-graphql'
|
|
179
164
|
|
|
@@ -258,12 +243,6 @@ interface NitroGraphQLYogaOptions {
|
|
|
258
243
|
methods?: string[]
|
|
259
244
|
}
|
|
260
245
|
|
|
261
|
-
// Cache headers configuration
|
|
262
|
-
cacheHeaders?: {
|
|
263
|
-
enabled?: boolean // default: true
|
|
264
|
-
maxAge?: number // default: 604800 (1 week)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
246
|
// Client type generation
|
|
268
247
|
client?: {
|
|
269
248
|
enabled?: boolean // default: false
|
|
@@ -362,14 +341,6 @@ Enable client type generation for your frontend queries:
|
|
|
362
341
|
// nitro.config.ts
|
|
363
342
|
export default defineNitroConfig({
|
|
364
343
|
graphqlYoga: {
|
|
365
|
-
client: {
|
|
366
|
-
enabled: true,
|
|
367
|
-
watchPatterns: [
|
|
368
|
-
'client/**/*.graphql',
|
|
369
|
-
'pages/**/*.vue',
|
|
370
|
-
'components/**/*.vue'
|
|
371
|
-
]
|
|
372
|
-
}
|
|
373
344
|
}
|
|
374
345
|
})
|
|
375
346
|
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all) __defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
22
|
+
key = keys[i];
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
24
|
+
get: ((k) => from[k]).bind(null, key),
|
|
25
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
+
value: mod,
|
|
32
|
+
enumerable: true
|
|
33
|
+
}) : target, mod));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { __commonJS, __esm, __export, __toCommonJS, __toESM };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { join, resolve } from "pathe";
|
|
2
|
+
import { defineNuxtModule } from "@nuxt/kit";
|
|
3
|
+
|
|
4
|
+
//#region src/ecosystem/nuxt.ts
|
|
5
|
+
var nuxt_default = defineNuxtModule({
|
|
6
|
+
meta: {
|
|
7
|
+
name: "nitro-graphql-nuxt",
|
|
8
|
+
configKey: "nitro-graphql-nuxt",
|
|
9
|
+
compatibility: { nuxt: ">=3.16.0" }
|
|
10
|
+
},
|
|
11
|
+
setup: async (_options, nuxt) => {
|
|
12
|
+
nuxt.hooks.hook("prepare:types", (options) => {
|
|
13
|
+
options.references.push({ path: "types/nitro-graphql-client.d.ts" });
|
|
14
|
+
options.tsConfig ??= {};
|
|
15
|
+
options.tsConfig.compilerOptions ??= {};
|
|
16
|
+
options.tsConfig.compilerOptions.paths ??= {};
|
|
17
|
+
options.tsConfig.compilerOptions.paths["#graphql/client"] = ["./types/nitro-graphql-client.d.ts"];
|
|
18
|
+
options.tsConfig.include = options.tsConfig.include || [];
|
|
19
|
+
options.tsConfig.include.push("./types/nitro-graphql-client.d.ts");
|
|
20
|
+
});
|
|
21
|
+
nuxt.options.alias = nuxt.options.alias || {};
|
|
22
|
+
nuxt.options.alias["#graphql/client"] = join(nuxt.options.buildDir, "types/nitro-graphql-client.d.ts");
|
|
23
|
+
nuxt.hook("imports:dirs", (dirs) => {
|
|
24
|
+
dirs.push(resolve(nuxt.options.srcDir, "graphql"));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { nuxt_default as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StandardSchemaV1 } from "./types/standard-schema.js";
|
|
2
|
+
import { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions } from "./types/index.js";
|
|
3
|
+
import { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType } from "./utils/define.js";
|
|
4
|
+
import * as nitropack5 from "nitropack";
|
|
2
5
|
|
|
3
6
|
//#region src/index.d.ts
|
|
4
|
-
|
|
7
|
+
interface Resolvers extends Record<string, any> {}
|
|
8
|
+
interface CustomSchema extends Record<string, any> {}
|
|
9
|
+
type GraphQLFramework = 'graphql-yoga';
|
|
10
|
+
declare const _default: nitropack5.NitroModule;
|
|
5
11
|
//#endregion
|
|
6
|
-
export { _default as default };
|
|
12
|
+
export { CodegenClientConfig, CodegenServerConfig, CustomSchema, GenImport, GraphQLFramework, NitroGraphQLOptions, Resolvers, StandardSchemaV1, _default as default, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
package/dist/index.js
CHANGED
|
@@ -1,162 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { relativeWithDot, scanDefs, scanResolvers } from "./utils/index.js";
|
|
2
|
+
import { clientTypeGeneration, serverTypeGeneration } from "./utils/server-type-generation.js";
|
|
3
|
+
import { rollupConfig } from "./rollup.js";
|
|
4
|
+
import { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType } from "./utils/define.js";
|
|
5
|
+
import { writeFileSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { watch } from "chokidar";
|
|
8
|
+
import defu from "defu";
|
|
4
9
|
import { defineNitroModule } from "nitropack/kit";
|
|
10
|
+
import { dirname, join, resolve } from "pathe";
|
|
5
11
|
|
|
6
12
|
//#region src/index.ts
|
|
7
13
|
var src_default = defineNitroModule({
|
|
8
|
-
name: "nitro
|
|
14
|
+
name: "nitro-graphql",
|
|
9
15
|
async setup(nitro) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
nitro.graphql ||= {
|
|
17
|
+
buildDir: "",
|
|
18
|
+
watchDirs: [],
|
|
19
|
+
clientDir: "",
|
|
20
|
+
serverDir: resolve(nitro.options.srcDir, "graphql")
|
|
21
|
+
};
|
|
22
|
+
nitro.hooks.hook("rollup:before", (nitro$1, rollupConfig$1) => {
|
|
23
|
+
rollupConfig$1.external = rollupConfig$1.external || [];
|
|
24
|
+
const codegenExternals = ["oxc-parser", "@oxc-parser"];
|
|
25
|
+
if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
|
|
26
|
+
else if (typeof rollupConfig$1.external === "function") {
|
|
27
|
+
const originalExternal = rollupConfig$1.external;
|
|
28
|
+
rollupConfig$1.external = (id, parent, isResolved) => {
|
|
29
|
+
if (codegenExternals.some((external) => id.includes(external))) return true;
|
|
30
|
+
return originalExternal(id, parent, isResolved);
|
|
21
31
|
};
|
|
22
32
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
endpoint:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
cacheHeaders: {
|
|
29
|
-
enabled: true,
|
|
30
|
-
maxAge: 604800
|
|
31
|
-
},
|
|
32
|
-
client: {
|
|
33
|
-
enabled: nitro.options.framework?.name === "nuxt",
|
|
34
|
-
outputPath: void 0,
|
|
35
|
-
watchPatterns: void 0,
|
|
36
|
-
config: {
|
|
37
|
-
documentMode: "string",
|
|
38
|
-
emitLegacyCommonJSImports: false,
|
|
39
|
-
useTypeImports: true,
|
|
40
|
-
enumsAsTypes: true
|
|
41
|
-
}
|
|
33
|
+
});
|
|
34
|
+
nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
|
|
35
|
+
endpoint: {
|
|
36
|
+
graphql: "/api/graphql",
|
|
37
|
+
healthCheck: "/api/graphql/health"
|
|
42
38
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
nitro.options.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const { prerender } = await import("./prerender.js");
|
|
55
|
-
await prerender(nitro, options);
|
|
39
|
+
playground: true
|
|
40
|
+
});
|
|
41
|
+
const graphqlBuildDir = resolve(nitro.options.buildDir, "graphql");
|
|
42
|
+
nitro.graphql.buildDir = graphqlBuildDir;
|
|
43
|
+
const watchDirs = [];
|
|
44
|
+
switch (nitro.options.framework.name) {
|
|
45
|
+
case "nuxt":
|
|
46
|
+
watchDirs.push(join(nitro.options.rootDir, "app", "graphql"));
|
|
47
|
+
nitro.graphql.clientDir = resolve(nitro.options.rootDir, "app", "graphql");
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
56
50
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
const watcher = watch(watchDirs, {
|
|
52
|
+
persistent: true,
|
|
53
|
+
ignoreInitial: true,
|
|
54
|
+
ignored: nitro.options.ignore
|
|
55
|
+
}).on("all", async (event, path) => {
|
|
56
|
+
if (path.endsWith(".graphql") || path.endsWith(".gql")) await clientTypeGeneration(nitro, path);
|
|
61
57
|
});
|
|
62
|
-
nitro.
|
|
63
|
-
|
|
64
|
-
handler: "#nitro-graphql/handler",
|
|
65
|
-
method: "post"
|
|
58
|
+
nitro.hooks.hook("close", () => {
|
|
59
|
+
watcher.close();
|
|
66
60
|
});
|
|
67
|
-
nitro.options.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
const tsConfigPath = resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath);
|
|
62
|
+
const tsconfigDir = dirname(tsConfigPath);
|
|
63
|
+
const typesDir = resolve(nitro.options.buildDir, "types");
|
|
64
|
+
const defs = await scanDefs(nitro);
|
|
65
|
+
nitro.scanDefs = defs;
|
|
66
|
+
const resolvers = await scanResolvers(nitro);
|
|
67
|
+
nitro.scanResolvers = resolvers;
|
|
68
|
+
nitro.hooks.hook("dev:start", async () => {
|
|
69
|
+
const defs$1 = await scanDefs(nitro);
|
|
70
|
+
nitro.scanDefs = defs$1;
|
|
71
|
+
const resolvers$1 = await scanResolvers(nitro);
|
|
72
|
+
nitro.scanResolvers = resolvers$1;
|
|
73
|
+
});
|
|
74
|
+
await rollupConfig(nitro);
|
|
75
|
+
await serverTypeGeneration(nitro);
|
|
76
|
+
await clientTypeGeneration(nitro, nitro.graphql.clientDir);
|
|
77
|
+
const runtime = fileURLToPath(new URL("routes", import.meta.url));
|
|
78
|
+
const methods = [
|
|
79
|
+
"get",
|
|
80
|
+
"post",
|
|
81
|
+
"options"
|
|
82
|
+
];
|
|
83
|
+
if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
|
|
84
|
+
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
85
|
+
handler: join(runtime, "graphql-yoga"),
|
|
86
|
+
method
|
|
87
|
+
});
|
|
88
|
+
if (nitro.options.graphql?.framework === "apollo-server") for (const method of methods) nitro.options.handlers.push({
|
|
89
|
+
route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
|
|
90
|
+
handler: join(runtime, "apollo-server"),
|
|
91
|
+
method
|
|
71
92
|
});
|
|
72
93
|
nitro.options.handlers.push({
|
|
73
|
-
route:
|
|
74
|
-
handler: "
|
|
94
|
+
route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
|
|
95
|
+
handler: join(runtime, "health"),
|
|
75
96
|
method: "get"
|
|
76
97
|
});
|
|
77
|
-
nitro.options.virtual["#nitro-graphql/health"] = () => `
|
|
78
|
-
import { defineEventHandler, setResponseStatus } from 'h3'
|
|
79
|
-
|
|
80
|
-
export default defineEventHandler(async (event) => {
|
|
81
|
-
try {
|
|
82
|
-
const response = await $fetch('${endpoint}', {
|
|
83
|
-
method: 'POST',
|
|
84
|
-
body: {
|
|
85
|
-
query: 'query Health { __typename }',
|
|
86
|
-
operationName: 'Health',
|
|
87
|
-
},
|
|
88
|
-
headers: {
|
|
89
|
-
'Content-Type': 'application/json',
|
|
90
|
-
'Accept': 'application/json',
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
if (response && typeof response === 'object' && 'data' in response) {
|
|
95
|
-
return {
|
|
96
|
-
status: 'healthy',
|
|
97
|
-
message: 'GraphQL server is running',
|
|
98
|
-
timestamp: new Date().toISOString(),
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
throw new Error('Invalid response from GraphQL server')
|
|
103
|
-
} catch (error) {
|
|
104
|
-
setResponseStatus(event, 503)
|
|
105
|
-
return {
|
|
106
|
-
status: 'unhealthy',
|
|
107
|
-
message: error.message || 'GraphQL server is not responding',
|
|
108
|
-
timestamp: new Date().toISOString(),
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
`;
|
|
113
98
|
if (nitro.options.imports) nitro.options.imports.presets.push({
|
|
114
|
-
from: "nitro-graphql/utils",
|
|
115
|
-
imports: [
|
|
99
|
+
from: "nitro-graphql/utils/define",
|
|
100
|
+
imports: [
|
|
101
|
+
"defineResolver",
|
|
102
|
+
"defineMutation",
|
|
103
|
+
"defineQuery",
|
|
104
|
+
"defineSubscription",
|
|
105
|
+
"defineType",
|
|
106
|
+
"defineGraphQLConfig",
|
|
107
|
+
"defineSchema"
|
|
108
|
+
]
|
|
116
109
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
nitro.hooks.hook("rollup:before", (nitro$1, rollupConfig$1) => {
|
|
111
|
+
const manualChunks = rollupConfig$1.output?.manualChunks;
|
|
112
|
+
const chunkFiles = rollupConfig$1.output?.chunkFileNames;
|
|
113
|
+
if (!rollupConfig$1.output.inlineDynamicImports) rollupConfig$1.output.manualChunks = (id, meta) => {
|
|
114
|
+
if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
|
|
115
|
+
if (id.endsWith(".resolver.ts")) return "resolvers";
|
|
116
|
+
if (typeof manualChunks === "function") return manualChunks(id, meta);
|
|
117
|
+
return void 0;
|
|
118
|
+
};
|
|
119
|
+
rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
|
|
120
|
+
if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.includes("/graphql/") || id.includes(".graphql") || id.includes(".resolver.ts") || id.includes(".gql"))) return `chunks/graphql/[name].mjs`;
|
|
121
|
+
if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
|
|
122
|
+
return `chunks/_/[name].mjs`;
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const graphqlDtsContent = `// Auto-generated by nitro-graphql
|
|
126
|
+
|
|
127
|
+
import type { Resolvers as Test, SchemaType } from './nitro-graphql-server.d.ts'
|
|
128
|
+
|
|
129
|
+
declare module 'nitro-graphql' {
|
|
130
|
+
interface Resolvers extends Test {}
|
|
131
|
+
|
|
132
|
+
interface CustomSchema extends SchemaType {}
|
|
133
|
+
|
|
134
|
+
type GraphQLFramework = '${nitro.options.graphql?.framework || "graphql-yoga"}'
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
writeFileSync(join(typesDir, "graphql.d.ts"), graphqlDtsContent);
|
|
138
|
+
nitro.options.typescript.strict = true;
|
|
120
139
|
nitro.hooks.hook("types:extend", (types) => {
|
|
121
140
|
types.tsConfig ||= {};
|
|
122
141
|
types.tsConfig.compilerOptions ??= {};
|
|
123
142
|
types.tsConfig.compilerOptions.paths ??= {};
|
|
124
|
-
types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "graphql-
|
|
125
|
-
types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "graphql-client.
|
|
143
|
+
types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
|
|
144
|
+
types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
|
|
126
145
|
types.tsConfig.include = types.tsConfig.include || [];
|
|
127
|
-
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "graphql-
|
|
128
|
-
});
|
|
129
|
-
const graphqlPath = join(nitro.options.srcDir, "graphql");
|
|
130
|
-
nitro.hooks.hook("rollup:before", (nitro$1, rollupConfig) => {
|
|
131
|
-
rollupConfig.external = rollupConfig.external || [];
|
|
132
|
-
const codegenExternals = [
|
|
133
|
-
"@graphql-codegen/core",
|
|
134
|
-
"@graphql-codegen/typescript",
|
|
135
|
-
"@graphql-codegen/typescript-resolvers",
|
|
136
|
-
"@graphql-codegen/typescript-operations",
|
|
137
|
-
"@graphql-codegen/typescript-generic-sdk",
|
|
138
|
-
"@graphql-tools/graphql-file-loader",
|
|
139
|
-
"@graphql-tools/load"
|
|
140
|
-
];
|
|
141
|
-
if (Array.isArray(rollupConfig.external)) rollupConfig.external.push(...codegenExternals);
|
|
142
|
-
else if (typeof rollupConfig.external === "function") {
|
|
143
|
-
const originalExternal = rollupConfig.external;
|
|
144
|
-
rollupConfig.external = (id, parent, isResolved) => {
|
|
145
|
-
if (codegenExternals.some((external) => id.includes(external))) return true;
|
|
146
|
-
return originalExternal(id, parent, isResolved);
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const originalChunkFileNames = rollupConfig.output.chunkFileNames;
|
|
150
|
-
rollupConfig.output.chunkFileNames = (chunk) => {
|
|
151
|
-
const allIds = chunk.moduleIds || [];
|
|
152
|
-
const hasGraphQLResolverFile = allIds.some((id) => id.includes(graphqlPath) && !id.includes("node_modules") && !id.includes("#nitro-graphql") && (id.endsWith(".ts") || id.endsWith(".js") || id.endsWith(".mjs")));
|
|
153
|
-
if (hasGraphQLResolverFile) return `chunks/graphql/[name].mjs`;
|
|
154
|
-
if (typeof originalChunkFileNames === "function") return originalChunkFileNames(chunk);
|
|
155
|
-
return originalChunkFileNames || "chunks/_/[name].mjs";
|
|
156
|
-
};
|
|
146
|
+
types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
|
|
157
147
|
});
|
|
158
148
|
}
|
|
159
149
|
});
|
|
160
150
|
|
|
161
151
|
//#endregion
|
|
162
|
-
export { src_default as default };
|
|
152
|
+
export { src_default as default, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VALID_PLACEMENTS } from "./config.js";
|
|
2
|
+
|
|
3
|
+
//#region node_modules/.pnpm/@graphql-codegen+add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/index.js
|
|
4
|
+
const plugin = async (schema, documents, config) => {
|
|
5
|
+
const placement = config.placement || "prepend";
|
|
6
|
+
const { content } = config;
|
|
7
|
+
if (!VALID_PLACEMENTS.includes(placement)) throw Error(`Configuration provided for 'add' plugin is invalid: value of 'placement' field is not valid (valid values are: ${VALID_PLACEMENTS.join(", ")})`);
|
|
8
|
+
if (!content) throw Error(`Configuration provided for 'add' plugin is invalid: "content" is missing!`);
|
|
9
|
+
return {
|
|
10
|
+
content: null,
|
|
11
|
+
[placement]: Array.isArray(content) ? content : [content]
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
var esm_default = { plugin };
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { esm_default as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import esm_default from "../../../../../@graphql-codegen_add@3.2.3_graphql@16.11.0/node_modules/@graphql-codegen/add/esm/index.js";
|
|
2
|
+
import { isUsingTypes } from "../../../../../@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/helpers.js";
|
|
3
|
+
import "../../../../../@graphql-codegen_plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/index.js";
|
|
4
|
+
|
|
5
|
+
//#region node_modules/.pnpm/@graphql-codegen+import-types-preset@3.0.1_graphql@16.11.0/node_modules/@graphql-codegen/import-types-preset/esm/index.js
|
|
6
|
+
const preset = { buildGeneratesSection: (options) => {
|
|
7
|
+
if (!options.presetConfig.typesPath) throw new Error(`Preset "import-types" requires you to specify "typesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`);
|
|
8
|
+
const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
|
|
9
|
+
const pluginMap = {
|
|
10
|
+
...options.pluginMap,
|
|
11
|
+
add: esm_default
|
|
12
|
+
};
|
|
13
|
+
const plugins = [...options.plugins];
|
|
14
|
+
const config = {
|
|
15
|
+
...options.config,
|
|
16
|
+
namespacedImportName: importTypesNamespace,
|
|
17
|
+
importOperationTypesFrom: importTypesNamespace,
|
|
18
|
+
externalFragments: []
|
|
19
|
+
};
|
|
20
|
+
options.documents.map((documentFile) => {
|
|
21
|
+
if (isUsingTypes(documentFile.document, config.externalFragments.map((m) => m.name), options.schemaAst)) {
|
|
22
|
+
const importType = options.config.useTypeImports ? "import type" : "import";
|
|
23
|
+
plugins.unshift({ add: { content: `${importType} * as ${importTypesNamespace} from '${options.presetConfig.typesPath}';\n` } });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return [{
|
|
27
|
+
filename: options.baseOutputDir,
|
|
28
|
+
plugins,
|
|
29
|
+
pluginMap,
|
|
30
|
+
config,
|
|
31
|
+
schema: options.schema,
|
|
32
|
+
schemaAst: options.schemaAst,
|
|
33
|
+
documents: options.documents
|
|
34
|
+
}];
|
|
35
|
+
} };
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { preset };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __toESM } from "../../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import "./utils.js";
|
|
3
|
+
import { require_merge } from "../../../../../lodash@4.17.21/node_modules/lodash/merge.js";
|
|
4
|
+
import "./index.js";
|
|
5
|
+
import { isObjectType, parse } from "graphql";
|
|
6
|
+
import "@graphql-tools/utils";
|
|
7
|
+
|
|
8
|
+
//#region node_modules/.pnpm/@graphql-codegen+plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/federation.js
|
|
9
|
+
var import_merge = __toESM(require_merge(), 1);
|
|
10
|
+
/**
|
|
11
|
+
* Federation Spec
|
|
12
|
+
*/
|
|
13
|
+
const federationSpec = parse(`
|
|
14
|
+
scalar _FieldSet
|
|
15
|
+
|
|
16
|
+
directive @external on FIELD_DEFINITION
|
|
17
|
+
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
|
|
18
|
+
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
|
|
19
|
+
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
|
|
20
|
+
`);
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getDocumentNodeFromSchema, memoize1 } from "@graphql-tools/utils";
|
|
2
|
+
|
|
3
|
+
//#region node_modules/.pnpm/@graphql-codegen+plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/getCachedDocumentNodeFromSchema.js
|
|
4
|
+
const getCachedDocumentNodeFromSchema = memoize1(getDocumentNodeFromSchema);
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getBaseType } from "./utils.js";
|
|
2
|
+
import { Kind, isListType, isNonNullType, isObjectType, visit } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region node_modules/.pnpm/@graphql-codegen+plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/helpers.js
|
|
5
|
+
function hasNullableTypeRecursively(type) {
|
|
6
|
+
if (!isNonNullType(type)) return true;
|
|
7
|
+
if (isListType(type) || isNonNullType(type)) return hasNullableTypeRecursively(type.ofType);
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
function isUsingTypes(document, externalFragments, schema) {
|
|
11
|
+
let foundFields = 0;
|
|
12
|
+
const typesStack = [];
|
|
13
|
+
visit(document, {
|
|
14
|
+
SelectionSet: {
|
|
15
|
+
enter(node, key, parent, anscestors) {
|
|
16
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === "FragmentDefinition" && externalFragments.includes(f.name.value));
|
|
17
|
+
if (insideIgnoredFragment) return;
|
|
18
|
+
const selections = node.selections || [];
|
|
19
|
+
if (schema && selections.length > 0) {
|
|
20
|
+
const nextTypeName = (() => {
|
|
21
|
+
if (parent.kind === Kind.FRAGMENT_DEFINITION) return parent.typeCondition.name.value;
|
|
22
|
+
if (parent.kind === Kind.FIELD) {
|
|
23
|
+
const lastType = typesStack[typesStack.length - 1];
|
|
24
|
+
if (!lastType) throw new Error(`Unable to find parent type! Please make sure you operation passes validation`);
|
|
25
|
+
const field = lastType.getFields()[parent.name.value];
|
|
26
|
+
if (!field) throw new Error(`Unable to find field "${parent.name.value}" on type "${lastType}"!`);
|
|
27
|
+
return getBaseType(field.type).name;
|
|
28
|
+
}
|
|
29
|
+
if (parent.kind === Kind.OPERATION_DEFINITION) {
|
|
30
|
+
if (parent.operation === "query") return schema.getQueryType().name;
|
|
31
|
+
if (parent.operation === "mutation") return schema.getMutationType().name;
|
|
32
|
+
if (parent.operation === "subscription") return schema.getSubscriptionType().name;
|
|
33
|
+
} else if (parent.kind === Kind.INLINE_FRAGMENT) {
|
|
34
|
+
if (parent.typeCondition) return parent.typeCondition.name.value;
|
|
35
|
+
return typesStack[typesStack.length - 1].name;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
})();
|
|
39
|
+
typesStack.push(schema.getType(nextTypeName));
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
leave(node) {
|
|
43
|
+
const selections = node.selections || [];
|
|
44
|
+
if (schema && selections.length > 0) typesStack.pop();
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
Field: { enter: (node, key, parent, path, anscestors) => {
|
|
48
|
+
if (node.name.value.startsWith("__")) return;
|
|
49
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === "FragmentDefinition" && externalFragments.includes(f.name.value));
|
|
50
|
+
if (insideIgnoredFragment) return;
|
|
51
|
+
const selections = node.selectionSet ? node.selectionSet.selections || [] : [];
|
|
52
|
+
const relevantFragmentSpreads = selections.filter((s) => s.kind === Kind.FRAGMENT_SPREAD && !externalFragments.includes(s.name.value));
|
|
53
|
+
if (selections.length === 0 || relevantFragmentSpreads.length > 0) foundFields++;
|
|
54
|
+
if (schema) {
|
|
55
|
+
const lastType = typesStack[typesStack.length - 1];
|
|
56
|
+
if (lastType && isObjectType(lastType)) {
|
|
57
|
+
const field = lastType.getFields()[node.name.value];
|
|
58
|
+
if (!field) throw new Error(`Unable to find field "${node.name.value}" on type "${lastType}"!`);
|
|
59
|
+
const currentType = field.type;
|
|
60
|
+
if (hasNullableTypeRecursively(currentType)) foundFields++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} },
|
|
64
|
+
VariableDefinition: { enter: (node, key, parent, path, anscestors) => {
|
|
65
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === "FragmentDefinition" && externalFragments.includes(f.name.value));
|
|
66
|
+
if (insideIgnoredFragment) return;
|
|
67
|
+
foundFields++;
|
|
68
|
+
} },
|
|
69
|
+
InputValueDefinition: { enter: (node, key, parent, path, anscestors) => {
|
|
70
|
+
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === "FragmentDefinition" && externalFragments.includes(f.name.value));
|
|
71
|
+
if (insideIgnoredFragment) return;
|
|
72
|
+
foundFields++;
|
|
73
|
+
} }
|
|
74
|
+
});
|
|
75
|
+
return foundFields > 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { hasNullableTypeRecursively, isUsingTypes };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "./resolve-external-module-and-fn.js";
|
|
2
|
+
import { getBaseType, isWrapperType } from "./utils.js";
|
|
3
|
+
import { hasNullableTypeRecursively, isUsingTypes } from "./helpers.js";
|
|
4
|
+
import "./federation.js";
|
|
5
|
+
import "./getCachedDocumentNodeFromSchema.js";
|
|
6
|
+
import "./oldVisit.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { visit } from "graphql";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { __toESM } from "../../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_dist } from "../../../../../change-case-all@1.0.15/node_modules/change-case-all/dist/index.js";
|
|
3
|
+
|
|
4
|
+
//#region node_modules/.pnpm/@graphql-codegen+plugin-helpers@3.1.2_graphql@16.11.0/node_modules/@graphql-codegen/plugin-helpers/esm/resolve-external-module-and-fn.js
|
|
5
|
+
var import_dist = __toESM(require_dist(), 1);
|
|
6
|
+
|
|
7
|
+
//#endregion
|