Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Klesse committed Aug 16, 2024
1 parent 01d6de2 commit 5f92f43
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,33 @@ export async function generateComposables(meta: GraphQLMeta): Promise<string> {
if (methods?.mutation) {
for (const mutation of methods.mutation) {
const types = meta.getTypesForMethod(mutation, 'Mutation');
if (types.customTypes) {
customTypes.push(types.customTypes);
}
customTypes.push(types.customTypes);
const inputFieldsType = types.returnType.replace('[]', '');
const returnTypeIsDefaultType = defaultTypes.includes(types.returnType.toLowerCase());

template.push(
`export const use${capitalizeFirstLetter(mutation)}Mutation = (${
types.argType ? 'variables: { ' + types.argType + ' },' : ''
} fields?: InputFields<${inputFieldsType}>[] | null, log?: boolean): Promise<UseMutationReturn<{${mutation}: ${types.returnType}}, any>> => gqlMutation<{${mutation}: ${
} ${returnTypeIsDefaultType ? '' : `fields?: InputFields<${inputFieldsType}>[] | null,`} log?: boolean): Promise<UseMutationReturn<{${mutation}: ${types.returnType}}, any>> => gqlMutation<{${mutation}: ${
types.returnType
}}>('${mutation}', {${types.argType ? 'variables,' : ''} fields, log})`,
}}>('${mutation}', {${types.argType ? 'variables,' : ''} ${returnTypeIsDefaultType ? 'fields: null' : 'fields'}, log})`,
);
}
}

if (methods?.subscription) {
for (const subscription of methods.subscription) {
const types = meta.getTypesForMethod(subscription, 'Subscription');
if (types.customTypes) {
customTypes.push(types.customTypes);
}
customTypes.push(types.customTypes);
const inputFieldsType = types.returnType.replace('[]', '');
const returnTypeIsDefaultType = defaultTypes.includes(types.returnType.toLowerCase());

template.push(
`export const use${capitalizeFirstLetter(subscription)}Subscription = (${
types.argType ? 'variables: { ' + types.argType + ' },' : ''
} fields?: InputFields<${inputFieldsType}>[] | null, log?: boolean): Promise<UseSubscriptionReturn<{${subscription}: ${
} ${returnTypeIsDefaultType ? '' : `fields?: InputFields<${inputFieldsType}>[] | null,`} log?: boolean): Promise<UseSubscriptionReturn<{${subscription}: ${
types.returnType
}}, any>> => gqlSubscription<{${subscription}: ${types.returnType}}>('${subscription}', {${types.argType ? 'variables,' : ''} fields, log})`,
}}, any>> => gqlSubscription<{${subscription}: ${types.returnType}}>('${subscription}', {${types.argType ? 'variables,' : ''} ${returnTypeIsDefaultType ? 'fields: null' : 'fields'}, log})`,
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/runtime/composables/gql-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import type { UseMutationReturn } from '@vue/apollo-composable';
import { useMutation } from '@vue/apollo-composable';
import { mutation } from 'gql-query-builder';
import gql from 'graphql-tag';
import { callWithNuxt, useNuxtApp } from 'nuxt/app';
import { useNuxtApp } from 'nuxt/app';

import type { GraphQLMeta } from '../classes/graphql-meta.class';
import type { IGraphQLOptions } from '../interfaces/graphql-options.interface';

import { hashPasswords } from '../functions/graphql-meta';

export async function gqlMutation<T = any>(method: string, options: IGraphQLOptions = {}): Promise<UseMutationReturn<T, any>> {
const _nuxt = useNuxtApp();
const { $graphQl } = _nuxt;
const { $graphQl } = useNuxtApp();

// Check parameters
if (!method) {
Expand Down Expand Up @@ -126,5 +125,5 @@ export async function gqlMutation<T = any>(method: string, options: IGraphQLOpti
console.debug('gqlMutation::documentNode ', documentNode);
}

return callWithNuxt(_nuxt, useMutation<T>, [documentNode, { fetchPolicy: 'no-cache', variables }]);
return useMutation<T>(documentNode, { fetchPolicy: 'no-cache', variables });
}
5 changes: 2 additions & 3 deletions src/runtime/composables/gql-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AsyncData } from 'nuxt/app';
import { useAsyncQuery, useLazyAsyncQuery } from '#imports';
import { query } from 'gql-query-builder';
import gql from 'graphql-tag';
import { callWithNuxt, useNuxtApp } from 'nuxt/app';
import { useNuxtApp } from 'nuxt/app';

import type { GraphQLMeta } from '../classes/graphql-meta.class';
import type { IGraphQLOptions } from '../interfaces/graphql-options.interface';
Expand Down Expand Up @@ -37,7 +37,6 @@ export async function gqlQuery<T = any>(method: string, options: IGraphQLOptions
}

const meta = $graphQl() as unknown as GraphQLMeta;

if (!meta) {
return;
}
Expand Down Expand Up @@ -117,5 +116,5 @@ export async function gqlQuery<T = any>(method: string, options: IGraphQLOptions
variables: variables,
};

return callWithNuxt(_nuxt, config.lazy ? useLazyAsyncQuery<T> : useAsyncQuery<T>, [queryConfig]);
return config.lazy ? useLazyAsyncQuery<T>(queryConfig) : useAsyncQuery<T>(queryConfig);
}

0 comments on commit 5f92f43

Please sign in to comment.