Search code examples
typescriptgraphqlprismaprisma-graphql

Typescript/Prisma: Can't Generate CRUD Operations with Custom Resolvers


Problem

I'm new to Prisma, and I just followed a few tutorials to get my database hosted locally via Docker. (I'm using Typescript as my language).

I've written a few custom resolvers for user creation in separate files (my file structure is as follows), and I am trying to access these resolvers on my server endpoint after I deploy my server using prisma deploy.

File Structure:
---
- graphql-schema
  - prisma.graphql  <-- where my schema is defined
- prisma
  - ...
- prisma-client-js
  - ...
- prisma-client-ts
  - ...
- src
  - generated
  - resolvers       <-- where my custom resolvers
- datamodel.prisma  <-- where my data models are defined
- package.json
- prisma.yml
- tsconfig.json
- yarn.lock

After deployment onto localhost, all of the createModel, updateModel, etc. operations are generated for each of my datamodels, but my signUp and logIn functions aren't.

Question

Is it possible to deploy my GraphQL server with both CRUD operations and custom resolvers? If so, how? I'm using Prisma 1.26.

Thanks in advance.


Solution

  • Yes, you can expose with of these operations. Just import the prisma ones from the prisma.graphql file using graphql-import and define them in the resolvers. https://github.com/prisma/graphql-import

    Here is an example project using this approach: https://github.com/javascript-af/javascript-af/blob/master/packages/backend/src/schema.graphql

    There is also new project which simplifies this process quite a lot: https://github.com/prisma/nexus-prisma