nuxt-graphql-middleware 4.0.0-beta.4 → 4.0.0-beta.6

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.4",
4
+ "version": "4.0.0-beta.6",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.1.0"
7
7
  }
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { fileURLToPath } from 'url';
2
2
  import { resolve } from 'pathe';
3
3
  import { defu } from 'defu';
4
- import { useLogger, resolveAlias, resolveFiles, defineNuxtModule, createResolver, addImportsDir, addTemplate, addServerHandler, addPlugin, updateTemplates } from '@nuxt/kit';
4
+ import { useLogger, resolveAlias, resolveFiles, defineNuxtModule, createResolver, addImports, addTemplate, addServerHandler, addPlugin, updateTemplates } from '@nuxt/kit';
5
5
  import inquirer from 'inquirer';
6
6
  import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
7
7
  import { existsSync } from 'fs';
@@ -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.4";
23
+ const version = "4.0.0-beta.6";
24
24
 
25
25
  const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
26
26
  const DEVTOOLS_UI_LOCAL_PORT = 3300;
@@ -687,9 +687,20 @@ const module = defineNuxtModule({
687
687
  graphqlEndpoint: options.graphqlEndpoint || ""
688
688
  };
689
689
  if (options.includeComposables) {
690
- addImportsDir(moduleResolver("runtime/composables"));
690
+ addImports({
691
+ from: moduleResolver("./runtime/composables/useGraphqlQuery"),
692
+ name: "useGraphqlQuery"
693
+ });
694
+ addImports({
695
+ from: moduleResolver("./runtime/composables/useGraphqlMutation"),
696
+ name: "useGraphqlMutation"
697
+ });
698
+ addImports({
699
+ from: moduleResolver("./runtime/composables/useGraphqlState"),
700
+ name: "useGraphqlState"
701
+ });
691
702
  nuxt.options.alias["#graphql-composable"] = moduleResolver(
692
- "runtime/composables"
703
+ "runtime/composables/server"
693
704
  );
694
705
  }
695
706
  Object.values(GraphqlMiddlewareTemplate).forEach((filename) => {
@@ -0,0 +1,5 @@
1
+ import type { FetchOptions } from 'ofetch';
2
+ export declare function performRequest(operation: string, operationName: string, method: 'get' | 'post', options: FetchOptions): Promise<{
3
+ data: any;
4
+ errors: any[];
5
+ }>;
@@ -0,0 +1,15 @@
1
+ import { useGraphqlState } from "./useGraphqlState.mjs";
2
+ import { getEndpoint } from "./shared.mjs";
3
+ export function performRequest(operation, operationName, method, options) {
4
+ const state = useGraphqlState();
5
+ return $fetch(getEndpoint(operation, operationName), {
6
+ ...state && state.fetchOptions ? state.fetchOptions : {},
7
+ ...options,
8
+ method
9
+ }).then((v) => {
10
+ return {
11
+ data: v.data,
12
+ errors: v.errors || []
13
+ };
14
+ });
15
+ }
@@ -0,0 +1,10 @@
1
+ import { GraphqlMiddlewareQueryName, GetQueryArgs, QueryObjectArgs, GetQueryResult, GraphqlMiddlewareMutationName, GetMutationArgs, MutationObjectArgs, GetMutationResult } from './shared';
2
+ import type { GraphqlMiddlewareQuery, GraphqlMiddlewareMutation } from '#build/nuxt-graphql-middleware';
3
+ /**
4
+ * Performs a GraphQL query.
5
+ */
6
+ export declare function useGraphqlQuery<T extends GraphqlMiddlewareQueryName>(...args: GetQueryArgs<T, GraphqlMiddlewareQuery> | [QueryObjectArgs<T, GraphqlMiddlewareQuery>]): Promise<GetQueryResult<T, GraphqlMiddlewareQuery>>;
7
+ /**
8
+ * Performs a GraphQL mutation.
9
+ */
10
+ export declare function useGraphqlMutation<T extends GraphqlMiddlewareMutationName>(...args: GetMutationArgs<T, GraphqlMiddlewareMutation> | [MutationObjectArgs<T, GraphqlMiddlewareMutation>]): Promise<GetMutationResult<T, GraphqlMiddlewareMutation>>;
@@ -1,23 +1,9 @@
1
+ import {
2
+ getEndpoint
3
+ } from "./shared.mjs";
1
4
  import { buildRequestParams } from "./../helpers/index.mjs";
2
- import { useRuntimeConfig } from "#imports";
3
- function getEndpoint(operation, operationName) {
4
- const config = useRuntimeConfig();
5
- return `${config?.public?.["nuxt-graphql-middleware"]?.serverApiPrefix}/${operation}/${operationName}`;
6
- }
7
- export const useGraphqlState = function() {
8
- try {
9
- const app = useNuxtApp();
10
- if (app.$graphqlState) {
11
- return app.$graphqlState;
12
- }
13
- } catch (_e) {
14
- }
15
- return null;
16
- };
17
5
  function performRequest(operation, operationName, method, options) {
18
- const state = useGraphqlState();
19
6
  return $fetch(getEndpoint(operation, operationName), {
20
- ...state && state.fetchOptions ? state.fetchOptions : {},
21
7
  ...options,
22
8
  method
23
9
  }).then((v) => {
@@ -0,0 +1,31 @@
1
+ import type { FetchOptions } from 'ofetch';
2
+ import type { GraphqlMiddlewareQuery, GraphqlMiddlewareMutation } from '#build/nuxt-graphql-middleware';
3
+ export type GraphqlMiddlewareQueryName = keyof GraphqlMiddlewareQuery;
4
+ export type GraphqlMiddlewareMutationName = keyof GraphqlMiddlewareMutation;
5
+ export type GetQueryArgs<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T][0] extends null ? [T] : M[T][1] extends false ? [T, M[T][0]] : [T, M[T][0]?];
6
+ export type GetMutationArgs<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T][0] extends null ? [T] : M[T][1] extends false ? [T, M[T][0]] : [T, M[T][0]?];
7
+ export type GraphqlResponse<T> = {
8
+ data: T;
9
+ errors: any[];
10
+ };
11
+ export type GetQueryResult<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
12
+ export type GetMutationResult<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
13
+ export declare function getEndpoint(operation: string, operationName: string): string;
14
+ export type QueryObjectArgs<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T][0] extends null ? {
15
+ name: T;
16
+ fetchOptions?: FetchOptions;
17
+ variables?: null;
18
+ } : {
19
+ name: T;
20
+ variables: M[T][0];
21
+ fetchOptions?: FetchOptions;
22
+ };
23
+ export type MutationObjectArgs<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T][0] extends null ? {
24
+ name: T;
25
+ variables?: null;
26
+ fetchOptions?: FetchOptions;
27
+ } : {
28
+ name: T;
29
+ variables: M[T][0];
30
+ fetchOptions?: FetchOptions;
31
+ };
@@ -0,0 +1,5 @@
1
+ import { useRuntimeConfig } from "#imports";
2
+ export function getEndpoint(operation, operationName) {
3
+ const config = useRuntimeConfig();
4
+ return `${config?.public?.["nuxt-graphql-middleware"]?.serverApiPrefix}/${operation}/${operationName}`;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { GraphqlMiddlewareMutationName, GetMutationArgs, MutationObjectArgs, GetMutationResult } from './shared';
2
+ import type { GraphqlMiddlewareMutation } from '#build/nuxt-graphql-middleware';
3
+ /**
4
+ * Performs a GraphQL mutation.
5
+ */
6
+ export declare function useGraphqlMutation<T extends GraphqlMiddlewareMutationName>(...args: GetMutationArgs<T, GraphqlMiddlewareMutation> | [MutationObjectArgs<T, GraphqlMiddlewareMutation>]): Promise<GetMutationResult<T, GraphqlMiddlewareMutation>>;
@@ -0,0 +1,8 @@
1
+ import { performRequest } from "./nuxtApp.mjs";
2
+ export function useGraphqlMutation(...args) {
3
+ const [name, body, fetchOptions = {}] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].name, args[0].variables, args[0].fetchOptions];
4
+ return performRequest("mutation", name, "post", {
5
+ body,
6
+ ...fetchOptions
7
+ });
8
+ }
@@ -0,0 +1,6 @@
1
+ import { GraphqlMiddlewareQueryName, GetQueryArgs, QueryObjectArgs, GetQueryResult } from './shared';
2
+ import type { GraphqlMiddlewareQuery } from '#build/nuxt-graphql-middleware';
3
+ /**
4
+ * Performs a GraphQL query.
5
+ */
6
+ export declare function useGraphqlQuery<T extends GraphqlMiddlewareQueryName>(...args: GetQueryArgs<T, GraphqlMiddlewareQuery> | [QueryObjectArgs<T, GraphqlMiddlewareQuery>]): Promise<GetQueryResult<T, GraphqlMiddlewareQuery>>;
@@ -0,0 +1,9 @@
1
+ import { buildRequestParams } from "./../helpers/index.mjs";
2
+ import { performRequest } from "./nuxtApp.mjs";
3
+ export function useGraphqlQuery(...args) {
4
+ const [name, variables, fetchOptions = {}] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].name, args[0].variables, args[0].fetchOptions];
5
+ return performRequest("query", name, "get", {
6
+ params: buildRequestParams(variables),
7
+ ...fetchOptions
8
+ });
9
+ }
@@ -0,0 +1,3 @@
1
+ import { NuxtApp } from 'nuxt/app';
2
+ import { GraphqlMiddlewareState } from './../../types';
3
+ export declare const useGraphqlState: (providedApp?: NuxtApp) => GraphqlMiddlewareState | null;
@@ -0,0 +1,11 @@
1
+ import { useNuxtApp } from "nuxt/app";
2
+ export const useGraphqlState = function(providedApp) {
3
+ try {
4
+ const app = providedApp || useNuxtApp();
5
+ if (app.$graphqlState) {
6
+ return app.$graphqlState;
7
+ }
8
+ } catch (_e) {
9
+ }
10
+ return null;
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.6",
4
4
  "description": "Module to perform GraphQL requests as a server middleware.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,41 +0,0 @@
1
- import type { FetchOptions } from 'ofetch';
2
- import { GraphqlMiddlewareState } from './../../types';
3
- import type { GraphqlMiddlewareQuery, GraphqlMiddlewareMutation } from '#build/nuxt-graphql-middleware';
4
- type GraphqlMiddlewareQueryName = keyof GraphqlMiddlewareQuery;
5
- type GraphqlMiddlewareMutationName = keyof GraphqlMiddlewareMutation;
6
- type GetQueryArgs<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T][0] extends null ? [T] : M[T][1] extends false ? [T, M[T][0]] : [T, M[T][0]?];
7
- type GetMutationArgs<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T][0] extends null ? [T] : M[T][1] extends false ? [T, M[T][0]] : [T, M[T][0]?];
8
- type GraphqlResponse<T> = {
9
- data: T;
10
- errors: any[];
11
- };
12
- type GetQueryResult<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
13
- type GetMutationResult<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T] extends undefined ? undefined : GraphqlResponse<M[T][2]>;
14
- export declare const useGraphqlState: () => GraphqlMiddlewareState | null;
15
- type QueryObjectArgs<T extends GraphqlMiddlewareQueryName, M extends GraphqlMiddlewareQuery> = M[T][0] extends null ? {
16
- name: T;
17
- fetchOptions?: FetchOptions;
18
- variables?: null;
19
- } : {
20
- name: T;
21
- variables: M[T][0];
22
- fetchOptions?: FetchOptions;
23
- };
24
- type MutationObjectArgs<T extends GraphqlMiddlewareMutationName, M extends GraphqlMiddlewareMutation> = M[T][0] extends null ? {
25
- name: T;
26
- variables?: null;
27
- fetchOptions?: FetchOptions;
28
- } : {
29
- name: T;
30
- variables: M[T][0];
31
- fetchOptions?: FetchOptions;
32
- };
33
- /**
34
- * Performs a GraphQL query.
35
- */
36
- export declare function useGraphqlQuery<T extends GraphqlMiddlewareQueryName>(...args: GetQueryArgs<T, GraphqlMiddlewareQuery> | [QueryObjectArgs<T, GraphqlMiddlewareQuery>]): Promise<GetQueryResult<T, GraphqlMiddlewareQuery>>;
37
- /**
38
- * Performs a GraphQL mutation.
39
- */
40
- export declare function useGraphqlMutation<T extends GraphqlMiddlewareMutationName>(...args: GetMutationArgs<T, GraphqlMiddlewareMutation> | [MutationObjectArgs<T, GraphqlMiddlewareMutation>]): Promise<GetMutationResult<T, GraphqlMiddlewareMutation>>;
41
- export {};