prisma-labs / graphqlgen

⚙️ Generate type-safe resolvers based upon your GraphQL Schema
MIT License
818 stars 54 forks source link

Configure GraphQL scalar mapping #165

Open schickling opened 6 years ago

schickling commented 6 years ago

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 commented 6 years ago

Looks like this might land soon: https://github.com/facebook/graphql/pull/521

mariusmarais commented 5 years ago

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 commented 5 years ago

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?