-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate types for the "app" part #273
Comments
Would it work like this ? in app:
schemaPath: src/schema.graphql
includes: ["**/*.graphql"]
extensions:
endpoints:
default: ${env:API_PROTOCOL}://${env:API_HOST}:${env:API_PORT}
codegen:
- generator: prisma-binding
language: typescript
output:
binding: src/generated/api.ts then reference api-side types in resolvers with Would not it be cleaner and less dependencies ? |
@Sharlaan, I'll surely give it a shot! |
@degroote22 nice help! It looks like using the newest version of
gql-gen --require ts-node/register --template typescript -s ./src/schema.graphql --out ./src/typings/ |
I'm currently using graphql-code-generator to generate types for the "app" part of the code and the experience is awesome.
It gives me the types for the public api which I can export for the front-end and use on the server code itself.
With these dependencies:
We need to join the schemas because of this kind of modular graphql schema used with prisma,
so we create src/importSchema.ts
Automate it in prisma.yml:
or package.json
and we can use the types like so, in Query.ts (strict Typescript 👍 )
This approach should be added here, like this or with apollo-codegen (which I couldn't get to work like this). It helped me catch a bug on the prisma docs where they have a mutation like this on the app side:
implemented like this
against a DB structured like this
So at app level "content" was optional. At DB level it wasn't. The typescript compiler wouldn't warn if I hadn't taken this approach.
Also, in this project, if we remove a "!" from a type or argument at app level the compiler won't catch this regression unless we generate the types.
The text was updated successfully, but these errors were encountered: