nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

Path of schema in runtime

Open emtudo opened this issue 2 years ago • 1 comments

Is there any way at runtime to inform the schema path or even the schema itself instead of just its name?

emtudo avatar Sep 09 '22 12:09 emtudo

@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?

Diizzayy avatar Sep 11 '22 23:09 Diizzayy

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 avatar Oct 17 '22 13:10 emtudo

@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

Diizzayy avatar Oct 17 '22 13:10 Diizzayy

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 avatar Oct 17 '22 16:10 emtudo

@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>

Diizzayy avatar Oct 17 '22 16:10 Diizzayy

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 avatar Oct 17 '22 16:10 emtudo

@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
}
}

Diizzayy avatar Oct 17 '22 17:10 Diizzayy