Diizzayy / nuxt-graphql-client

⚡️ Minimal GraphQL Client + Code Generation for Nuxt3
https://nuxt-graphql-client.web.app
MIT License
366 stars 44 forks source link

Error for multiple client. Can't select the good client. #193

Closed aspitrine closed 2 years ago

aspitrine commented 2 years ago

Hi,

I can't use multiple client with nuxt-graphql-client.

I found the error here : https://github.com/Diizzayy/nuxt-graphql-client/blob/e0a910c281fb1b0ef04a0455619031b41fcf0914/src/runtime/composables/index.ts#L293

for the purpose look at my exemple :

I have 2 client :

I create query and mutation prefixed with the client.

When they need to select the good client

const client = Object.keys(GqlOperations).find(k => GqlOperations[k].includes(operation)) ?? 'default'

// GqlOperations[k] // ['query1', 'query2'] array of query name without the client prefix 
// operation // 'system_query1' the query WITH the client prefix 

So they can't work and select default value. A quick fix will be

const client = Object.keys(GqlOperations).find((k) => GqlOperations[k].find(op => operation.includes(op))) ?? "default";

You have the same error for generated query in https://github.com/Diizzayy/nuxt-graphql-client/blob/e0a910c281fb1b0ef04a0455619031b41fcf0914/src/context.ts#L25

the fix will be something like this

const client = ctx?.clients.find((c) => ctx?.clientOps?.[c]?.find(op => fn.includes(op)));

If you need more information, just ask.

Thanks for your work !

Diizzayy commented 2 years ago

@aspitrine Thank you for raising this issue! This bug slipped through the cracks here for far too long, it was caused to a previous regression where the GraphQL operations where no longer being prepared beforehand. This in hand directly affected the usage of useAsyncGql and the generated GqlFunctions in multi-client mode.