graphql-mesh
graphql-mesh copied to clipboard
strictScalars and scalars map for graphql source codegen
Is your feature request related to a problem? Please describe.
I am stitching together several graphql sources. They define custom scalar types, and I would like to be able to tell the codegen process what the equivalent typescript type should be for those scalars via the scalars map as documented here.
I would then additionally like to be able to enable the strictScalars flag so that the build process fails if I haven't provided a Typescript mapping for a scalar.
Describe the solution you'd like
I guess this would make sense in the source config:
sources:
- name: MyGraphQLApi
handler:
graphql:
endpoint: http://my-service-url:3000/graphql
operationHeaders:
Authorization: Bearer {env.MY_API_TOKEN}
scalars:
ScalarTypeA: string
ScalarTypeB: number
strictScalars: true
Describe alternatives you've considered
Leaving it as it is, which applies the type any
to any unknown scalar. This isn't great as it will lead to bugs.
Perhaps it make make things a little more future-proof if the graphql source config block just forwarded a codegen config block onto graphql-codegen directly, e.g.:
sources:
- name: MyGraphQLApi
handler:
graphql:
endpoint: http://my-service-url:3000/graphql
operationHeaders:
Authorization: Bearer {env.MY_API_TOKEN}
codegen:
scalars:
ScalarTypeA: string
ScalarTypeB: number
strictScalars: true
You can add custom codegen config like below;
codegen:
scalars:
...
Hi. That works for the types emitted for the meshed schema, but it doesn't emit config for the source schemas.
e.g. say in my source schema there is scalar DateTime
, if i add:
codegen:
scalars:
DateTime: string
then in the emitted .mesh/index.ts
I get:
// at the top of the file
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
DateTime: string; // <-- looks good
}
// lower down in the file
namespace MySourceTypes {
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
DateTime: any; // <-- uh oh
}
}
If I try to add a codegen
yaml block inside the graphql source block then I get errors about excess properties not being allowed.
For now, it is not possible to configure InContext SDK type generation.