Reputation: 639
I am following the How To GraphQL Node.js tutorial and I am at the part "Connecting Server and Database with Prisma Bindings". I think I have everything set up correctly according to the tutorial but when I try to execute a post mutation in the GraphQL Playground it throws this error:
{
"data": null,
"errors": [
{
"message": "Variable '$data' cannot be non input type 'LinkCreateInput!'. (line 1, column 18):\nmutation ($data: LinkCreateInput!) {\n ^",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"post"
]
}
]
}
I'm not even sure what I should be getting back, but when I do the "info" query I get back the info from my index.js file: "data": { "info": "This is the API for the Hacker News clone!, Get Rigth Witcha, imma get ya !!" }
So, I know that the info query is working. When I try to do the Feed query I get back this error in the GraphQl playground:
{
"data": null,
"errors": [
{
"message": "Cannot query field 'links' on type 'Query'. (line 2, column 3):\n links {\n ^",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"feed"
]
}
]
}
So only the Info query is working and the others keep sending back an error. I am so lost and I really want to get more skill with GRaohQL. When I go to my Prisma Client I can't access my Service. They only let me look at the list of my servers. I have screenshots of the console but I do not have enough reputation to post them with this question.
I have tried going over each step and making sure my code is correct. I've also checked out the HowToGraphql git repository however they only have the completed server code present and I would like to build mine from the ground up so their code isn't much help. I'm not sure if the problem is with the Prisma Client or my code. Any feedback or assistance would be greatly appreciated!!
Here is the link to the repository: https://github.com/thelovesmith/HckrNws-Cln-GrphQL-Srvr
Please help!!
src/index.js:
const { GraphQLServer } = require('graphql-yoga')
const { prisma } = require('./generated/prisma-client/index')
// Revolvers
const resolvers = {
Query: {
info: () => 'This is the API for the Hacker News clone!,
Get Rigth Witcha, imma get ya !!' ,
feed: (root, args, context, info) => {
return context.prisma.links()
}
},
Mutation: {
post : (root, args, context) => {
return context.prisma.createLink({
url: args.url,
description: args.description,
})
}
},
}
//Server
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
//initializing context object that is being passed to each
resolver
context: { prisma },
})
server.start(() => console.log('Server is running on
http://localhost:4000'))
schema.graphql:
type Query {
info: String!
feed: [Link!]!
}
type Mutation {
post(url: String!, description: String!): Link!
}
type Link {
id: ID!
description: String!
url: String!
}
prisma.yml:
# The HTTP endpoint for your Prisma API
#endpoint: ''
endpoint: https://us1.prisma.sh/avery-dante-hinds/hckrnws/dev
# Points to the file that contains your datamodel
datamodel: datamodel.prisma
# Specifies language & location for the generated Prisma client
generate:
- generator: javascript-client
output: ../src/generated/prisma-client
datamodel.prisma:
type Link {
id: ID! @ unique
createdAt: DateTime!
description: String!
url: String!
}
When I run Prisma Deploy I can an error message:
ERROR: Syntax error while parsing GraphQL query. Invalid input "{
\n id: ID! @ ", expected ImplementsInterfaces, DirectivesConst or
FieldDefinitions (line 1, column 11):
type Link {
^
{
"data": {
"deploy": null
},
"errors": [
{
"locations": [
{
"line": 2,
"column": 9
}
],
"path": [
"deploy"
],
"code": 3017,
"message": "Syntax error while parsing GraphQL query. Invalid
input \"{ \\n id: ID! @ \", expected ImplementsInterfaces,
DirectivesConst or FieldDefinitions (line 1, column 11):\ntype Link {
\n ^",
"requestId": "us1:cjr0vodzl2ykt0a71zuql5544"
}
],
"status": 200
}
Upvotes: 3
Views: 2082
Reputation: 22731
It seems like you have a typo in your datamodel, it should be @unique
instead of @ unique
.
Upvotes: 3