gpt4 book ai didi

graphql - 变量 '$_data' 不能是 Prisma GraphQL 突变中的非输入类型

转载 作者:行者123 更新时间:2023-12-02 16:02:55 24 4
gpt4 key购买 nike

我将 Prisma 与 GraphQL 结合使用,但在运行变异时出现错误。我成功部署了 prisma 并将其与本地 graphQL 绑定(bind)。

-- datamodel.graphql - prisma 设置

type Link {
id: ID! @unique
description: String!
url: String!
postedBy: User
}

type User {
id: ID! @unique
name: String!
email: String! @unique
password: String!
links: [Link!]!
}

-- schema.graphql - 本地设置

# import Link from "./generated/prisma.graphql"
type Query {
info: String!
feed: [Link!]!
}

type Mutation {
post(url: String!, description: String!): Link!
signup(email: String!, password: String!, name: String!): AuthPayload
login(email: String!, password: String!): AuthPayload
}

type AuthPayload {
token: String
user: User
}

type User {
id: ID!
name: String!
email: String!
links: [Link!]!
}

注册突变的解析器是

async function signup(parent, args, context, info) {
// 1
const password = await bcrypt.hash(args.password, 10)
// 2
const user = await context.db.mutation.createUser({
data: { ...args, password },
}, `{ id }`)

// 3
const token = jwt.sign({ userId: user.id }, APP_SECRET)

// 4
return {
token,
user,
}
}

这是 .graphqlconfig.yml 内容

projects:
app:
schemaPath: src/schema.graphql
extensions:
endpoints:
default: http://localhost:4000
database:
schemaPath: src/generated/prisma.graphql
extensions:
prisma: database/prisma.yml

我运行的 GraphQL 查询是。

mutation {
signup(
name: "Alice"
email: "alice@graph.cool"
password: "graphql"
) {
token
user {
id
}
}
}

当我运行这个时得到的响应是

{
"data": {
"signup": null
},
"errors": [
{
"message": "Variable '$_data' cannot be non input type 'UserCreateInput!'. (line 1, column 19):\nmutation ($_data: UserCreateInput!) {\n ^",
"locations": [],
"path": [
"createUser"
]
}
]
}

我找不到原因。

谢谢。

最佳答案

尝试使用 prisma deploy --force

这对我有用。

关于graphql - 变量 '$_data' 不能是 Prisma GraphQL 突变中的非输入类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50091924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com