Relay-compiler-language-typescript: Define ts types for scalars

Created on 15 Jan 2020  路  2Comments  路  Source: relay-tools/relay-compiler-language-typescript

Hello folks
Since recently, graphql unknown scalars are compiled into ts unknown type. This makes sense, but at the same time introduces a lot of annoying casts in the code whenever one needs to use one of these fields...
Is there a way to configure which ts type a given scalar should be compiled into ?

Most helpful comment

You can use the customScalars feature of the relay compiler (either in the CLI or using the relay-config npm package) to define this. As an example here's a snippet of the config we use (in relay.config.js)

    customScalars: {
        BigInt: 'String',
        DateTime: 'String',
        LocalDate: 'String',
        LocalDateTime: 'String',
        Percent: 'Int',
        Probability: 'Int',
    },

Note that you must map the scalars to known graphql scalar types.

All 2 comments

You can use the customScalars feature of the relay compiler (either in the CLI or using the relay-config npm package) to define this. As an example here's a snippet of the config we use (in relay.config.js)

    customScalars: {
        BigInt: 'String',
        DateTime: 'String',
        LocalDate: 'String',
        LocalDateTime: 'String',
        Percent: 'Int',
        Probability: 'Int',
    },

Note that you must map the scalars to known graphql scalar types.

Thanks, exactly what I was looking for 馃憤

Was this page helpful?
0 / 5 - 0 ratings