This is an optional extension to Joist's codegen logic to generate additional GraphQL-specific output.
The core joist-orm
/etc. is GraphQL/REST/etc. agnostic, but pragmatically much of Joist's development is driven by implementing a TypeScript/Apollo GraphQL service, so this module helps with some of the glue code.
In your joist-codegen.json
add an additional setting:
{
"codegenPlugins": ["joist-graphql-codegen"]
}
This will generate:
-
schema/enums.graphql
with a GraphQL version of each Joist/domain enumFor entities, Joist takes an "arms-length" stance on GraphqL integration, i.e. a GraphQL entity type
Book
will probably match 80% of the Joist domain entity typeBook
, but the last 20% will be bespoke, and so the two need to float independently.This arms-length caution seems less necessary for enums, so
enums.graphql
will contain a one-to-one mapping of GraphQL enums that exactly the domain enums. -
src/resolvers/enumResolvers.ts
includes resolvers for the "enum detail" patternGiven "turn this code into a name" if a frequent operation for frontends, our enum detail pattern allows wrapping each enum with an object type that exposes both the
code
(i.e. the enum value itself) as well as the name (as driven by thename
column in the enum's database table). -
./graphql-codegen-joist.js
containsmappers
andenumValues
config values torequire
into your primarygraphql-codegen.js
file.mappers
declares every entity as a mapped type to its strongly-typed id, i.e.Book: BookId
(which becomes the root type of the entity's resolver).enumValues
tells graphql-code-generator to use the existing/Joist-generatedsrc/entities
enum declarations instead of re-creating its own enums ingraphql-types.ts
.
- Remove the hard-coded file paths like
@src/resolvers
/etc.