nuxt-graphql-middleware 5.0.0-alpha.9 → 5.1.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/README.md +101 -19
- package/dist/client/200.html +8 -8
- package/dist/client/404.html +8 -8
- package/dist/client/_nuxt/{C9pb_2rp.js → CPiV13Ng.js} +2 -2
- package/dist/client/_nuxt/CQCiRbEL.js +1 -0
- package/dist/client/_nuxt/CYI2eNUl.js +1 -0
- package/dist/client/_nuxt/UAIVpYSK.js +25 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/48332277-c4ad-4d6a-8f09-7a58a109c32d.json +1 -0
- package/dist/client/_nuxt/error-404.Bbd2eCoc.css +1 -0
- package/dist/client/_nuxt/error-500.Cd2cwFc3.css +1 -0
- package/dist/client/_nuxt/{BLvMh1Ga.js → u1b7LyOw.js} +1 -1
- package/dist/client/index.html +8 -8
- package/dist/client-options.d.mts +6 -0
- package/dist/client-options.mjs +5 -0
- package/dist/module.d.mts +63 -181
- package/dist/module.json +4 -4
- package/dist/module.mjs +435 -92
- package/dist/runtime/components/CodeFrame.vue +19 -28
- package/dist/runtime/components/CodeFrame.vue.d.ts +7 -0
- package/dist/runtime/components/DevModeOverlay.vue +25 -33
- package/dist/runtime/components/DevModeOverlay.vue.d.ts +3 -0
- package/dist/runtime/components/ErrorExtensions.vue +9 -11
- package/dist/runtime/components/ErrorExtensions.vue.d.ts +5 -0
- package/dist/runtime/components/ErrorGroup.vue +28 -39
- package/dist/runtime/components/ErrorGroup.vue.d.ts +9 -0
- package/dist/runtime/composables/nuxtApp.d.ts +30 -2
- package/dist/runtime/composables/nuxtApp.js +66 -24
- package/dist/runtime/composables/useAsyncGraphqlQuery.js +28 -25
- package/dist/runtime/composables/useGraphqlMutation.d.ts +1 -1
- package/dist/runtime/composables/useGraphqlMutation.js +11 -16
- package/dist/runtime/composables/useGraphqlQuery.d.ts +1 -1
- package/dist/runtime/composables/useGraphqlQuery.js +7 -25
- package/dist/runtime/composables/useGraphqlUploadMutation.js +1 -1
- package/dist/runtime/helpers/ClientCache.d.ts +1 -0
- package/dist/runtime/helpers/ClientCache.js +12 -0
- package/dist/runtime/helpers/composables.d.ts +8 -0
- package/dist/runtime/helpers/composables.js +27 -0
- package/dist/runtime/helpers/index.d.ts +0 -4
- package/dist/runtime/helpers/index.js +0 -13
- package/dist/runtime/helpers/queryEncoding.d.ts +11 -0
- package/dist/runtime/helpers/queryEncoding.js +89 -0
- package/dist/runtime/plugins/devMode.js +2 -1
- package/dist/runtime/server/api/mutation.js +2 -1
- package/dist/runtime/server/api/query.js +7 -8
- package/dist/runtime/server/utils/doGraphqlRequest.js +5 -4
- package/dist/runtime/server/utils/useGraphqlQuery.js +2 -2
- package/dist/runtime/settings/index.d.ts +1 -0
- package/dist/runtime/settings/index.js +1 -0
- package/dist/runtime/types.d.ts +2 -2
- package/dist/server-options.d.mts +8 -0
- package/dist/server-options.mjs +5 -0
- package/dist/shared/nuxt-graphql-middleware.-BeiPV4H.d.mts +566 -0
- package/dist/types.d.mts +1 -7
- package/dist/utils.d.mts +15 -0
- package/dist/utils.mjs +18 -0
- package/package.json +36 -32
- package/dist/client/_nuxt/CBwfSTyQ.js +0 -1
- package/dist/client/_nuxt/CPyoLiCY.js +0 -1
- package/dist/client/_nuxt/VpkRx2_e.js +0 -25
- package/dist/client/_nuxt/builds/meta/826a43da-d42c-4fbf-8dfd-2572141eaf8f.json +0 -1
- package/dist/client/_nuxt/error-404.BJkSn6RI.css +0 -1
- package/dist/client/_nuxt/error-500.TOCKLquH.css +0 -1
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -210
- package/dist/runtime/clientOptions/index.d.ts +0 -2
- package/dist/runtime/clientOptions/index.js +0 -3
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +0 -4
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.js +0 -3
- package/dist/runtime/serverOptions/index.d.ts +0 -2
- package/dist/runtime/serverOptions/index.js +0 -2
- package/dist/types.d.ts +0 -7
|
@@ -23,39 +23,30 @@
|
|
|
23
23
|
</div>
|
|
24
24
|
</template>
|
|
25
25
|
|
|
26
|
-
<script setup
|
|
27
|
-
import { computed } from
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const before = 20
|
|
36
|
-
const after = 20
|
|
37
|
-
|
|
26
|
+
<script setup>
|
|
27
|
+
import { computed } from "#imports";
|
|
28
|
+
const props = defineProps({
|
|
29
|
+
source: { type: String, required: true },
|
|
30
|
+
line: { type: Number, required: true },
|
|
31
|
+
column: { type: Number, required: true }
|
|
32
|
+
});
|
|
33
|
+
const before = 20;
|
|
34
|
+
const after = 20;
|
|
38
35
|
const lines = computed(() => {
|
|
39
|
-
const fullLines = props.source.split(
|
|
40
|
-
const indexStart = Math.max(props.line - before - 1, 0)
|
|
41
|
-
const indexEnd = Math.min(props.line + after, fullLines.length)
|
|
42
|
-
|
|
43
|
-
// Take only the lines we care about
|
|
44
|
-
const sliced = fullLines.slice(indexStart, indexEnd)
|
|
45
|
-
|
|
46
|
-
// Remove trailing empty lines
|
|
36
|
+
const fullLines = props.source.split("\n");
|
|
37
|
+
const indexStart = Math.max(props.line - before - 1, 0);
|
|
38
|
+
const indexEnd = Math.min(props.line + after, fullLines.length);
|
|
39
|
+
const sliced = fullLines.slice(indexStart, indexEnd);
|
|
47
40
|
while (sliced.length && !sliced[sliced.length - 1]?.trim()) {
|
|
48
|
-
sliced.pop()
|
|
41
|
+
sliced.pop();
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
// Map to your final structure
|
|
52
43
|
return sliced.map((code, i) => {
|
|
53
|
-
const lineNumber = indexStart + i + 1
|
|
44
|
+
const lineNumber = indexStart + i + 1;
|
|
54
45
|
return {
|
|
55
46
|
lineNumber,
|
|
56
47
|
code,
|
|
57
|
-
isHighlighted: lineNumber === props.line
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
})
|
|
48
|
+
isHighlighted: lineNumber === props.line
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
});
|
|
61
52
|
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
source: string;
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
export default _default;
|
|
@@ -21,40 +21,32 @@
|
|
|
21
21
|
</div>
|
|
22
22
|
</template>
|
|
23
23
|
|
|
24
|
-
<script setup
|
|
25
|
-
import
|
|
26
|
-
import { useState, computed } from
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
() => [],
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
const groups = computed<OperationResponseError[]>(() => {
|
|
24
|
+
<script setup>
|
|
25
|
+
import "./../css/output.css";
|
|
26
|
+
import { useState, computed } from "#imports";
|
|
27
|
+
import ErrorGroup from "./ErrorGroup.vue";
|
|
28
|
+
const errors = useState(
|
|
29
|
+
"nuxt-graphql-middleware-errors",
|
|
30
|
+
() => []
|
|
31
|
+
);
|
|
32
|
+
const groups = computed(() => {
|
|
37
33
|
return [
|
|
38
|
-
...errors.value
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
]
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
/** Clear the error state => close/hide the overlay */
|
|
34
|
+
...errors.value.reduce((acc, v) => {
|
|
35
|
+
const key = `${v.operation}_${v.operationName}`;
|
|
36
|
+
if (!acc.has(key)) {
|
|
37
|
+
acc.set(key, {
|
|
38
|
+
operation: v.operation,
|
|
39
|
+
operationName: v.operationName,
|
|
40
|
+
errors: [],
|
|
41
|
+
stack: v.stack
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
acc.get(key).errors.push(...v.errors);
|
|
45
|
+
return acc;
|
|
46
|
+
}, /* @__PURE__ */ new Map()).values()
|
|
47
|
+
];
|
|
48
|
+
});
|
|
57
49
|
function clearErrors() {
|
|
58
|
-
errors.value = []
|
|
50
|
+
errors.value = [];
|
|
59
51
|
}
|
|
60
52
|
</script>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import './../css/output.css.js';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
3
|
+
export default _default;
|
|
@@ -5,19 +5,17 @@
|
|
|
5
5
|
</tr>
|
|
6
6
|
</template>
|
|
7
7
|
|
|
8
|
-
<script setup
|
|
9
|
-
import { computed } from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}>()
|
|
14
|
-
|
|
8
|
+
<script setup>
|
|
9
|
+
import { computed } from "#imports";
|
|
10
|
+
const props = defineProps({
|
|
11
|
+
extensions: { type: Object, required: false }
|
|
12
|
+
});
|
|
15
13
|
const mapped = computed(() => {
|
|
16
14
|
if (!props.extensions) {
|
|
17
|
-
return []
|
|
15
|
+
return [];
|
|
18
16
|
}
|
|
19
17
|
return Object.entries(props.extensions).map(([key, value]) => {
|
|
20
|
-
return { key, value }
|
|
21
|
-
})
|
|
22
|
-
})
|
|
18
|
+
return { key, value };
|
|
19
|
+
});
|
|
20
|
+
});
|
|
23
21
|
</script>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
extensions?: Record<string, unknown>;
|
|
3
|
+
};
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
export default _default;
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<template v-for="error in uniqueErrors" :key="error.key">
|
|
24
24
|
<tr>
|
|
25
25
|
<td>Path</td>
|
|
26
|
-
<td>{{ error.path.join(
|
|
26
|
+
<td>{{ error.path.join(" - ") }}</td>
|
|
27
27
|
</tr>
|
|
28
28
|
<tr>
|
|
29
29
|
<td colspan="2" class="ngm-large">{{ error.message }}</td>
|
|
@@ -46,44 +46,33 @@
|
|
|
46
46
|
</table>
|
|
47
47
|
</template>
|
|
48
48
|
|
|
49
|
-
<script
|
|
50
|
-
import
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import
|
|
54
|
-
import
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
errors: GraphqlResponseError[]
|
|
63
|
-
stack?: string
|
|
64
|
-
}>()
|
|
65
|
-
|
|
66
|
-
const key = computed(() => props.operation + '_' + props.operationName)
|
|
67
|
-
|
|
49
|
+
<script setup>
|
|
50
|
+
import { documents } from "#nuxt-graphql-middleware/documents";
|
|
51
|
+
import { operationSources } from "#nuxt-graphql-middleware/sources";
|
|
52
|
+
import { computed } from "#imports";
|
|
53
|
+
import CodeFrame from "./CodeFrame.vue";
|
|
54
|
+
import ErrorExtensions from "./ErrorExtensions.vue";
|
|
55
|
+
const props = defineProps({
|
|
56
|
+
operation: { type: String, required: true },
|
|
57
|
+
operationName: { type: String, required: true },
|
|
58
|
+
errors: { type: Array, required: true },
|
|
59
|
+
stack: { type: String, required: false }
|
|
60
|
+
});
|
|
61
|
+
const key = computed(() => props.operation + "_" + props.operationName);
|
|
68
62
|
const filePath = computed(() => {
|
|
69
|
-
return operationSources[key.value]
|
|
70
|
-
})
|
|
71
|
-
|
|
63
|
+
return operationSources[key.value];
|
|
64
|
+
});
|
|
72
65
|
const source = computed(
|
|
73
|
-
() =>
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}, new Map())
|
|
86
|
-
.values()
|
|
87
|
-
.toArray()
|
|
88
|
-
})
|
|
66
|
+
() => documents[props.operation]?.[props.operationName]
|
|
67
|
+
);
|
|
68
|
+
const uniqueErrors = computed(() => {
|
|
69
|
+
return props.errors.reduce((acc, v) => {
|
|
70
|
+
const key2 = v.message;
|
|
71
|
+
if (!acc.has(key2)) {
|
|
72
|
+
acc.set(key2, { ...v, key: key2, count: 0 });
|
|
73
|
+
}
|
|
74
|
+
acc.get(key2).count++;
|
|
75
|
+
return acc;
|
|
76
|
+
}, /* @__PURE__ */ new Map()).values().toArray();
|
|
77
|
+
});
|
|
89
78
|
</script>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GraphqlResponseError } from '../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
operation: string;
|
|
4
|
+
operationName: string;
|
|
5
|
+
errors: GraphqlResponseError[];
|
|
6
|
+
stack?: string;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
export default _default;
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import type { FetchOptions } from 'ofetch';
|
|
2
|
-
import { GraphqlMiddlewareCache } from '../helpers/ClientCache.js';
|
|
2
|
+
import type { GraphqlMiddlewareCache } from '../helpers/ClientCache.js';
|
|
3
3
|
import type { GraphqlResponse } from '#nuxt-graphql-middleware/response';
|
|
4
4
|
import type { RequestCacheOptions } from './../types.js';
|
|
5
|
-
export declare function performRequest<T>(
|
|
5
|
+
export declare function performRequest<T>(
|
|
6
|
+
/**
|
|
7
|
+
* The operation type.
|
|
8
|
+
*/
|
|
9
|
+
operation: 'query' | 'mutation',
|
|
10
|
+
/**
|
|
11
|
+
* The name of the operation.
|
|
12
|
+
*/
|
|
13
|
+
operationName: string,
|
|
14
|
+
/**
|
|
15
|
+
* The operation variables.
|
|
16
|
+
*/
|
|
17
|
+
variablesOrBody: Record<string, any>,
|
|
18
|
+
/**
|
|
19
|
+
* Fetch options set on the composable.
|
|
20
|
+
*/
|
|
21
|
+
overrideFetchOptions: FetchOptions,
|
|
22
|
+
/**
|
|
23
|
+
* The global client options determined in the composable.
|
|
24
|
+
*/
|
|
25
|
+
globalClientContext: Record<string, any>,
|
|
26
|
+
/**
|
|
27
|
+
* Client options overrides set on the composable.
|
|
28
|
+
*/
|
|
29
|
+
overrideClientContext: Record<string, any>,
|
|
30
|
+
/**
|
|
31
|
+
* The cache options set on the composable.
|
|
32
|
+
*/
|
|
33
|
+
cacheOptions: RequestCacheOptions): Promise<GraphqlResponse<T>>;
|
|
6
34
|
declare module '#app' {
|
|
7
35
|
interface NuxtApp {
|
|
8
36
|
$graphqlCache?: GraphqlMiddlewareCache;
|
|
@@ -1,26 +1,57 @@
|
|
|
1
1
|
import { useGraphqlState } from "./useGraphqlState.js";
|
|
2
2
|
import { hash } from "ohash";
|
|
3
|
-
import { GraphqlMiddlewareCache } from "../helpers/ClientCache.js";
|
|
4
3
|
import { getEndpoint } from "#nuxt-graphql-middleware/helpers";
|
|
5
4
|
import { useNuxtApp, useAppConfig } from "#imports";
|
|
6
|
-
|
|
5
|
+
import { operationHashes } from "#nuxt-graphql-middleware/operation-hashes";
|
|
6
|
+
import {
|
|
7
|
+
clientCacheEnabledAtBuild,
|
|
8
|
+
importMetaClient
|
|
9
|
+
} from "#nuxt-graphql-middleware/config";
|
|
10
|
+
import { encodeVariables } from "../helpers/queryEncoding.js";
|
|
11
|
+
import {
|
|
12
|
+
encodeContext,
|
|
13
|
+
getOrCreateClientCache,
|
|
14
|
+
sortQueryParams
|
|
15
|
+
} from "../helpers/composables.js";
|
|
16
|
+
import { OPERATION_HASH_PREFIX } from "../settings/index.js";
|
|
17
|
+
export function performRequest(operation, operationName, variablesOrBody, overrideFetchOptions, globalClientContext, overrideClientContext, cacheOptions) {
|
|
7
18
|
const state = useGraphqlState();
|
|
8
19
|
const app = useNuxtApp();
|
|
20
|
+
const config = useAppConfig();
|
|
21
|
+
const method = operation === "query" ? "get" : "post";
|
|
22
|
+
const isQuery = operation === "query";
|
|
9
23
|
if (!state) {
|
|
10
24
|
console.error(
|
|
11
25
|
`A GraphQL composable for ${operation} "${operationName}" was called before the "nuxt-graphql-middleware-provide-state" plugin could provide the state, which might lead to unexpected behaviour. Make sure that custom plugins that perform GraphQL requests are executed after "nuxt-graphql-middleware-provide-state" by setting it as a dependency via "dependsOn".`
|
|
12
26
|
);
|
|
13
27
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const clientContext = Object.assign(
|
|
29
|
+
{},
|
|
30
|
+
globalClientContext,
|
|
31
|
+
overrideClientContext
|
|
32
|
+
);
|
|
33
|
+
const fetchOptions = Object.assign(
|
|
34
|
+
{},
|
|
35
|
+
state?.fetchOptions,
|
|
36
|
+
overrideFetchOptions
|
|
37
|
+
);
|
|
38
|
+
const paramsRaw = Object.assign(
|
|
39
|
+
importMetaClient ? {
|
|
40
|
+
// The unique operation hash that changes whenever any operation source or
|
|
41
|
+
// fragment changes.
|
|
42
|
+
[OPERATION_HASH_PREFIX]: operationHashes[operationName]
|
|
43
|
+
} : {},
|
|
44
|
+
encodeContext(clientContext),
|
|
45
|
+
fetchOptions.params,
|
|
46
|
+
fetchOptions.query,
|
|
47
|
+
isQuery ? encodeVariables(variablesOrBody) : null
|
|
48
|
+
);
|
|
49
|
+
const params = importMetaClient && isQuery ? sortQueryParams(paramsRaw) : paramsRaw;
|
|
50
|
+
const cacheKey = importMetaClient && clientCacheEnabledAtBuild && isQuery && cacheOptions?.client && config.graphqlMiddleware.clientCacheEnabled ? `${operation}:${operationName}:${hash(params)}` : void 0;
|
|
51
|
+
if (importMetaClient && cacheKey) {
|
|
52
|
+
const cache = getOrCreateClientCache(app, config);
|
|
53
|
+
if (cache) {
|
|
54
|
+
const cached = cache.get(cacheKey);
|
|
24
55
|
if (cached) {
|
|
25
56
|
if (import.meta.dev) {
|
|
26
57
|
cached.then((response) => {
|
|
@@ -40,11 +71,23 @@ export function performRequest(operation, operationName, method, options, cacheO
|
|
|
40
71
|
}
|
|
41
72
|
const promise = $fetch(
|
|
42
73
|
getEndpoint(operation, operationName),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
74
|
+
Object.assign(
|
|
75
|
+
{},
|
|
76
|
+
// Use the merged fetch options.
|
|
77
|
+
fetchOptions,
|
|
78
|
+
// Remove params and query from the fetch options.
|
|
79
|
+
{
|
|
80
|
+
params: void 0,
|
|
81
|
+
query: void 0
|
|
82
|
+
},
|
|
83
|
+
// Set the previously merged params. That way we only ever pass "params"
|
|
84
|
+
// as the query params.
|
|
85
|
+
{
|
|
86
|
+
params,
|
|
87
|
+
method,
|
|
88
|
+
body: operation === "mutation" ? variablesOrBody : void 0
|
|
89
|
+
}
|
|
90
|
+
)
|
|
48
91
|
).then((v) => {
|
|
49
92
|
if (import.meta.dev && v.errors?.length) {
|
|
50
93
|
app.callHook("nuxt-graphql-middleware:errors", {
|
|
@@ -54,14 +97,13 @@ export function performRequest(operation, operationName, method, options, cacheO
|
|
|
54
97
|
stack: Error().stack
|
|
55
98
|
});
|
|
56
99
|
}
|
|
57
|
-
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
100
|
+
return Object.assign({}, v, {
|
|
101
|
+
data: v?.data,
|
|
102
|
+
errors: v?.errors || []
|
|
103
|
+
});
|
|
62
104
|
});
|
|
63
|
-
if (
|
|
64
|
-
app.$graphqlCache.set(
|
|
105
|
+
if (importMetaClient && cacheKey && app.$graphqlCache && clientCacheEnabledAtBuild) {
|
|
106
|
+
app.$graphqlCache.set(cacheKey, promise);
|
|
65
107
|
}
|
|
66
108
|
return promise;
|
|
67
109
|
}
|
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
getOrCreateClientCache
|
|
3
3
|
} from "./../helpers/composables.js";
|
|
4
4
|
import { isRef, unref } from "vue";
|
|
5
|
-
import { buildRequestParams } from "./../helpers/index.js";
|
|
6
5
|
import { performRequest } from "./nuxtApp.js";
|
|
7
6
|
import {
|
|
8
7
|
clientOptions
|
|
9
8
|
} from "#nuxt-graphql-middleware/client-options";
|
|
10
|
-
import { useAsyncData, useAppConfig, useNuxtApp } from "#imports";
|
|
9
|
+
import { useAsyncData, useAppConfig, useNuxtApp, computed } from "#imports";
|
|
11
10
|
import { hash } from "ohash";
|
|
11
|
+
import { importMetaClient } from "#nuxt-graphql-middleware/config";
|
|
12
12
|
export function useAsyncGraphqlQuery(name, ...args) {
|
|
13
13
|
const variables = args[0];
|
|
14
14
|
const asyncDataOptions = args[1] || {};
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const asyncDataKey = computed(() => {
|
|
16
|
+
const vars = isRef(variables) ? variables.value : variables;
|
|
17
|
+
return `useAsyncGraphqlQuery:${name}:${hash(vars)}`;
|
|
18
|
+
});
|
|
17
19
|
const config = useAppConfig();
|
|
18
20
|
const app = useNuxtApp();
|
|
19
|
-
if (
|
|
21
|
+
if (importMetaClient) {
|
|
20
22
|
if (variables && isRef(variables)) {
|
|
21
23
|
if (!asyncDataOptions.watch) {
|
|
22
24
|
asyncDataOptions.watch = [];
|
|
23
25
|
}
|
|
24
26
|
asyncDataOptions.watch.push(variables);
|
|
25
27
|
}
|
|
28
|
+
if (asyncDataOptions.graphqlCaching?.client && app.isHydrating) {
|
|
29
|
+
const cache = getOrCreateClientCache(app, config);
|
|
30
|
+
if (cache) {
|
|
31
|
+
const key = asyncDataKey.value;
|
|
32
|
+
const payload = app.payload.data[asyncDataKey.value];
|
|
33
|
+
if (payload) {
|
|
34
|
+
cache.set(key, payload);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
if (asyncDataOptions.graphqlCaching?.client && !asyncDataOptions.getCachedData) {
|
|
27
|
-
asyncDataOptions.getCachedData = function(
|
|
28
|
-
if (
|
|
29
|
-
return;
|
|
39
|
+
asyncDataOptions.getCachedData = function(key, app2, ctx) {
|
|
40
|
+
if (ctx.cause === "initial") {
|
|
41
|
+
return app2.payload.data[key] ?? app2.$graphqlCache?.get(key);
|
|
30
42
|
}
|
|
31
|
-
return app.payload.data[key2];
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
const result = useAsyncData(
|
|
36
|
-
|
|
47
|
+
asyncDataKey,
|
|
37
48
|
() => {
|
|
38
|
-
const globalClientContext = clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
49
|
+
const globalClientContext = clientOptions && clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
39
50
|
return performRequest(
|
|
40
51
|
"query",
|
|
41
52
|
name,
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
...buildRequestParams(unref(variables)),
|
|
48
|
-
...encodeContext({
|
|
49
|
-
...globalClientContext,
|
|
50
|
-
...asyncDataOptions.clientContext || {}
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
asyncDataOptions.graphqlCaching
|
|
53
|
+
unref(variables) || {},
|
|
54
|
+
asyncDataOptions.fetchOptions || {},
|
|
55
|
+
globalClientContext,
|
|
56
|
+
asyncDataOptions.clientContext || {},
|
|
57
|
+
asyncDataOptions.graphqlCaching || {}
|
|
55
58
|
);
|
|
56
59
|
},
|
|
57
60
|
asyncDataOptions
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { GetMutationArgs, MutationObjectArgs, GetMutationResult } from './../helpers/composables.js';
|
|
2
2
|
import type { GraphqlResponse } from '#nuxt-graphql-middleware/response';
|
|
3
3
|
import type { Mutation } from '#nuxt-graphql-middleware/operation-types';
|
|
4
4
|
/**
|
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
encodeContext
|
|
3
|
-
} from "./../helpers/composables.js";
|
|
4
1
|
import { performRequest } from "./nuxtApp.js";
|
|
5
2
|
import { clientOptions } from "#nuxt-graphql-middleware/client-options";
|
|
6
3
|
export function useGraphqlMutation(...args) {
|
|
7
|
-
const [name, body, fetchOptions
|
|
4
|
+
const [name, body, fetchOptions, overrideClientContext] = typeof args[0] === "string" ? [args[0], args[1], args[2]?.fetchOptions, args[2]?.clientContext] : [
|
|
8
5
|
args[0].name,
|
|
9
6
|
args[0].variables,
|
|
10
7
|
args[0].fetchOptions,
|
|
11
8
|
args[0].clientContext
|
|
12
9
|
];
|
|
13
|
-
const globalClientContext = clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
14
|
-
return performRequest(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
});
|
|
10
|
+
const globalClientContext = clientOptions && clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
11
|
+
return performRequest(
|
|
12
|
+
"mutation",
|
|
13
|
+
name,
|
|
14
|
+
body || {},
|
|
15
|
+
fetchOptions || {},
|
|
16
|
+
globalClientContext,
|
|
17
|
+
overrideClientContext || {},
|
|
18
|
+
{}
|
|
19
|
+
);
|
|
25
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { GetQueryArgs, QueryObjectArgs, GetQueryResult } from './../helpers/composables.js';
|
|
2
2
|
import type { GraphqlResponse } from '#nuxt-graphql-middleware/response';
|
|
3
3
|
import type { Query } from '#nuxt-graphql-middleware/operation-types';
|
|
4
4
|
/**
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
encodeContext
|
|
3
|
-
} from "./../helpers/composables.js";
|
|
4
|
-
import { buildRequestParams } from "./../helpers/index.js";
|
|
5
1
|
import { performRequest } from "./nuxtApp.js";
|
|
6
2
|
import { clientOptions } from "#nuxt-graphql-middleware/client-options";
|
|
7
3
|
export function useGraphqlQuery(...args) {
|
|
8
|
-
const [
|
|
9
|
-
name,
|
|
10
|
-
variables,
|
|
11
|
-
fetchOptions = {},
|
|
12
|
-
graphqlCaching = {},
|
|
13
|
-
overrideClientContext = {}
|
|
14
|
-
] = typeof args[0] === "string" ? [
|
|
4
|
+
const [name, variables, fetchOptions, graphqlCaching, overrideClientContext] = typeof args[0] === "string" ? [
|
|
15
5
|
args[0],
|
|
16
6
|
args[1],
|
|
17
7
|
args[2]?.fetchOptions,
|
|
@@ -24,22 +14,14 @@ export function useGraphqlQuery(...args) {
|
|
|
24
14
|
args[0].graphqlCaching,
|
|
25
15
|
args[0].clientContext
|
|
26
16
|
];
|
|
27
|
-
const globalClientContext = clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
17
|
+
const globalClientContext = clientOptions && clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
28
18
|
return performRequest(
|
|
29
19
|
"query",
|
|
30
20
|
name,
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...buildRequestParams(variables),
|
|
37
|
-
...encodeContext({
|
|
38
|
-
...globalClientContext,
|
|
39
|
-
...overrideClientContext
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
graphqlCaching
|
|
21
|
+
variables || {},
|
|
22
|
+
fetchOptions || {},
|
|
23
|
+
globalClientContext || {},
|
|
24
|
+
overrideClientContext || {},
|
|
25
|
+
graphqlCaching || {}
|
|
44
26
|
);
|
|
45
27
|
}
|
|
@@ -49,7 +49,7 @@ export function useGraphqlUploadMutation(...args) {
|
|
|
49
49
|
}
|
|
50
50
|
const state = useGraphqlState();
|
|
51
51
|
const formData = createFormData(variables);
|
|
52
|
-
const globalClientContext = clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
52
|
+
const globalClientContext = clientOptions && clientOptions.buildClientContext ? clientOptions.buildClientContext() : {};
|
|
53
53
|
const clientContext = encodeContext({
|
|
54
54
|
...globalClientContext,
|
|
55
55
|
...overrideClientContext
|
|
@@ -36,5 +36,17 @@ export class GraphqlMiddlewareCache {
|
|
|
36
36
|
}
|
|
37
37
|
purge() {
|
|
38
38
|
this.cache = {};
|
|
39
|
+
this.keys = [];
|
|
40
|
+
}
|
|
41
|
+
remove(key) {
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(this.cache, key)) {
|
|
43
|
+
delete this.cache[key];
|
|
44
|
+
const index = this.keys.indexOf(key);
|
|
45
|
+
if (index > -1) {
|
|
46
|
+
this.keys.splice(index, 1);
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
39
51
|
}
|
|
40
52
|
}
|