GraphQL/Prisma Client Server Error: Variable '$data' cannot be non input type 'LinkCreateInput!'. (line 1, column 18)
GraphQL/Prisma Client Server Error: Variable '$data' cannot be non input type 'LinkCreateInput!'. (line 1, column 18)
我正在学习如何使用 GraphQL Node.js 教程,并且我在 "Connecting Server and Database with Prisma Bindings" 部分。我想我已经根据教程正确设置了所有内容,但是当我尝试在 GraphQL Playground 中执行 post 突变时,它会抛出此错误:
{
"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"
]
}
]
}
我什至不确定我应该返回什么,但是当我执行 "info" 查询时,我从 index.js 文件中返回了信息:"data":{
"info": "This is the API for the Hacker News clone!, Get Rigth Witcha, imma get ya !!"
}
所以,我知道信息查询正在运行。当我尝试执行 Feed 查询时,我在 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"
]
}
]
}
所以只有 Info 查询有效,其他查询一直发回错误。我很迷茫,我真的很想获得更多 GRaohQL 技能。当我转到我的 Prisma 客户端时,我无法访问我的服务。他们只让我查看我的服务器列表。我有控制台的屏幕截图,但我没有足够的声誉 post 他们提出这个问题。
我已经尝试过每一步并确保我的代码是正确的。我还检查了 HowToGraphql git 存储库,但是他们只有完整的服务器代码,我想从头开始构建我的代码,所以他们的代码没有太大帮助。我不确定问题出在 Prisma Client 还是我的代码上。任何反馈或帮助将不胜感激!!
这是存储库的 link:
https://github.com/thelovesmith/HckrNws-Cln-GrphQL-Srvr
请帮忙!!
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!
}
更新
当我 运行 Prisma Deploy 时,我会收到一条错误消息:
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
}
您的数据模型似乎有错字,应该是 @unique
而不是 @ unique
。
我正在学习如何使用 GraphQL Node.js 教程,并且我在 "Connecting Server and Database with Prisma Bindings" 部分。我想我已经根据教程正确设置了所有内容,但是当我尝试在 GraphQL Playground 中执行 post 突变时,它会抛出此错误:
{
"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"
]
}
]
}
我什至不确定我应该返回什么,但是当我执行 "info" 查询时,我从 index.js 文件中返回了信息:"data":{ "info": "This is the API for the Hacker News clone!, Get Rigth Witcha, imma get ya !!" }
所以,我知道信息查询正在运行。当我尝试执行 Feed 查询时,我在 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"
]
}
]
}
所以只有 Info 查询有效,其他查询一直发回错误。我很迷茫,我真的很想获得更多 GRaohQL 技能。当我转到我的 Prisma 客户端时,我无法访问我的服务。他们只让我查看我的服务器列表。我有控制台的屏幕截图,但我没有足够的声誉 post 他们提出这个问题。
我已经尝试过每一步并确保我的代码是正确的。我还检查了 HowToGraphql git 存储库,但是他们只有完整的服务器代码,我想从头开始构建我的代码,所以他们的代码没有太大帮助。我不确定问题出在 Prisma Client 还是我的代码上。任何反馈或帮助将不胜感激!!
这是存储库的 link: https://github.com/thelovesmith/HckrNws-Cln-GrphQL-Srvr
请帮忙!!
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!
}
更新
当我 运行 Prisma Deploy 时,我会收到一条错误消息:
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
}
您的数据模型似乎有错字,应该是 @unique
而不是 @ unique
。