'Types Of Property Are Incompatible' In GraphQL CodeGen

GraphQL

23/01/2023


If you use GraphQL CodeGen to generate your types and Prisma on the backend, you will eventually come accross the following error due to a divergence in resolver types.

BASH
Types of property 'X' are incompatible.
Type 'import("...").X' is not assignable to type 'import(".../resolvers-types").X'.

To avoid this divergence, you will need to map your generated Prisma types to your defined GraphQL schema types. To accomplish this, add the following config properties in your CodeGen file.

codegen.yml
YML
generates:
./generated/resolvers-types.ts:
plugins:
- typescript
- typescript-resolvers
config:
mapperTypeSuffix: Model
mappers:
X: "@prisma/client#X"

Under mappers, assign each GraphQL schema type its Prisma equivalent, e.g. User: "@prisma/client#User".

mapperTypeSuffix helps us avoid name collisions 💥 between your GraphQL and generated Prisma types.


WRITTEN BY

Code and stuff