I have a custom resolver for GraphQL's ID scalar, which sends strings to the client but resolves to integers for the server.
I have tried specifying a custom type inside gql-gen.json, however I still get string inside the generated types.
Is there a way to override the types for default scalars such as ID?
// gql-gen.json
{
"generatorConfig": {
"scalars": {
"ID": "number"
}
}
}
# schema.graphql
type MyType {
id: ID!
}
// types.ts
export interface MyType {
id: string;
}
Could you try to use primitives instead of scalars?
@ardatan Tried as described in packages/graphql-codegen-cli/README.md but has no effect.
// gql-gen.json
{
"primitives": {
"ID": "number"
}
}
Just for good measure, I even tried the following, but still no luck
{
"primitives": {
"ID": "number"
},
"scalars": {
"ID": "number"
},
"generatorConfig": {
"primitives": {
"ID": "number"
},
"scalars": {
"ID": "number"
}
}
}
Could you remove scalars field and only use primitives?
@ardatan That was the first thing I tried. Also tried any other combinations I could think of
@ardatan Minimal repro available here https://github.com/Slessi/gql-gen-primitive-override-repro
Found an issue about CLI's gql-gen.json handling.
Thank you!
For now, we released an alpha version with a fix for this:
Successfully published:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- graphql-codegen-typescript-mongodb-template@0.12.0-alpha.821f12df
- graphql-codegen-typescript-react-apollo-template@0.12.0-alpha.821f12df
- [email protected]
I can confirm that it works for me now with the alpha branch
Done in 0.12.0
Most helpful comment
I can confirm that it works for me now with the alpha branch