Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Configure GraphQL scalar mapping #165

Open
schickling opened this issue Oct 20, 2018 · 3 comments
Open

Configure GraphQL scalar mapping #165

schickling opened this issue Oct 20, 2018 · 3 comments

Comments

@schickling
Copy link
Contributor

schickling commented Oct 20, 2018

While GraphQL SDL doesn't yet support an expressive enough syntax for scalar value definitions, there is some mapping needed for custom scalars (e.g. DateTime in GraphQL SDL should map to string in TypeScript). This mapping is depending on the application's implementation and therefore needs to be configured in the graphqlgen.yml.

Here is a proposal for the configuration format:

scalars:
  DateTime: string

Additionally, we should extend the validation logic of graphqlgen (similar to how types <> models are validated) to always require a mapping for custom scalars.

@schickling
Copy link
Contributor Author

Looks like this might land soon: graphql/graphql-spec#521

@mariusmarais
Copy link

mariusmarais commented Dec 7, 2018

Is there any advice for what to do in the meantime? I'm not sure where to go next.

Does this mean my app has to serialize to / deserialize from string manually in the resolvers for now or is there some other workaround?

[EDIT:] Defining your own resolvers coupled with resolvers as any is your friend.

@bent-sportsbet
Copy link

bent-sportsbet commented Apr 24, 2019

Given that this doesn't seem to have moved forward yet, as an interim measure I'm wondering how useful it would be to have options similar to apollo client:codegen's passthroughCustomScalars and customScalarsPrefix? In the case of TypeScript at least, it's then easy enough to declare a global type definition for the scalar type name (with the option of attaching the prefix to avoid clashes with other global names). This approach has worked successfully for me with the output of apollo client:codegen. Worth creating a PR for?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants