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!
{
"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"
}
}
datasource db {
provider = "mysql"
url = "mysql://..."
}
generator photon {
provider = "photonjs"
}
generator nexus_prisma {
provider = "nexus-prisma"
}
...[INTROSPECTED MODELS HERE]
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`));
Also, FYI: prisma2 --version shows:
[email protected], binary version: 30a33bde5b1d9f79e0a48491749528da76002e24
Any luck with this?
I am following the same guide and getting the same t.crud errors plus some t.model errors.
In my understanding the type definitions are created when you run makeSchema (into generated/nexus-typegen.ts. Once the type definitions are there, the errors should disappear.
I can confirm that starting the server/running makeSchema on a starter project doesn't get rid of this error for me.
However- the code still works fine, it's just the types that aren't working.
I looked at some of the typescript examples from photonjs.prisma.io and I was able to get things working with ts-node-dev although I am still getting crud and model errors when I run ts-node or tsc; running on preview 5.
Success in:
"nexus": "0.11.7"
and
"ts-node-dev": "^1.0.0-pre.40",
Fails in
"nexus": "^0.12.0-beta.6"
or
"ts-node": "8.3.0"
i have the same issue.
You can try running the schema only with the nexusPrisma type. Add more types like Query afterward, when the typegen and schema was generated once.
const schema = makeSchema({
types: [nexusPrisma],
...
})
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
Hey @robmurtagh, this should be working now. Update your deps. You can see a working example in this repo under /example
Ref https://github.com/prisma/nexus-prisma/issues/367#issuecomment-526921529.
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.
Same here :
"dependencies": {
"@types/node": "^12.7.12",
"graphql": "^14.5.8",
"graphql-yoga": "^1.18.3",
"nexus": "^0.12.0-beta.14",
"nexus-prisma": "^0.5.0"
},
// package.json
import { makeSchema } from 'nexus'
import { nexusPrismaPlugin } from 'nexus-prisma'
import * as types from './types'
import { join } from 'path'
export const schema = makeSchema({
types: [types, nexusPrismaPlugin({ types })],
// prettierConfig: join(__dirname, '../../.prettierrc.json'),
outputs: {
schema: join(__dirname, '/generated/schema.graphql'),
typegen: join(__dirname, '/generated/nexus.ts'),
},
})
//schema.ts
I'm still getting this error:
Property 'model' does not exist on type 'ObjectDefinitionBlock<"Profile">'
Hey @poulainv, looks like you're using the legacy config pattern. Try referring to the current examples to aid your debugging.
You're right, I did not see the breaking changes. My bad. 🙏
All good, let me know if any troubles arise, it is still not as easy as it should be (we're working on it 😄).
Yep but when it works, dev exp is awesome ;)
And.. for now, it works well locally but when I've deployed it on heroku I got the same error 😅
@poulainv I'll setup an example for heroku soon, but for now see if the reference docs are enough: https://github.com/prisma-labs/nexus-prisma#project-setup. It actually mentions Heroku heh.
In my case the issue was misconfigured types field in tsconfig compilerOptions.
Hey @alexichepura you might be interested in https://github.com/prisma-labs/nexus/issues/284 & https://github.com/prisma-labs/nexus-cli/issues/2.
@jasonkuhrt is there a reason why you are using the import * syntax for all imports?
import * as Nexus from 'nexus'
import { nexusPrismaPlugin } from 'nexus-prisma'
import * as Query from './Query'
import * as Mutation from './Mutation'
import * as Blog from './Blog'
import * as Post from './Post'
import * as User from './User'
import * as path from 'path'
@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 :)
Most helpful comment
I finally got the types to work. outputs is expecting an absolute path so I used:
After making sure they were generated when running
ts-node-dev, I added import to the top of my index.ts:I could then build with
tsc