nexus-plugin-prisma: Property 'crud' does not exist on type 'ObjectDefinitionBlock<"Query">'

Hi Prisma Team, love the product and trying to work through some Proof-of-Concepts. I hope this isn’t a stupid question, but I can’t seem to generate t.crud using prisma2 generate.

I’m following this guide on Database Access with Prisma 2, but I hit the following error message:

Using ts-node version 8.3.0, typescript version 3.5.2
[ERROR] 12:47:51 ⨯ Unable to compile TypeScript:
src/index.ts:16:7 - error TS2339: Property 'crud' does not exist on type 'ObjectDefinitionBlock<"Query">'.

16     t.crud.findOneFoo();

Both Photon and Nexus appear to have generated successfully after prisma2 generate, but crud is simply not available on the generated Nexus type/library.

The minimal example of my code is as below. Would really appreciate any insight into whats going on with this.

Thanks in advance!

./package.json

{
  "devDependencies": {
    "ts-node": "^8.3.0",
    "ts-node-dev": "^1.0.0-pre.40",
    "typescript": "^3.5.2"
  },
  "scripts": {
    "start": "ts-node-dev ./src/index.ts"
  },
  "dependencies": {
    "@prisma/nexus": "0.0.1",
    "graphql": "^14.4.2",
    "graphql-yoga": "^1.18.1",
    "nexus": "^0.12.0-beta.6",
    "nexus-prisma": "^0.3.7"
  }
}

./prisma/schema.prisma

datasource db {
  provider = "mysql"
  url      = "mysql://..."
}

generator photon {
  provider = "photonjs"
}

generator nexus_prisma {
  provider = "nexus-prisma"
}

...[INTROSPECTED MODELS HERE]

./src/index.ts

import { nexusPrismaPlugin } from "@generated/nexus-prisma";
import Photon from "@generated/photon";
import { makeSchema, objectType } from "@prisma/nexus";
import { GraphQLServer } from "graphql-yoga";
import { join } from "path";

const photon = new Photon();

const nexusPrisma = nexusPrismaPlugin({
  photon: (ctx) => ctx.photon,
});

const Query = objectType({
  name: "Query",
  definition(t) {
    t.crud.findOneFoo();
  },
});

const schema = makeSchema({
  types: [Query, nexusPrisma],
  outputs: {
    typegen: join(__dirname, "../generated/nexus-typegen.ts"),
    schema: join(__dirname, "/schema.graphql"),
  },
  typegenAutoConfig: {
    sources: [
      {
        source: "@generated/photon",
        alias: "photon",
      },
      {
        source: join(__dirname, "types.ts"),
        alias: "ctx",
      },
    ],
    contextType: "ctx.Context",
  },
});

const server = new GraphQLServer({
  schema,
  context: { photon },
});

server.start(() => console.log(`🚀 Server ready at http://localhost:4000`));

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 14
  • Comments: 22 (6 by maintainers)

Most upvoted comments

I finally got the types to work. outputs is expecting an absolute path so I used:

outputs: {
    typegen: join(__dirname, '/generated/nexus.ts'),
    schema: join(__dirname, '/generated/schema.graphql'),
  },

After making sure they were generated when running ts-node-dev, I added import to the top of my index.ts:

import './generated/nexus'

I could then build with tsc

This is still not working for me.

I’m still getting the same error:

Property 'model' does not exist on type 'ObjectDefinitionBlock<"User">'.

Even with latest deps.

At this point I’m not even sure if I’m making mistakes or this doesn’t work right now so please point me at something which definitely works.

I am following the same guide and getting the same t.crud errors plus some t.model errors.

@iamandyk I personally like namespaces (ala Go) but for the data part (graphql type defs) its just a convenient pattern. For yourself, do as you please 😃