nuxt-graphql-middleware 1.2.2 → 2.0.4
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/dist/module.mjs +324 -0
- package/dist/plugin.mjs +97 -0
- package/{lib/types/module → dist/types}/codegen.d.ts +0 -0
- package/dist/types/codegen.d.ts.map +1 -0
- package/{lib/types/module → dist/types}/graphqlImport.d.ts +0 -0
- package/dist/types/graphqlImport.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{lib/types/module/index.d.ts → dist/types/module.d.ts} +5 -4
- package/dist/types/module.d.ts.map +1 -0
- package/{lib/types/serverMiddleware/index.d.ts → dist/types/serverMiddleware.d.ts} +1 -1
- package/dist/types/serverMiddleware.d.ts.map +1 -0
- package/{lib/types/plugin/index.d.ts → dist/types/templates/plugin.d.ts} +2 -1
- package/dist/types/templates/plugin.d.ts.map +1 -0
- package/module.cjs +6 -0
- package/package.json +44 -30
- package/{types.d.ts → types/index.d.ts} +8 -9
- package/lib/cjs/index.js +0 -5
- package/lib/cjs/module/codegen.js +0 -84
- package/lib/cjs/module/graphqlImport.js +0 -14
- package/lib/cjs/module/index.js +0 -177
- package/lib/cjs/plugin/index.js +0 -95
- package/lib/cjs/serverMiddleware/index.js +0 -113
- package/lib/esm/index.js +0 -1
- package/lib/esm/module/codegen.js +0 -59
- package/lib/esm/module/graphqlImport.js +0 -11
- package/lib/esm/module/index.js +0 -170
- package/lib/esm/plugin/index.js +0 -91
- package/lib/esm/serverMiddleware/index.js +0 -107
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/module/codegen.d.ts.map +0 -1
- package/lib/types/module/graphqlImport.d.ts.map +0 -1
- package/lib/types/module/index.d.ts.map +0 -1
- package/lib/types/plugin/index.d.ts.map +0 -1
- package/lib/types/serverMiddleware/index.d.ts.map +0 -1
package/dist/module.mjs
ADDED
|
@@ -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 };
|
package/dist/plugin.mjs
ADDED
|
@@ -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 };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/codegen.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,8BAA8B;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,GAAG,CAAA;CACnB;AAED,MAAM,CAAC,OAAO,WACZ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,8BAA8B;;;EAmDxC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlImport.d.ts","sourceRoot":"","sources":["../../src/graphqlImport.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,WAAW,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OASnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module } from '@nuxt/types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { GraphqlMiddlewarePluginConfig } from './templates/plugin';
|
|
3
|
+
import { GraphqlServerMiddlewareConfig } from './serverMiddleware';
|
|
4
4
|
import { GraphqlMiddlewareCodegenConfig } from './codegen';
|
|
5
5
|
export interface GraphqlMiddlewareConfig {
|
|
6
6
|
graphqlServer: string;
|
|
@@ -13,5 +13,6 @@ export interface GraphqlMiddlewareConfig {
|
|
|
13
13
|
plugin?: GraphqlMiddlewarePluginConfig;
|
|
14
14
|
server?: GraphqlServerMiddlewareConfig;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
declare const graphqlMiddleware: Module;
|
|
17
|
+
export default graphqlMiddleware;
|
|
18
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAyB,EACvB,6BAA6B,EAC9B,MAAM,oBAAoB,CAAA;AAE3B,OAAgB,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAA;AAMnE,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,8BAA8B,CAAA;IAC3C,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,6BAA6B,CAAA;IACtC,MAAM,CAAC,EAAE,6BAA6B,CAAA;CACvC;AAiED,QAAA,MAAM,iBAAiB,EAAE,MAgKxB,CAAA;AAED,eAAe,iBAAiB,CAAA"}
|
|
@@ -10,4 +10,4 @@ export interface GraphqlServerMiddlewareConfig {
|
|
|
10
10
|
onMutationError?: any;
|
|
11
11
|
}
|
|
12
12
|
export default function createServerMiddleware(graphqlServer: string, queries: Map<string, any>, mutations: Map<string, any>, config?: GraphqlServerMiddlewareConfig): import("express-serve-static-core").Express;
|
|
13
|
-
//# sourceMappingURL=
|
|
13
|
+
//# sourceMappingURL=serverMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverMiddleware.d.ts","sourceRoot":"","sources":["../../src/serverMiddleware.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAA;AAcpE,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,cAAc,CAAA;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAA;IAClB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAA;IAChE,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IACxC,eAAe,CAAC,EAAE,GAAG,CAAA;IACrB,YAAY,CAAC,EAAE,GAAG,CAAA;IAClB,kBAAkB,CAAC,EAAE,GAAG,CAAA;IACxB,eAAe,CAAC,EAAE,GAAG,CAAA;CACtB;AAkBD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,MAAM,CAAC,EAAE,6BAA6B,+CA0FvC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context, Plugin } from '@nuxt/types';
|
|
2
2
|
export interface GraphqlMiddlewarePluginConfig {
|
|
3
3
|
enabled?: boolean;
|
|
4
|
+
port?: number;
|
|
4
5
|
cacheInBrowser?: boolean;
|
|
5
6
|
cacheInServer?: boolean;
|
|
6
7
|
}
|
|
@@ -20,4 +21,4 @@ export declare class GraphqlMiddlewarePlugin {
|
|
|
20
21
|
}
|
|
21
22
|
declare const graphqlMiddlewarePlugin: Plugin;
|
|
22
23
|
export default graphqlMiddlewarePlugin;
|
|
23
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/templates/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAW7C,MAAM,WAAW,6BAA6B;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,qBAAa,uBAAuB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,GAAG,CAAA;IACZ,eAAe,EAAE,QAAQ,GAAG,SAAS,CAAA;IACrC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxB,OAAO,EAAE,GAAG,CAAA;gBAGV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,GAAG,EACZ,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,OAAO;IAUlB,oBAAoB;;;IAMpB,aAAa,CAAC,EAAE,EAAE,QAAQ;IAO1B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ;IAgDtD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ;CAuBxD;AAED,QAAA,MAAM,uBAAuB,EAAE,MAyB9B,CAAA;AAED,eAAe,uBAAuB,CAAA"}
|
package/module.cjs
ADDED
package/package.json
CHANGED
|
@@ -1,51 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-graphql-middleware",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.4",
|
|
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
|
-
"
|
|
9
|
-
"
|
|
12
|
+
"email": "me@dulnan.net",
|
|
13
|
+
"url": "https://dulnan.net"
|
|
10
14
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/module.mjs",
|
|
18
|
+
"require": "./module.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./dist/*": "./dist/*"
|
|
13
21
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
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
|
-
"
|
|
23
|
-
"
|
|
25
|
+
"types/*",
|
|
26
|
+
"module.cjs",
|
|
27
|
+
"dist/*.js",
|
|
28
|
+
"dist/*.mjs",
|
|
29
|
+
"dist/*.d.ts",
|
|
30
|
+
"dist/types/*"
|
|
24
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "unbuild && npm run generate-types",
|
|
34
|
+
"dev": "unbuild --stub=true",
|
|
35
|
+
"generate-types": "tsc -p tsconfig.json --emitDeclarationOnly",
|
|
36
|
+
"plain-ts": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json"
|
|
37
|
+
},
|
|
25
38
|
"dependencies": {
|
|
26
|
-
"@graphql-codegen/cli": "^
|
|
27
|
-
"@graphql-codegen/schema-ast": "^
|
|
28
|
-
"@graphql-codegen/typescript": "^
|
|
29
|
-
"@graphql-codegen/typescript-operations": "^
|
|
30
|
-
"@graphql-fragment-import/lib": "^1.
|
|
39
|
+
"@graphql-codegen/cli": "^2.3.0",
|
|
40
|
+
"@graphql-codegen/schema-ast": "^2.4.0",
|
|
41
|
+
"@graphql-codegen/typescript": "^2.4.1",
|
|
42
|
+
"@graphql-codegen/typescript-operations": "^2.2.1",
|
|
43
|
+
"@graphql-fragment-import/lib": "^1.2.0",
|
|
31
44
|
"express": "^4.17.1",
|
|
32
|
-
"graphql": "^15.
|
|
33
|
-
"graphql-request": "^3.
|
|
45
|
+
"graphql": "^15.6.0",
|
|
46
|
+
"graphql-request": "^3.6.1"
|
|
34
47
|
},
|
|
35
48
|
"devDependencies": {
|
|
36
|
-
"@nuxt/types": "^2.
|
|
49
|
+
"@nuxt/types": "^2.15.8",
|
|
37
50
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
38
|
-
"@types/mkdirp": "^1.0.
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"consola": "^2.15.
|
|
51
|
+
"@types/mkdirp": "^1.0.2",
|
|
52
|
+
"@types/node": "^16.11.9",
|
|
53
|
+
"consola": "^2.15.3",
|
|
41
54
|
"eslint": "latest",
|
|
42
55
|
"eslint-config-prettier": "latest",
|
|
43
56
|
"eslint-plugin-prettier": "latest",
|
|
44
|
-
"globby": "^11.0.2",
|
|
45
57
|
"mkdirp": "^1.0.4",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
58
|
+
"mkdist": "latest",
|
|
59
|
+
"nuxt": "^2.15.8",
|
|
60
|
+
"prettier": "^2.4.1",
|
|
61
|
+
"typescript": "^4.5.2",
|
|
62
|
+
"unbuild": "^0.5.13",
|
|
63
|
+
"vue": "^2.6.14"
|
|
50
64
|
}
|
|
51
65
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import '
|
|
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
|
}
|
|
@@ -31,3 +24,9 @@ declare module '@nuxt/types' {
|
|
|
31
24
|
graphqlMiddleware?: GraphqlMiddlewareConfig
|
|
32
25
|
}
|
|
33
26
|
}
|
|
27
|
+
|
|
28
|
+
declare module '@nuxt/schema' {
|
|
29
|
+
interface NuxtConfig {
|
|
30
|
+
graphqlMiddleware?: GraphqlMiddlewareConfig
|
|
31
|
+
}
|
|
32
|
+
}
|
package/lib/cjs/index.js
DELETED