Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strictScalars and scalars map for graphql source codegen #3508

Open
leemhenson opened this issue Jan 20, 2022 · 4 comments
Open

strictScalars and scalars map for graphql source codegen #3508

leemhenson opened this issue Jan 20, 2022 · 4 comments

Comments

@leemhenson
Copy link

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.

@leemhenson
Copy link
Author

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

@ardatan
Copy link
Owner

ardatan commented Mar 13, 2022

You can add custom codegen config like below;

codegen:
  scalars:
    ...

@leemhenson
Copy link
Author

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.

@ardatan
Copy link
Owner

ardatan commented Mar 16, 2022

For now, it is not possible to configure InContext SDK type generation.

@Urigo Urigo mentioned this issue Aug 11, 2022
22 tasks
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants