nuxt-graphql-middleware 1.2.1 → 2.0.3

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.
@@ -0,0 +1,324 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import mkdirp from 'mkdirp';
4
+ import chokidar from 'chokidar';
5
+ import consola from 'consola';
6
+ import express from 'express';
7
+ import { GraphQLClient } from 'graphql-request';
8
+ import { generate } from '@graphql-codegen/cli';
9
+ import * as PluginTypescript from '@graphql-codegen/typescript';
10
+ import * as PluginTypescriptOperations from '@graphql-codegen/typescript-operations';
11
+ import * as PluginSchemaAst from '@graphql-codegen/schema-ast';
12
+
13
+ // -- Unbuild CommonJS Shims --
14
+ import __cjs_url__ from 'url';
15
+ import __cjs_path__ from 'path';
16
+ import __cjs_mod__ from 'module';
17
+ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
18
+ const __dirname = __cjs_path__.dirname(__filename);
19
+ const require = __cjs_mod__.createRequire(import.meta.url);
20
+
21
+
22
+ function getVariables(vars) {
23
+ try {
24
+ return JSON.parse(vars);
25
+ } catch (error) {
26
+ return {};
27
+ }
28
+ }
29
+ function buildHeaders(req, name, type, config) {
30
+ if (config?.buildHeaders) {
31
+ return config.buildHeaders(req, name, type);
32
+ }
33
+ if (config?.fetchOptions?.headers) {
34
+ return config.fetchOptions.headers;
35
+ }
36
+ return {};
37
+ }
38
+ function createServerMiddleware(graphqlServer, queries, mutations, config) {
39
+ const app = express();
40
+ app.use(express.json());
41
+ const clients = new Map();
42
+ function getClient(endpoint) {
43
+ if (!clients.has(endpoint)) {
44
+ const client = new GraphQLClient(endpoint);
45
+ clients.set(endpoint, client);
46
+ }
47
+ return clients.get(endpoint);
48
+ }
49
+ function getEndpoint(req) {
50
+ if (config?.buildEndpoint) {
51
+ return config.buildEndpoint(req);
52
+ }
53
+ return graphqlServer;
54
+ }
55
+ if (config?.middleware) {
56
+ app.use(config.middleware);
57
+ }
58
+ async function query(req, res) {
59
+ const name = req.query.name;
60
+ if (!name || !queries.has(name)) {
61
+ res.status(404).send();
62
+ return;
63
+ }
64
+ try {
65
+ const headers = buildHeaders(req, name, "query", config);
66
+ const variables = getVariables(req.query.variables);
67
+ const query2 = queries.get(name);
68
+ const endpoint = getEndpoint(req);
69
+ const client = getClient(endpoint);
70
+ const response = await client.rawRequest(query2, variables, headers);
71
+ if (config?.onQueryResponse) {
72
+ return config.onQueryResponse(response, req, res);
73
+ }
74
+ return res.json(response.data);
75
+ } catch (e) {
76
+ if (config?.onQueryError) {
77
+ return config.onQueryError(e, req, res);
78
+ }
79
+ return res.status(500).send();
80
+ }
81
+ }
82
+ async function mutate(req, res) {
83
+ const name = req.query.name;
84
+ if (!name || !mutations.has(name)) {
85
+ res.status(404).send();
86
+ return;
87
+ }
88
+ const mutation = mutations.get(name);
89
+ try {
90
+ const headers = buildHeaders(req, name, "mutation", config);
91
+ const endpoint = getEndpoint(req);
92
+ const client = getClient(endpoint);
93
+ const response = await client.request(mutation, req.body, headers);
94
+ if (config?.onMutationResponse) {
95
+ return config.onMutationResponse(response, req, res);
96
+ }
97
+ return res.json(response);
98
+ } catch (error) {
99
+ if (config?.onMutationError) {
100
+ return config.onMutationError(error, req, res);
101
+ }
102
+ return res.status(500).send();
103
+ }
104
+ }
105
+ app.get("/query", query);
106
+ app.post("/mutate", mutate);
107
+ return app;
108
+ }
109
+
110
+ const fragmentImport = require("@graphql-fragment-import/lib/inline-imports");
111
+ function graphqlImport(path, resolver) {
112
+ return fragmentImport(path, {
113
+ resolveImport(identifier) {
114
+ return resolver(identifier);
115
+ },
116
+ resolveOptions: {
117
+ basedir: "./"
118
+ }
119
+ });
120
+ }
121
+
122
+ const typescriptConfig = {
123
+ exportFragmentSpreadSubTypes: true,
124
+ preResolveTypes: true,
125
+ skipTypeNameForRoot: true
126
+ };
127
+ function pluginLoader(name) {
128
+ if (name === "@graphql-codegen/typescript") {
129
+ return Promise.resolve(PluginTypescript);
130
+ } else if (name === "@graphql-codegen/typescript-operations") {
131
+ return Promise.resolve(PluginTypescriptOperations);
132
+ } else {
133
+ return Promise.resolve(PluginSchemaAst);
134
+ }
135
+ }
136
+ function codegen(graphqlServer, options) {
137
+ const schemaPath = path.resolve(options.schemaOutputPath, "schema.graphql");
138
+ function generateSchema() {
139
+ const schema = options.skipSchemaDownload ? schemaPath : { [graphqlServer]: options.schemaOptions };
140
+ const configSchemaAst = { ...typescriptConfig, sort: true };
141
+ return generate({
142
+ schema,
143
+ pluginLoader,
144
+ generates: {
145
+ [schemaPath]: {
146
+ plugins: [{ "schema-ast": configSchemaAst }],
147
+ config: configSchemaAst
148
+ },
149
+ [path.resolve(options.typesOutputPath, "graphql-schema.d.ts")]: {
150
+ plugins: [{ typescript: typescriptConfig }],
151
+ config: typescriptConfig
152
+ }
153
+ }
154
+ }, true);
155
+ }
156
+ function generateTypes() {
157
+ const config = {
158
+ ...typescriptConfig,
159
+ onlyOperationTypes: true
160
+ };
161
+ return generate({
162
+ schema: schemaPath,
163
+ pluginLoader,
164
+ documents: path.resolve(options.resolvedQueriesPath, "./*.graphql"),
165
+ generates: {
166
+ [path.resolve(options.typesOutputPath, "graphql-operations.d.ts")]: {
167
+ plugins: ["typescript", { "typescript-operations": config }],
168
+ config
169
+ }
170
+ }
171
+ }, true);
172
+ }
173
+ return { generateSchema, generateTypes };
174
+ }
175
+
176
+ const logger = consola.withTag("nuxt-graphql-middleware");
177
+ const PLUGIN_PATH = path.resolve(__dirname, "../dist/plugin.mjs");
178
+ var FileType;
179
+ (function(FileType2) {
180
+ FileType2["Query"] = "query";
181
+ FileType2["Mutation"] = "mutation";
182
+ })(FileType || (FileType = {}));
183
+ function resolveGraphqlFile(file, resolver) {
184
+ return fs.promises.readFile(file).then((buffer) => buffer.toString()).then((source) => graphqlImport(source, resolver));
185
+ }
186
+ function writeSource(dest, type, name, source) {
187
+ const fileName = `${type}.${name}.graphql`;
188
+ const out = path.resolve(dest, fileName);
189
+ return fs.promises.writeFile(out, source);
190
+ }
191
+ function resolveGraphql(files, map, resolver, filesMap, type, outputPath) {
192
+ return Promise.all(Object.keys(files).map((name) => {
193
+ const filePath = files[name];
194
+ const file = resolver(filePath);
195
+ return resolveGraphqlFile(file, resolver).then((source) => {
196
+ map.set(name, source);
197
+ if (outputPath) {
198
+ writeSource(outputPath, type, name, source);
199
+ }
200
+ filesMap.set(file, {
201
+ type,
202
+ name,
203
+ file: filePath
204
+ });
205
+ });
206
+ }));
207
+ }
208
+ const graphqlMiddleware = async function() {
209
+ const resolver = this.nuxt.resolver.resolveAlias;
210
+ const options = this.options;
211
+ const PORT = this.options?.server?.port || 3e3;
212
+ const provided = this.options.graphqlMiddleware || {};
213
+ const config = {
214
+ graphqlServer: provided.graphqlServer || "",
215
+ typescript: {
216
+ enabled: !!provided.typescript?.enabled,
217
+ schemaOptions: provided.typescript?.schemaOptions,
218
+ resolvedQueriesPath: provided.typescript?.resolvedQueriesPath || provided.outputPath || "",
219
+ schemaOutputPath: provided.typescript?.schemaOutputPath || "~/schema",
220
+ typesOutputPath: provided.typescript?.typesOutputPath || "~/types",
221
+ skipSchemaDownload: !!provided.typescript?.skipSchemaDownload
222
+ },
223
+ endpointNamespace: provided.endpointNamespace || "/__graphql_middleware",
224
+ debug: provided.debug || options.dev,
225
+ queries: provided.queries || {},
226
+ mutations: provided.mutations || {},
227
+ outputPath: provided.outputPath || "",
228
+ server: provided.server,
229
+ plugin: {
230
+ enabled: !!provided.plugin?.enabled,
231
+ port: 4e3,
232
+ cacheInBrowser: !!provided.plugin?.cacheInBrowser,
233
+ cacheInServer: !!provided.plugin?.cacheInServer
234
+ }
235
+ };
236
+ if (config.plugin?.enabled) {
237
+ this.addPlugin({
238
+ filename: "graphqlMiddleware.js",
239
+ src: PLUGIN_PATH,
240
+ options: {
241
+ namespace: config.endpointNamespace,
242
+ port: PORT,
243
+ cacheInBrowser: config.plugin?.cacheInBrowser ? "true" : "false",
244
+ cacheInServer: config.plugin?.cacheInServer ? "true" : "false"
245
+ }
246
+ });
247
+ }
248
+ const fileMap = new Map();
249
+ const queries = new Map();
250
+ const mutations = new Map();
251
+ const outputPath = config.outputPath ? resolver(config.outputPath) : "";
252
+ await mkdirp(outputPath);
253
+ const schemaOutputPath = resolver(config.typescript?.schemaOutputPath);
254
+ const typesOutputPath = resolver(config.typescript?.typesOutputPath);
255
+ const { generateSchema, generateTypes } = codegen(config.graphqlServer, {
256
+ resolvedQueriesPath: config.outputPath,
257
+ schemaOptions: config.typescript?.schemaOptions,
258
+ skipSchemaDownload: config.typescript?.skipSchemaDownload,
259
+ schemaOutputPath,
260
+ typesOutputPath
261
+ });
262
+ if (config.typescript?.enabled) {
263
+ if (!outputPath) {
264
+ throw new Error("TypeScript enabled, but no outputPath given.");
265
+ }
266
+ await mkdirp(schemaOutputPath);
267
+ await generateSchema();
268
+ }
269
+ function build() {
270
+ logger.log("Building GraphQL files...");
271
+ return Promise.all([
272
+ resolveGraphql(config.queries, queries, resolver, fileMap, FileType.Query, outputPath),
273
+ resolveGraphql(config.mutations, mutations, resolver, fileMap, FileType.Mutation, outputPath)
274
+ ]).then(() => {
275
+ logger.success("Finished building GraphQL files");
276
+ if (config.typescript?.enabled) {
277
+ return generateTypes().then(() => {
278
+ logger.success("Finished generating GraphQL TypeScript files.");
279
+ });
280
+ }
281
+ });
282
+ }
283
+ function watchFiles() {
284
+ const ignored = ["node_modules", ".nuxt"];
285
+ if (config.outputPath) {
286
+ ignored.push(config.outputPath);
287
+ }
288
+ const filesWatcher = chokidar.watch("./**/*.graphql", {
289
+ ignoreInitial: true,
290
+ ignored
291
+ });
292
+ if (filesWatcher) {
293
+ logger.info("Watching for query changes");
294
+ filesWatcher.on("change", () => {
295
+ build();
296
+ });
297
+ }
298
+ return filesWatcher;
299
+ }
300
+ let watcher;
301
+ if (this.nuxt.options.dev) {
302
+ this.nuxt.hook("build:done", () => {
303
+ watcher = watchFiles();
304
+ });
305
+ this.nuxt.hook("close", () => {
306
+ if (watcher) {
307
+ watcher.close();
308
+ watcher = void 0;
309
+ }
310
+ });
311
+ }
312
+ build().then(() => {
313
+ if (options.debug) {
314
+ logger.info("Available queries and mutations:");
315
+ console.table(Array.from(fileMap.entries()).map(([_key, value]) => value));
316
+ }
317
+ });
318
+ this.addServerMiddleware({
319
+ path: config.endpointNamespace,
320
+ handler: createServerMiddleware(config.graphqlServer, queries, mutations, config.server)
321
+ });
322
+ };
323
+
324
+ export { graphqlMiddleware as default };
@@ -0,0 +1,97 @@
1
+ const IS_DEV = process.env.NODE_ENV === "development";
2
+ function log(action, path, message) {
3
+ if (IS_DEV) {
4
+ console.log(`[API - ${action}] ${message}: ${path}`);
5
+ }
6
+ }
7
+ class GraphqlMiddlewarePlugin {
8
+ constructor(baseURL, headers, useCache, context) {
9
+ this.baseURL = baseURL;
10
+ this.headers = headers || {};
11
+ this.context = context;
12
+ if (useCache) {
13
+ this.cache = new Map();
14
+ }
15
+ }
16
+ getPluginHeaderValue() {
17
+ return {
18
+ "Nuxt-Graphql-Middleware-Route": this.context?.route?.fullPath || ""
19
+ };
20
+ }
21
+ beforeRequest(fn) {
22
+ this.beforeRequestFn = fn;
23
+ }
24
+ query(name, variables, headers = {}) {
25
+ const params = new URLSearchParams({
26
+ name,
27
+ variables: JSON.stringify(variables || {})
28
+ });
29
+ const url = this.baseURL + "/query?" + params.toString();
30
+ if (this.cache?.has(url)) {
31
+ log("query", url, "Loading from cache");
32
+ return Promise.resolve(this.cache.get(url));
33
+ }
34
+ log("query", url, "Fetching");
35
+ let fetchOptions = {
36
+ method: "GET",
37
+ credentials: "include",
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ ...headers,
41
+ ...this.headers,
42
+ ...this.getPluginHeaderValue()
43
+ }
44
+ };
45
+ if (this.beforeRequestFn) {
46
+ fetchOptions = this.beforeRequestFn(this.context, fetchOptions);
47
+ }
48
+ return fetch(url, fetchOptions).then((response) => {
49
+ if (response.ok) {
50
+ return response.json();
51
+ }
52
+ throw new Error("Server Error");
53
+ }).then((data) => {
54
+ if (this.cache && this.cache.size > 30) {
55
+ const key = this.cache.keys().next().value;
56
+ this.cache.delete(key);
57
+ }
58
+ this.cache?.set(url, data);
59
+ return data;
60
+ });
61
+ }
62
+ mutate(name, variables, headers = {}) {
63
+ const params = new URLSearchParams({
64
+ name
65
+ });
66
+ let fetchOptions = {
67
+ method: "POST",
68
+ credentials: "include",
69
+ headers: {
70
+ "Content-Type": "application/json",
71
+ ...headers,
72
+ ...this.headers,
73
+ ...this.getPluginHeaderValue()
74
+ },
75
+ body: JSON.stringify(variables)
76
+ };
77
+ if (this.beforeRequestFn) {
78
+ fetchOptions = this.beforeRequestFn(this.context, fetchOptions);
79
+ }
80
+ return fetch(this.baseURL + "/mutate?" + params.toString(), fetchOptions).then((response) => response.json());
81
+ }
82
+ }
83
+ const graphqlMiddlewarePlugin = (context, inject) => {
84
+ const namespace = "<%= options.namespace || '' %>";
85
+ const port = process?.env?.NUXT_PORT || "<%= options.port %>";
86
+ const cacheInBrowser = false;
87
+ const cacheInServer = false;
88
+ let baseURL = namespace;
89
+ if (process.server) {
90
+ baseURL = "http://localhost:" + port + namespace;
91
+ }
92
+ const useCache = process.server && cacheInServer || process.client && cacheInBrowser;
93
+ const plugin = new GraphqlMiddlewarePlugin(baseURL, context.req?.headers, useCache, context);
94
+ inject("graphql", plugin);
95
+ };
96
+
97
+ export { GraphqlMiddlewarePlugin, graphqlMiddlewarePlugin as default };
package/module.cjs ADDED
@@ -0,0 +1,6 @@
1
+ // CommonJS proxy to bypass jiti transforms from nuxt 2 and using native ESM
2
+ module.exports = function(...args) {
3
+ return import('./dist/module.mjs').then(m => m.default.call(this, ...args))
4
+ }
5
+
6
+ module.exports.meta = require('./package.json')
package/package.json CHANGED
@@ -1,51 +1,64 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
- "version": "1.2.1",
3
+ "version": "2.0.3",
4
4
  "description": "Module to perform GraphQL requests as a server middleware.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dulnan/nuxt-graphql-middleware.git"
