nuxt-graphql-middleware 2.1.2 → 2.2.0
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
CHANGED
|
@@ -41,7 +41,7 @@ function createServerMiddleware(graphqlServer, queries, mutations, config) {
|
|
|
41
41
|
const clients = new Map();
|
|
42
42
|
function getClient(endpoint) {
|
|
43
43
|
if (!clients.has(endpoint)) {
|
|
44
|
-
const client = new GraphQLClient(endpoint);
|
|
44
|
+
const client = new GraphQLClient(endpoint, config?.graphqlClientOptions);
|
|
45
45
|
clients.set(endpoint, client);
|
|
46
46
|
}
|
|
47
47
|
return clients.get(endpoint);
|
|
@@ -90,7 +90,7 @@ function createServerMiddleware(graphqlServer, queries, mutations, config) {
|
|
|
90
90
|
const headers = buildHeaders(req, name, "mutation", config);
|
|
91
91
|
const endpoint = getEndpoint(req);
|
|
92
92
|
const client = getClient(endpoint);
|
|
93
|
-
const response = await client.
|
|
93
|
+
const response = await client.rawRequest(mutation, req.body, headers);
|
|
94
94
|
if (config?.onMutationResponse) {
|
|
95
95
|
return config.onMutationResponse(response, req, res);
|
|
96
96
|
}
|
package/dist/plugin.mjs
CHANGED
|
@@ -73,7 +73,7 @@ class GraphqlMiddlewarePlugin {
|
|
|
73
73
|
const params = new URLSearchParams({
|
|
74
74
|
name
|
|
75
75
|
});
|
|
76
|
-
let
|
|
76
|
+
let fetchOptions = {
|
|
77
77
|
method: "POST",
|
|
78
78
|
credentials: "include",
|
|
79
79
|
headers: {
|
|
@@ -84,9 +84,10 @@ class GraphqlMiddlewarePlugin {
|
|
|
84
84
|
},
|
|
85
85
|
body: JSON.stringify(variables)
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
87
|
+
if (this.beforeRequestFn) {
|
|
88
|
+
fetchOptions = this.beforeRequestFn(this.context, fetchOptions);
|
|
89
|
+
}
|
|
90
|
+
return fetch(this.baseURL + "/mutate?" + params.toString(), fetchOptions).then((response) => response.json());
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
const graphqlMiddlewarePlugin = (context, inject) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, RequestHandler } from 'express';
|
|
2
|
+
import * as Dom from 'graphql-request/dist/types.dom';
|
|
2
3
|
export interface GraphqlServerMiddlewareConfig {
|
|
3
4
|
middleware?: RequestHandler;
|
|
4
5
|
fetchOptions?: any;
|
|
@@ -8,6 +9,7 @@ export interface GraphqlServerMiddlewareConfig {
|
|
|
8
9
|
onQueryError?: any;
|
|
9
10
|
onMutationResponse?: any;
|
|
10
11
|
onMutationError?: any;
|
|
12
|
+
graphqlClientOptions?: Dom.RequestInit;
|
|
11
13
|
}
|
|
12
14
|
export default function createServerMiddleware(graphqlServer: string, queries: Map<string, any>, mutations: Map<string, any>, config?: GraphqlServerMiddlewareConfig): import("express-serve-static-core").Express;
|
|
13
15
|
//# sourceMappingURL=serverMiddleware.d.ts.map
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"serverMiddleware.d.ts","sourceRoot":"","sources":["../../src/serverMiddleware.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAA;AAEpE,OAAO,KAAK,GAAG,MAAM,gCAAgC,CAAA;AAarD,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;IAIrB,oBAAoB,CAAC,EAAE,GAAG,CAAC,WAAW,CAAA;CACvC;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"}
|