GraphQL and typegen
The application uses GraphQL for communication. The build pipeline goes as follow:
-
The
Dialogporten
project 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
bff
application we define our own GraphQL schema code-first, then we stitch it together with the schema we get fromDialogporten
-
In
bff-types-generated
we 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
frontend
we import thebff-types-generated
package 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-generated
based 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
. Thebff
itself 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