8
+ },
5
9
  "license": "MIT",
6
10
  "author": {
7
11
  "name": "Jan Hug",
8
- "url": "https://dulnan.net",
9
- "email": "me@dulnan.net"
12
+ "email": "me@dulnan.net",
13
+ "url": "https://dulnan.net"
10
14
  },
11
- "scripts": {
12
- "build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json"
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/module.mjs",
18
+ "require": "./module.cjs"
19
+ },
20
+ "./dist/*": "./dist/*"
13
21
  },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/dulnan/nuxt-graphql-middleware.git"
17
- },
18
- "main": "./lib/cjs/index.js",
19
- "module": "./lib/esm/index.js",
20
- "types": "./types.d.ts",
22
+ "main": "./module.cjs",
23
+ "types": "./types/index.d.ts",
21
24
  "files": [
22
- "lib/",
23
- "types.d.ts"
25
+ "types/*",
26
+ "module.cjs",
27
+ "dist/*.js",
28
+ "dist/*.mjs",
29
+ "dist/*.d.ts"
24
30
  ],
31
+ "scripts": {
32
+ "build": "unbuild && npm run generate-types",
33
+ "dev": "unbuild --stub=true",
34
+ "generate-types": "tsc -p tsconfig.json --emitDeclarationOnly",
35
+ "plain-ts": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json"
36
+ },
25
37
  "dependencies": {
26
- "@graphql-codegen/cli": "^1.20.1",
27
- "@graphql-codegen/schema-ast": "^1.18.1",
28
- "@graphql-codegen/typescript": "^1.21.0",
29
- "@graphql-codegen/typescript-operations": "^1.17.14",
30
- "@graphql-fragment-import/lib": "^1.1.1",
38
+ "@graphql-codegen/cli": "^2.3.0",
39
+ "@graphql-codegen/schema-ast": "^2.4.0",
40
+ "@graphql-codegen/typescript": "^2.4.1",
41
+ "@graphql-codegen/typescript-operations": "^2.2.1",
42
+ "@graphql-fragment-import/lib": "^1.2.0",
31
43
  "express": "^4.17.1",
32
- "graphql": "^15.5.0",
33
- "graphql-request": "^3.4.0"
44
+ "graphql": "^15.6.0",
45
+ "graphql-request": "^3.6.1"
34
46
  },
