diff --git a/src/runtime/composables/gql-async-query.ts b/src/runtime/composables/gql-async-query.ts index 860f1b8..338dfe8 100644 --- a/src/runtime/composables/gql-async-query.ts +++ b/src/runtime/composables/gql-async-query.ts @@ -27,6 +27,10 @@ export async function gqlAsyncQuery(method: string, options: IGraphQLOp str = JSON.stringify(input); } + if (!str) { + return 0; + } + let hash = 0; for (let i = 0; i < str.length; i++) { @@ -43,27 +47,32 @@ export async function gqlAsyncQuery(method: string, options: IGraphQLOp throw new Error('No method detected'); } + const config = { + asyncDataOptions: { + lazy: false, + }, + fields: null, + log: false, + variables: null, + ...options, + hashPasswords: options.hashPasswords ?? true, + }; + + // check if config.variables is a function + if (typeof config.variables === 'function') { + config.variables = config.variables(); + } + + if (config.hashPasswords) { + config.variables = await hashPasswords(config.variables); + } + return useAsyncData( method + hashCode(options.variables), async () => { // Get config - const config = { - asyncDataOptions: { - lazy: false, - }, - fields: null, - log: false, - variables: null, - ...options, - hashPasswords: options.hashPasswords ?? true, - }; const fields = config.fields as unknown as string[]; - // check if config.variables is a function - if (typeof config.variables === 'function') { - config.variables = config.variables(); - } - if (config.log) { console.debug('gqlQuery::fields ', fields); console.debug('gqlQuery::variables ', config.variables); @@ -73,10 +82,6 @@ export async function gqlAsyncQuery(method: string, options: IGraphQLOp throw new Error('GraphQLMeta is not available.'); } - if (config.hashPasswords) { - config.variables = await hashPasswords(config.variables); - } - const argType = _meta.getArgs(method); const builderInput = {}; const metaFields = _meta.getFields(method);