GraphQL and typegen
The application uses GraphQL for communication. The build pipeline goes as follow:
-
The
Dialogportenproject publishes the npm package @digdir/dialogporten-schma any time the schema changes. The package includes the raw graphql schema converted into a JavaScript file that exports it as a string and export the from the package. -
We add the @digdir/dialogporten-schema npm package as a dependency to our project
bff. -
In the
bffapplication we define our own GraphQL schema code-first, then we stitch it together with the schema we get fromDialogporten -
In
bff-types-generatedwe import the stitched schema frombff-
Then we define GraphQL queries and fragment queries that the frontend need in
./packages/bff-types-generated/queries -
And then generate TypeScript types from the GraphQL schema as well as functions from the GraphQL queries
-
Only GraphQL types that we have defined a queries/fragment-queries for will actually be generated
-
-
In the
frontendwe import thebff-types-generatedpackage and have ready types and functions that we can use in the frontend
Developmentβ
When dialogporten releases new schema versionsβ
-
Update the package version in
dialogporten-types-generatedbased on the newest verison -
Check for schema changes using npmdiff.dev and see if there is any breaking changes
-
Rebuild the project to ensure that there are no new build problems
Caveatsβ
Currently there are no dev tasks that watches for changes setup in dialogporten-types-generated and bff-types-generated so you may need to rebuild the whole project if you do one of the followign changes:
-
Change the schema definitions in the
bff. Thebffitself will hot-reload but not the rest. -
Change or write new Graph queries (and fragment queris) in
bff-types-generated
TODO: using turborepo setup dev tasks and Docker watch statements for all of this so that it all rebuilds autoamtically