kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 311 forks source link

Unable to use query fragments directly in a query #1833

Closed bnm27 closed 1 year ago

bnm27 commented 2 years ago

Describe the bug

It appears that I cannot use a query fragment as a top level statement inside of a query.

e.g.

query allFilmsWithVariables {
   ...FilmWrapper
   ...PersonWrapper
 }

If the fragment is nested under another node it works fine, but when placed directly in a query then no data is returned.

As far as I can tell this is valid and should work since the API will return the same results for both queries when executed directly against the API

To Reproduce

I have put together an example here: https://stackblitz.com/edit/node-c2x7qv?file=src/app/films/films.component.graphql

Expected behavior

Data is returned when executing a query where a query fragment is supplied as a top level statement

Environment:

- @angular/cli@14.2.6
- @angular/core@14.2.7
- @apollo/client@3.7.0
- apollo-angular@4.1.0
- graphql@16.6.0
- typescript@4.7.4

Additional context

bnm27 commented 2 years ago

Might be related to this: https://github.com/apollographql/apollo-client/issues/3402

cantoute commented 1 year ago

Having same issue. the issue pointed seems in deed related but is closed.

krechtern commented 1 year ago

We are facing the same issue right now. The apollo client responses only with the __typename. But looking into the browser network request, the response contains all requested data.

peterfication commented 1 year ago

This one fixed it for me: https://github.com/apollographql/apollo-client/issues/7470

If your query type is not called Query, you have to specify it in the InMemoryCache. In the example given, the query type is called Root and hence it fails.

Edit: fix the link

PowerKiKi commented 1 year ago

@peterfication thanks for the solution, though you might have copy-pasted the wrong link.

I'll close this, since it is not specific to apollo-angular.