Skip to content

Commit

Permalink
fix: try unique key for async query
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Klesse committed Sep 10, 2024
1 parent 43d2698 commit 5a67aef
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/runtime/composables/gql-async-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export async function gqlAsyncQuery<T = any>(method: string, options: IGraphQLOp
str = JSON.stringify(input);
}

if (!str) {
return 0;
}

let hash = 0;

for (let i = 0; i < str.length; i++) {
Expand All @@ -43,27 +47,32 @@ export async function gqlAsyncQuery<T = any>(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);
Expand All @@ -73,10 +82,6 @@ export async function gqlAsyncQuery<T = any>(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);
Expand Down

0 comments on commit 5a67aef

Please sign in to comment.