35
47
  "devDependencies": {
36
- "@nuxt/types": "^2.14.12",
48
+ "@nuxt/types": "^2.15.8",
37
49
  "@nuxtjs/eslint-config-typescript": "latest",
38
- "@types/mkdirp": "^1.0.1",
39
- "@types/node": "^14.14.22",
40
- "consola": "^2.15.0",
50
+ "@types/mkdirp": "^1.0.2",
51
+ "@types/node": "^16.11.9",
52
+ "consola": "^2.15.3",
41
53
  "eslint": "latest",
42
54
  "eslint-config-prettier": "latest",
43
55
  "eslint-plugin-prettier": "latest",
44
- "globby": "^11.0.2",
45
56
  "mkdirp": "^1.0.4",
46
- "nuxt": "^2.14.12",
47
- "prettier": "^2.2.1",
48
- "typescript": "^4.1.3",
49
- "vue": "^2.6.12"
57
+ "mkdist": "latest",
58
+ "nuxt": "^2.15.8",
59
+ "prettier": "^2.4.1",
60
+ "typescript": "^4.5.2",
61
+ "unbuild": "^0.5.13",
62
+ "vue": "^2.6.14"
50
63
  }
51
64
  }
@@ -1,11 +1,5 @@
1
- import Vue from 'vue'
2
- import '@nuxt/types'
3
- import { GraphqlMiddlewarePlugin } from './lib/types/plugin'
4
- import { GraphqlMiddlewareConfig } from './lib/types/module'
5
-
6
- declare module '*.vue' {
7
- export default Vue
8
- }
1
+ import { GraphqlMiddlewarePlugin } from '../dist/types/templates/plugin'
2
+ import { GraphqlMiddlewareConfig } from '../dist/types/module'
9
3
 
