Describe the bug
Custom scalars inside a fragment are turned into any when preResolveTypes: true
To Reproduce
Check live: https://codesandbox.io/s/elegant-haibt-30ppy
Steps to reproduce the behavior:
scalar Date
type Query {
user(id: ID!): User!
}
type User {
id: ID!
username: String!
email: String!
createdAt: Date!
}
query user {
user(id: 1) {
...UserFragment
}
}
fragment UserFragment on User {
username
email
createdAt
}
codegen.yml config file:schema: schema.graphql
documents: document.graphql
generates:
types.ts:
plugins:
- typescript:
scalars:
Date: string
- typescript-operations:
preResolveTypes: true
Expected behavior
UserFragmentFragment['createdAt'] should be Scalars['Date'], but it is any
Environment:
@graphql-codegen/...:
"@graphql-codegen/cli": "^1.17.10",
"@graphql-codegen/typescript": "^1.17.10",
"@graphql-codegen/typescript-operations": "^1.17.8",
NodeJS: 12.16.1
@CarlosGines you are using the per-plugin configuration, so scalars config is only available for typescript plugin and not for the typescript-operations.
Please use:
schema: schema.graphql
documents: document.graphql
generates:
types.ts:
config:
scalars:
Date: string
plugins:
- typescript
- typescript-operations:
preResolveTypes: true
This happens even when the config is outside the plugin
@cevr just noticed it, re-opening. Thanks
@cevr it did work for me, the issue was solved following his suggestion.
@dotansimha thank you very much!
@CarlosGines yeah you are right, rerunning worked, it guess it was something with the sandbox. Closing :)
@cevr if you are still having issues with that, can you please report a new issue, with a reproduction? Thanks!
Ah okay I see the problem,
My use case was that in a monorepo, I had one repo that held the schema types, and one repo that held the operations and apollo hooks.
I only declared the scalars in the schema type repo, but hadn't declared them in the other.
Declaring the scalars on both configs fixed the issue.
@dotansimha if the import-types preset is used, should it attempt to import before defaulting to any if no scalars are present in the config?
EDIT: here's a sandbox simulating the issue: https://codesandbox.io/s/suspicious-sound-9v0on?file=/codegen.yml
scalars should be under config. Maybe that's the problem;
See;
https://codesandbox.io/s/purple-wave-v08j9?file=/codegen.yml
Most helpful comment
@cevr it did work for me, the issue was solved following his suggestion.
@dotansimha thank you very much!