Closed abir-taheer closed 10 months ago
Deeper investigation has revealed that this behavior still occurs even without typegen and I've discovered that this is actually an issue with the Apollo cache.
For anyone else who runs into this see this issue:
https://github.com/apollographql/apollo-client/issues/7648
Essentially, you have to add the possibleTypes
property to the client cache.
Changing the cache to this:
const cache = new InMemoryCache({
possibleTypes: {
Person: ["Employee", "Customer"],
},
});
fixed the issue
Which packages are impacted by your issue?
@graphql-codegen/client-preset
Describe the bug
Codegen doesn't spread the fields correctly when:
Example:
Employee
andCustomer
are both subtypes ofBasePerson
The data will not include the
id
andname
fields from the fragmentdata
belonging to the PeopleQuery, will logA minimum reproducible example is provided here:
https://github.com/abir-taheer/minimum-reproducible-graphql-codegen-interface-fail
In that repo, for convenience, codegen will be run after the
yarn
command runs in thepostinstall
scriptrunning
yarn dev
from the mono repo root folder will run the web app and graphql server to demonstrate the query mismatchThe codegen config file is here: https://github.com/abir-taheer/minimum-reproducible-graphql-codegen-interface-fail/blob/main/apps/graphql/codegen.ts
typedefs: https://github.com/abir-taheer/minimum-reproducible-graphql-codegen-interface-fail/blob/main/apps/graphql/typeDefs.ts
The query is here: https://github.com/abir-taheer/minimum-reproducible-graphql-codegen-interface-fail/blob/main/apps/web/src/App.tsx
Your Example Website or App
https://github.com/abir-taheer/minimum-reproducible-graphql-codegen-interface-fail/tree/main
Steps to Reproduce the Bug or Issue
Most details are mentioned prior
commands to run MRE
Expected behavior
Site should be displaying
But it displays:
Screenshots or Videos
No response
Platform
graphql
version: 16.8.1@graphql-codegen/cli
: "^5.0.0"@graphql-codegen/client-preset
: "^4.1.0"Codegen Config File
Additional context
No response