10
4
  declare module 'vue/types/vue' {
11
5
  interface Vue {
@@ -14,7 +8,6 @@ declare module 'vue/types/vue' {
14
8
  }
15
9
 
16
10
  declare module 'vuex/types/index' {
17
- // @ts-ignore
18
11
  interface Store<S> {
19
12
  readonly $graphql: GraphqlMiddlewarePlugin
20
13
  }
package/lib/cjs/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = void 0;
4
- var module_1 = require("./module");
5
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return module_1.graphqlMiddleware; } });
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const path_1 = __importDefault(require("path"));
26
- const cli_1 = require("@graphql-codegen/cli");
27
- const PluginTypescript = __importStar(require("@graphql-codegen/typescript"));
28
- const PluginTypescriptOperations = __importStar(require("@graphql-codegen/typescript-operations"));
29
- const PluginSchemaAst = __importStar(require("@graphql-codegen/schema-ast"));
30
- const typescriptConfig = {
31
- exportFragmentSpreadSubTypes: true,
32
- preResolveTypes: true,
33
- skipTypeNameForRoot: true,
34
- };
35
- function pluginLoader(name) {
36
- if (name === '@graphql-codegen/typescript') {
37
- return Promise.resolve(PluginTypescript);
38
- }
39
- else if (name === '@graphql-codegen/typescript-operations') {
40
- return Promise.resolve(PluginTypescriptOperations);
41
- }
42
- else {
43
- return Promise.resolve(PluginSchemaAst);
44
- }
45
- }
46
- function default_1(graphqlServer, options) {
47
- const schemaPath = path_1.default.resolve(options.schemaOutputPath, 'schema.graphql');
48
- function generateSchema() {
49
- const schema = options.skipSchemaDownload
50
- ? schemaPath
51
- : { [graphqlServer]: options.schemaOptions };
52
- const configSchemaAst = Object.assign(Object.assign({}, typescriptConfig), { sort: true });
53
- return cli_1.generate({
54
- schema,
55
- pluginLoader,
56
- generates: {
57
- [schemaPath]: {
58
- plugins: [{ 'schema-ast': configSchemaAst }],
59
- config: configSchemaAst,
60
- },
61
- [path_1.default.resolve(options.typesOutputPath, 'graphql-schema.d.ts')]: {
62
- plugins: [{ typescript: typescriptConfig }],
63
- config: typescriptConfig,
64
- },
65
- },
66
- }, true);
67
- }
68
- function generateTypes() {
69
- const config = Object.assign(Object.assign({}, typescriptConfig), { onlyOperationTypes: true });
70
- return cli_1.generate({
71
- schema: schemaPath,
72
- pluginLoader,
73
- documents: path_1.default.resolve(options.resolvedQueriesPath, './*.graphql'),
74
- generates: {
75
- [path_1.default.resolve(options.typesOutputPath, 'graphql-operations.d.ts')]: {
76
- plugins: ['typescript', { 'typescript-operations': config }],
77
- config,
78
- },
79
- },
80
- }, true);
81
- }
82
- return { generateSchema, generateTypes };
83
- }
84
- exports.default = default_1;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fragmentImport = require('@graphql-fragment-import/lib/inline-imports');
4
- function default_1(path, resolver) {
5
- return fragmentImport(path, {
6
- resolveImport(identifier) {
7
- return resolver(identifier);
8
- },
9
- resolveOptions: {
10
- basedir: './',
11
- },
12
- });
13
- }
14
- exports.default = default_1;