GraphQL/Prisma 客户端服务器错误:变量'$data'不能是非输入类型"LinkCreateInput!"。(第 1 行,第 18 栏)



我正在学习How To GraphQL Node.js教程,我正在学习"使用Prisma Bindings连接服务器和数据库"部分。我认为我已经根据教程正确设置了所有内容,但当我试图在GraphQL Playground中执行后突变时,它会抛出以下错误:

{
"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"
]
}
]
}

我甚至不确定我应该得到什么,但当我进行"信息"查询时,我会从我的index.js文件中得到信息:"数据":{"信息":"这是黑客新闻克隆的API!获取Rigth Witcha,ima获取ya!!"}

所以,我知道信息查询正在工作。当我尝试执行Feed查询时,我在GraphQl操场上得到了这个错误:

{
"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客户端时,我无法访问我的服务。他们只允许我查看服务器列表。我有控制台的截图,但我没有足够的声誉来发布这个问题。

我已经尝试过每一步,并确保我的代码是正确的。我也检查了HowToGraphql git存储库,但他们只有完整的服务器代码,我想从头开始构建我的代码,所以他们的代码没有多大帮助。我不确定问题是Prisma客户端还是我的代码。如有任何反馈或帮助,我们将不胜感激!!

以下是指向存储库的链接: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!
}

棱镜.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