Fragment cannot be found if the reference is a property of an object
Thiagolino8 opened this issue · 2 comments
Describe the bug
If the fragment is declared as a variable it can be used in a query normally
But if it is declared as an object or array of fragments, the query where it is used cannot find the fragment
This work:
const fragment = graphql(`
fragment Pokemon on pokemon_v2_pokemonspecies {
has_gender_differences
evolves_from_species_id
generation_id
name
evolution_chain_id
}
`)
const PokemonsQuery = graphql(`
query Pokemons($limit: Int = 10, $offset: Int = 0) {
pokemons: pokemon_v2_pokemonspecies(order_by: { id: asc }, distinct_on: id, limit: $limit, offset: $offset) {
id
...Pokemon
}
}
`, [fragment])
This doesn't:
const fragments = {
pokemon: graphql(`
fragment Pokemon on pokemon_v2_pokemonspecies {
has_gender_differences
evolves_from_species_id
generation_id
name
evolution_chain_id
}
`
})
const PokemonsQuery = graphql(`
query Pokemons($limit: Int = 10, $offset: Int = 0) {
pokemons: pokemon_v2_pokemonspecies(order_by: { id: asc }, distinct_on: id, limit: $limit, offset: $offset) {
id
...Pokemon // Unknown fragment "Pokemon"
}
}
`, [fragments.pokemon])
Reproduction
https://github.com/Thiagolino8/gql.tada_object_fragment_issue_repro
gql.tada version
1.0.3
Validations
- I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
- Read the docs.
- Follow our Code of Conduct
This is basically a limitation in @0no-co/graphqlsp
with detecting this particular placement of queries. I'll transfer it over
Edit: btw, I saw you're trying out the new @_unmask
feature there. Since it's not documented just yet, in case it wasn't obvious, instead of ResultOf<typeof PokemonsQuery>['pokemons'][number]
the more convenient ResultOf<typeof fragments.pokemon>
works too. Writing FragmentOf<typeof fragments.pokemon>
is a little more idiomatic, since it'll switch between masked and unmasked mode seamlessly
Published the fix in 1.2.0