Closed PhiFry closed 11 months ago
👋 @PhiFry Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible. Please make sure you have provided enough context.
This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.
Thanks for reaching out @PhiFry. The code-generator should not update your query or inline any field selections. It should, however, append the fragment to your query and send it to the server. Something like
query GetAllUsers() {
users: core_users {
...userFields
}
}
fragment userFields on User {
id
display_name
}
It is then up to the server to handle this appropriately.
Thank you @budde377 for taking your time and explaining.
I can see now that I missed the fragment
part of the built query and it does indeed exist. Our issue is that we didnt name the User type exactly like the Hasura one. I changed type User
to type core_users
and now it works.
Flutter project pubspec.yaml:
We use Hasura as our GraphQL host. We have a
core_users
table which has columns(id, display_name)
.In our
schema.graphql
file we have defined:Then for our query:
then
build_runner build
When I then call
_graphQLClient.query_GetAllUsers()
I get error message saying that "id" is null. When I breakpoint into the generated parsing function I see that the data received only consists of__typename
so of course its null.I dug even deeper to view the actual query being sent to our GraphQL host and found that the query doesnt include the fragment fields but only the fragment name like this:
I expected the query sent in the request to be this:
Removing the fragment and instead entering the fields manually in the query then everything works.
Is this the intended behaviour?
If it is then how can I get fragments to work? Do the GraphQL host need to specify the fragments?