Open jakubmazanec opened 3 years ago
Hi @jakubmazanec and thank you for the report!
Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.
It seems like we are on stage 0
.
Now in order to advance to stage 1
we'll need an easily running reproduction, do you think you can create that on code sandbox?
Thank you and sorry that this comment is not a complete solution (yet).
Here is GitHub repo: https://github.com/jakubmazanec/graphql-codegen-import-types-preset
npm install
npm run codegen
File output/operations.ts
, lines 55-65 should show the issue.
Is this ok for reproduction? Thanks for finding time to look at this.
I think initially this was intended to be typescript
+ typescript-operations
in one file, and then typescript-react-apollo
in another file with that preset, this way all types are prefixed. So this might be a use-case that isn't fully supported yet... PRs are always welcome!
In my use, typescript-operations
is generated based on the consumer query definitions, so it makes more sense for it to be colocated with typescript-react-apollo
. Whereas typescript
is generated solely from the GQL Schema. A solution to this issue would be helpful for me
This problem still exists
This problem still exists
It seems
import-types
preset adds "Types." prefix to all types, regardless if they actualy need to be imported.Codegen config:
Types for the schema (i.e. those generated by
typescript
plugin) and the schema itself are in package @foo/graphql-schema. Code generated bytypescript-operations
is ok, it contains typed GraphQL operations specified inqueries.graphql
and uses types imported from@foo/graphql-schema
. But the code generated bytypescript-react-apollo
also tries to import stuff - but it shouldn't, as types for queries are defined right next to it, e.g.:For now I think I solved it by splitting the generation in two steps, first generate types for operations, and then generate Apollo hooks using
import-plugin
once again, but importing the types generated in the first step - I assume that it's okay, becausetypescript-react-apollo
doesn't actually need the schema types?