nuxt-graphql-client
nuxt-graphql-client copied to clipboard
Path of schema in runtime
Is there any way at runtime to inform the schema path or even the schema itself instead of just its name?
@emtudo I'm a bit unsure of what you're asking about here, can you give me an example or explain your use case a bit more?
Oops!
Apologies for the delay.
I want to be able to put my schema in the directory that I think makes the most sense and to be able to define which schema I want to call for each place.
@emtudo If my understanding is correct, this should already be possible. Multiple schemas can be placed anywhere in the project and linked to an individual client, note that the schema is only used for the typescript code generation (DX). Under the hood, your queries and mutation can be fired without you ever having to manually specify which client (or schema) to utilize
When I look at the documentation: https://nuxt-graphql-client.web.app/getting-started/composables
I don't see the possibility of me specifying my schema "the file" there I specify the name of the file and it needs to be in a standard directory.
How can I specify the file? example:
import Snacks from './lanches.gql'
const variables = { limit: 5 } const { data } = await useAsyncGql(snacks, { variables });
@emtudo Ahh, You're referring to the GraphQL documents rather than the GraphQL schemas. This module doesn't support manually passing graphql documents.
Is there a reason why the current implementation doesn't meet your needs?
Example below:
/nuxt-app/queries/demo.gql
# operation name is "launches"
query launches {
launches {
id
}
}
This query can be executed in your app by:
<script lang="ts" setup>
const variables = { limit: 5 }
// execute via operation name
const { data } = await useAsyncGql('launches', { variables });
async function callManually() {
// execute via auto imported function
await GqlLaunches()
}
</script>
The problem of that I can have two file of that.
/nuxt-app/queries/demo.gql query launches { launches { id } }
and another at:
/domains/demo/demo2.gql query launches { launches { id version } }
And at the moment X I want to use demo2 and not demo
@emtudo You would be to assign a more unique name to each query, that would allow you to use execute both ( also across different GraphQL APIs if needed )
query launchesX {
launches {
id
}
}
query launchesY {
launches {
id
version
}
}