Using GraphQL Code Generator to generate types and client code against an existing GraphQL backend.
- Backend server is not directly usable in client code, because (choose any that apply)
- it is external, maintained by another team/organisation
- it is in a separate repo
- it is written in another language
- Maintaining typings in multiple codebases violates DRY
- when backend changes client breaks without indication
- Generate typings and client code automatically against a backend server
- Type checking can be used to break the client build/CI/tests when backend schema changes
Setup
yarn ; yarn lerna bootstrap ; yarn build
Start client at http://localhost:4000
yarn start
Update typings (while server running):
yarn codegen
Check for type errors (you'd run this in CI with tests):
yarn type-check