nuxt-graphql-middleware 4.0.0-beta.3 → 4.0.0-beta.5

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.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
3
  "configKey": "graphqlMiddleware",
4
- "version": "4.0.0-beta.3",
4
+ "version": "4.0.0-beta.5",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.1.0"
7
7
  }
package/dist/module.mjs CHANGED
@@ -20,7 +20,7 @@ import { oldVisit } from '@graphql-codegen/plugin-helpers';
20
20
  import { pascalCase } from 'change-case-all';
21
21
 
22
22
  const name = "nuxt-graphql-middleware";
23
- const version = "4.0.0-beta.3";
23
+ const version = "4.0.0-beta.5";
24
24
 
25
25
  const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
26
26
  const DEVTOOLS_UI_LOCAL_PORT = 3300;
@@ -600,7 +600,7 @@ const module = defineNuxtModule({
600
600
  documents: []
601
601
  };
602
602
  let rpc = null;
603
- if (options.devtools && nuxt.options.dev) {
603
+ if (options.devtools) {
604
604
  const clientPath = moduleResolver("./client");
605
605
  setupDevToolsUI(nuxt, clientPath);
606
606
  const setupRpc = () => {
@@ -679,7 +679,7 @@ const module = defineNuxtModule({
679
679
  });
680
680
  }
681
681
  };
682
- generateHandler(true);
682
+ await generateHandler(true);
683
683
  nuxt.options.runtimeConfig.public["nuxt-graphql-middleware"] = {
684
684
  serverApiPrefix: options.serverApiPrefix
685
685
  };
@@ -11,7 +11,7 @@ type GraphqlResponse<T> = {
11
11
  };
12
12
  type GetQueryResult<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
13
13
  type GetMutationResult<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
14
- export declare const useGraphqlState: () => GraphqlMiddlewareState;
14
+ export declare const useGraphqlState: (providedApp?: any) => GraphqlMiddlewareState | null;
15
15
  type QueryObjectArgs<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T][0] extends null ? {
16
16
  name: T;
17
17
  fetchOptions?: FetchOptions;
@@ -4,16 +4,20 @@ function getEndpoint(operation, operationName) {
4
4
  const config = useRuntimeConfig();
5
5
  return `${config?.public?.["nuxt-graphql-middleware"]?.serverApiPrefix}/${operation}/${operationName}`;
6
6
  }
7
- const state = {
8
- fetchOptions: {}
9
- };
10
- export const useGraphqlState = function() {
11
- return state;
7
+ export const useGraphqlState = function(providedApp) {
8
+ try {
9
+ const app = providedApp || useNuxtApp();
10
+ if (app.$graphqlState) {
11
+ return app.$graphqlState;
12
+ }
13
+ } catch (_e) {
14
+ }
15
+ return null;
12
16
  };
13
17
  function performRequest(operation, operationName, method, options) {
14
- const state2 = useGraphqlState();
18
+ const state = useGraphqlState();
15
19
  return $fetch(getEndpoint(operation, operationName), {
16
- ...state2 && state2.fetchOptions ? state2.fetchOptions : {},
20
+ ...state && state.fetchOptions ? state.fetchOptions : {},
17
21
  ...options,
18
22
  method
19
23
  }).then((v) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
- "version": "4.0.0-beta.3",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Module to perform GraphQL requests as a server middleware.",
5
5
  "repository": {
6
6
  "type": "git",