Prisma v2: generate a .graphql file to edit with?

Viewed 1028

I'm building a graphql server (with apollo-server) on an existing postgresql db (I cannot modify the db tables).

Prisma can introspect the db and generate a schema.prisma file containing all db tables. To implement the graphql server, I need to define graphql types and queries and mutations manually.

With Prisma v1, this prisma.yml can generate a graphql file.

generate:
  - generator: graphql-schema
  output: ./generated/prisma.graphql

For Prisma v2, is there any way to generate a graphql file from schema.prisma?

Then I can modify the graphql file by removing some types that do not needed to be exposed to front, and create queries and mutations by myself.

2 Answers

prisma2 is an orm unlike prisma1 so you can use the nexus-plugin-prisma library to autogenerate your GraphQL types and resolvers from the Prisma schema

Prisma 2 is just an ORM unlike Prisma 1 that had a GraphQL layer. So you would need external libraries like this to autogenerate a GraphQL file. You can check out TypeGraphQL that does this.

Related