nuxt-graphql-middleware 2.0.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.
- package/dist/module.mjs +324 -0
- package/dist/{runtime/middlewarePlugin.js → plugin.mjs} +16 -1
- package/module.cjs +6 -0
- package/package.json +27 -16
- package/types/index.d.ts +26 -0
- package/dist/module.js +0 -7348
- package/dist/runtime/middlewarePlugin.d.ts +0 -26
- package/dist/types.d.ts +0 -82
- package/templates/plugin.js +0 -28
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Context } from '@nuxt/types';
|
|
2
|
-
export interface GraphqlMiddlewarePluginConfig {
|
|
3
|
-
enabled?: boolean;
|
|
4
|
-
cacheInBrowser?: boolean;
|
|
5
|
-
cacheInServer?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class GraphqlMiddlewarePlugin {
|
|
8
|
-
baseURL: string;
|
|
9
|
-
headers: any;
|
|
10
|
-
beforeRequestFn: Function | undefined;
|
|
11
|
-
cache?: Map<string, any>;
|
|
12
|
-
context: any;
|
|
13
|
-
constructor(baseURL: string, headers: any, useCache: boolean, context: Context);
|
|
14
|
-
getPluginHeaderValue(): {
|
|
15
|
-
'Nuxt-Graphql-Middleware-Route': any;
|
|
16
|
-
};
|
|
17
|
-
beforeRequest(fn: Function): void;
|
|
18
|
-
/**
|
|
19
|
-
* Perform a GraphQL query via the middleware.
|
|
20
|
-
*/
|
|
21
|
-
query(name: string, variables?: any, headers?: any): Promise<any>;
|
|
22
|
-
/**
|
|
23
|
-
* Perform a GraphQL mutation via the middleware.
|
|
24
|
-
*/
|
|
25
|
-
mutate(name: string, variables?: any, headers?: any): Promise<any>;
|
|
26
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Context } from '@nuxt/types';
|
|
2
|
-
import { RequestHandler, Request } from 'express';
|
|
3
|
-
|
|
4
|
-
interface GraphqlMiddlewarePluginConfig {
|
|
5
|
-
enabled?: boolean;
|
|
6
|
-
cacheInBrowser?: boolean;
|
|
7
|
-
cacheInServer?: boolean;
|
|
8
|
-
}
|
|
9
|
-
declare class GraphqlMiddlewarePlugin {
|
|
10
|
-
baseURL: string;
|
|
11
|
-
headers: any;
|
|
12
|
-
beforeRequestFn: Function | undefined;
|
|
13
|
-
cache?: Map<string, any>;
|
|
14
|
-
context: any;
|
|
15
|
-
constructor(baseURL: string, headers: any, useCache: boolean, context: Context);
|
|
16
|
-
getPluginHeaderValue(): {
|
|
17
|
-
'Nuxt-Graphql-Middleware-Route': any;
|
|
18
|
-
};
|
|
19
|
-
beforeRequest(fn: Function): void;
|
|
20
|
-
/**
|
|
21
|
-
* Perform a GraphQL query via the middleware.
|
|
22
|
-
*/
|
|
23
|
-
query(name: string, variables?: any, headers?: any): Promise<any>;
|
|
24
|
-
/**
|
|
25
|
-
* Perform a GraphQL mutation via the middleware.
|
|
26
|
-
*/
|
|
27
|
-
mutate(name: string, variables?: any, headers?: any): Promise<any>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface GraphqlServerMiddlewareConfig {
|
|
31
|
-
middleware?: RequestHandler;
|
|
32
|
-
fetchOptions?: any;
|
|
33
|
-
buildHeaders?: (req: Request, name: string, type: string) => any;
|
|
34
|
-
buildEndpoint?: (req: Request) => string;
|
|
35
|
-
onQueryResponse?: any;
|
|
36
|
-
onQueryError?: any;
|
|
37
|
-
onMutationResponse?: any;
|
|
38
|
-
onMutationError?: any;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface GraphqlMiddlewareCodegenConfig {
|
|
42
|
-
enabled?: boolean;
|
|
43
|
-
skipSchemaDownload?: boolean;
|
|
44
|
-
resolvedQueriesPath: string;
|
|
45
|
-
schemaOutputPath: string;
|
|
46
|
-
typesOutputPath: string;
|
|
47
|
-
schemaOptions: any;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface GraphqlMiddlewareConfig {
|
|
51
|
-
graphqlServer: string;
|
|
52
|
-
typescript?: GraphqlMiddlewareCodegenConfig;
|
|
53
|
-
endpointNamespace?: string;
|
|
54
|
-
debug: boolean;
|
|
55
|
-
queries: Record<string, string>;
|
|
56
|
-
mutations: Record<string, string>;
|
|
57
|
-
outputPath: string;
|
|
58
|
-
plugin?: GraphqlMiddlewarePluginConfig;
|
|
59
|
-
server?: GraphqlServerMiddlewareConfig;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare module 'vue/types/vue' {
|
|
63
|
-
interface Vue {
|
|
64
|
-
readonly $graphql: GraphqlMiddlewarePlugin;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
declare module 'vuex/types/index' {
|
|
68
|
-
interface Store<S> {
|
|
69
|
-
readonly $graphql: GraphqlMiddlewarePlugin;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
declare module '@nuxt/types' {
|
|
73
|
-
interface NuxtAppOptions {
|
|
74
|
-
readonly $graphql: GraphqlMiddlewarePlugin;
|
|
75
|
-
}
|
|
76
|
-
interface Context {
|
|
77
|
-
readonly $graphql: GraphqlMiddlewarePlugin;
|
|
78
|
-
}
|
|
79
|
-
interface Configuration {
|
|
80
|
-
graphqlMiddleware?: GraphqlMiddlewareConfig;
|
|
81
|
-
}
|
|
82
|
-
}
|
package/templates/plugin.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { GraphqlMiddlewarePlugin } from '~nuxtgraphqlmiddleware/middlewarePlugin'
|
|
2
|
-
|
|
3
|
-
export default function graphqlMiddlewarePlugin(context, inject) {
|
|
4
|
-
const namespace = "<%= options.namespace || '' %>"
|
|
5
|
-
// TODO: Get the port somehow from the context on SSR.
|
|
6
|
-
const port = process?.env?.NUXT_PORT || '<%= options.port %>'
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
const cacheInBrowser = "<%= options.cacheInBrowser || '' %>" === 'true'
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const cacheInServer = "<%= options.cacheInServer || '' %>" === 'true'
|
|
11
|
-
|
|
12
|
-
let baseURL = namespace
|
|
13
|
-
if (process.server) {
|
|
14
|
-
baseURL = 'http://localhost:' + port + namespace
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const useCache =
|
|
18
|
-
(process.server && cacheInServer) || (process.client && cacheInBrowser)
|
|
19
|
-
|
|
20
|
-
const plugin = new GraphqlMiddlewarePlugin(
|
|
21
|
-
baseURL,
|
|
22
|
-
context.req?.headers,
|
|
23
|
-
useCache,
|
|
24
|
-
context
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
inject('graphql', plugin)
|
|
28
|
-
}
|