Hi, I'm trying to get graphql-cli to read my datam...
# orm-help
m
Hi, I'm trying to get graphql-cli to read my datamodel but without success. Below is my Node project structure. I've called the graphql-cli file .graphql.config.yml. My Types are defined in <rootFolder>/prisma/datamodel.graphql. When I execute the command graphql get-schema nothing happens. The content of the graphql.config.yml file is as follows:
projects:
prisma:
schema: '/src/generated/prisma.graphql'
And my datamodel is as follows:
type User {
id: ID! @id
name: String!
email: String! @unique
posts: [Post!]! @relation(link: INLINE)
comments: [Comment!]! @relation(link: INLINE)
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Post {
id: ID! @id
title: String!
body: String!
published: Boolean!
author: User!
comments: [Comment!]! @relation(link: INLINE)
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Comment {
id: ID! @id
text: String!
author: User!
post: Post!
}
Using Docker Compose everyting works fine, the UI at localhost:4466 shows me all the mutations, queries and subscriptions. But I'd like graphql to generate the prisma.graphql which I can pass to the Prisma object in Node here under the /generated folder.:
import { Prisma } from 'prisma-binding';
const prisma = new Prisma({
typeDefs: './generated/prisma.graphql',
endpoint: 'localhost:4466',
});
Any idea as to why it's not working?
p
I assume you’re on prisma 1
m
This is my package.json file
{
"name": "graphql-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/index.js --ext js,graphql --exec babel-node",
"get-schema": "graphql get-schema -p prisma",
"graphql:coverage": "graphql coverage",
"graphql:validate": "graphql validate",
"graphql:diff": "graphql diff",
"graphql:similar": "graphql similar"
},
"author": "",
"license": "ISC",
"dependencies": {
"graphql-yoga": "^1.18.3",
"prisma-binding": "^2.3.16",
"uuid": "^8.2.0"
},
"devDependencies": {
"@babel/cli": "^7.10.3",
"@babel/core": "^7.10.3",
"@babel/node": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"nodemon": "^1.17.5",
"graphql-cli": "4.0.0",
"@graphql-cli/coverage": "2.1.0",
"@graphql-cli/validate": "2.1.0",
"@graphql-cli/diff": "2.1.0",
"@graphql-cli/similar": "2.1.0"
}
}
p
I haven’t used prisma-binding, I use prisma-client-lib and everything looks correct for that
m
How do you use it? I'm new to Prisma
p
try changing your datamodel to .prisma
m
Btw I've made some progress. I've renamed the file to .graphqlconfig.yml and I passed http://localhost:4466 as schema value and now I get the following output from graphqlcoverage info Schema coverage based on documents:
type Query {
users x 0
posts x 0
comments x 0
user x 0
post x 0
comment x 0
usersConnection x 0
postsConnection x 0
commentsConnection x 0
node x 0
}
type User {
id x 0
name x 0
email x 0
posts x 0
comments x 0
createdAt x 0
updatedAt x 0
}
interface Node {
id x 0
}
type Post {
id x 0
title x 0
body x 0
published x 0
author x 0
comments x 0
createdAt x 0
updatedAt x 0
}
type Comment {
id x 0
text x 0
author x 0
post x 0
}
type UserConnection {
pageInfo x 0
edges x 0
aggregate x 0
}
type PageInfo {
hasNextPage x 0
hasPreviousPage x 0
startCursor x 0
endCursor x 0
}
type UserEdge {
node x 0
cursor x 0
}
type AggregateUser {
count x 0
}
type PostConnection {
pageInfo x 0
edges x 0
aggregate x 0
}
type PostEdge {
node x 0
cursor x 0
}
type AggregatePost {
count x 0
}
type CommentConnection {
pageInfo x 0
edges x 0
aggregate x 0
}
type CommentEdge {
node x 0
cursor x 0
}
type AggregateComment {
count x 0
}
type Mutation {
createUser x 0
createPost x 0
createComment x 0
updateUser x 0
updatePost x 0
updateComment x 0
deleteUser x 0
deletePost x 0
deleteComment x 0
upsertUser x 0
upsertPost x 0
upsertComment x 0
updateManyUsers x 0
updateManyPosts x 0
updateManyComments x 0
deleteManyUsers x 0
deleteManyPosts x 0
deleteManyComments x 0
}
type BatchPayload {
count x 0
}
type Subscription {
user x 0
post x 0
comment x 0
}
type UserSubscriptionPayload {
mutation x 0
node x 0
updatedFields x 0
previousValues x 0
}
type UserPreviousValues {
id x 0
name x 0
email x 0
createdAt x 0
updatedAt x 0
}
type PostSubscriptionPayload {
mutation x 0
node x 0
updatedFields x 0
previousValues x 0
}
type PostPreviousValues {
id x 0
title x 0
body x 0
published x 0
createdAt x 0
updatedAt x 0
}
type CommentSubscriptionPayload {
mutation x 0
node x 0
updatedFields x 0
previousValues x 0
}
type CommentPreviousValues {
id x 0
text x 0
}
Can I just copy this content into the prisma.graphql file you think?
p
I’ve never seen something like that
I would change your original file from prisma.graphql to prisma.prisma
and then change the datamodel in the prisma.yml to prisma.prisma
m
OK I'll try that
Which command shall I run after that?
p
prisma deploy && prisma generate
unless you have post deploy hook in ur prisma.yml file
m
I've already run prisma deploy
Everything is in the database and I can interact with the database from the client at localhost:4466. I just need to generate this file for the Node config. I'll try prisma generate
p
you’ll have to run it again every time you update the datamodel
m
I get this: prisma deploy && prisma generate Deploying service
default
to stage
default
to server
local
491ms Service is already up to date.
But I don't see any generated files
I got it to work
p
Thas good
what u do
Just wish someone would respond to my question lol
m
First I moved the prisma.yml file under the same folder as the prisma config file. Then I changed it as follows:
endpoint: <http://localhost:4466>
datamodel: ./prisma/datamodel.graphql
databaseType: document
generate:
- generator: graphql-schema
output: ./src/generated/prisma.graphql
hooks:
post-deploy:
- prisma generate
p
nice
m
And that created a file as long as an arm lol
p
yup
then ur all set
u using mongoDB i see
it took me forever to figure out that you had to set databaseType: document
m
I used a utility who did it for me lol
Don't ask my which because I don't remember haha
I've just answered some questions and it generated everything for me
I'm using Mongo Atlas
p
Oh nice. I literally couldn’t find it in the docs so I went into the prisma cli code and figured it out
noice
yeah i wish they had mongo db in prisma 2
I don’t think migration will be too tricky though
m
Did they say anything about it?
p
No, I mean mongoDB is rewriting their driver in rust so that it’s compatibke with prisma 2, but the way it’s looking you’d just change the datamodel and a few set up things, but interacting with prisma would prob remain the same
m
Hope so. Prisma+Mongo is an awesome combination
I've tried Postgresql and I ran away lol
Plus prisma generates all returns in JSON, Mondo is the perfect db for it
p
Yeah, I mean relational stuff is good for a lot of usecases but a lot of modern day apps need documents,
m
Yes the modern stack is all based around documents
OK, I'm logging off now. Burning the candle at both ends. Good night and good luck with your question
And thank you for your help
p
Haha i figured it out, authorization is different for subscriptions than regular requests I think
np see ya