我需要帮助找出与 Apollo Client 一起使用的 GraphQL 标签。文档并没有超出最基本的突变用例。
我的目标是让唯一需要的输入是电子邮件。如果存在其他变量,我希望这些变量被接受并创建一个包含所有这些信息的提案。
我有突变(仅在电子邮件和完整变量场景中)在 GraphQl Playground 上成功运行(如果有帮助,您可以在此处找到并对其进行测试,查看架构等):https://prisma2 -graphql-yoga-shield.now.sh/playground)
mutation {
createOneProposal(
data: {
email: "fake@gmail.com"
name: "Sean"
types: {
create: {
model: PURCHASE
name: "e-commerce"
cost: 600
services: {
create: [
{ service: "Responsive web design" }
{ service: "Another service!" }
{ service: "And yet another service!" }
]
}
}
}
}
) {
created_at
proposal_id
types {
cost
model
name
type_id
services {
service
service_id
}
}
}
}
结果产生:
{
"data": {
"createOneProposal": {
"created_at": "2020-02-27T21:28:53.256Z",
"proposal_id": 35,
"types": [
{
"cost": 600,
"model": "PURCHASE",
"name": "e-commerce",
"type_id": 6,
"services": [
{
"service": "Responsive web design",
"service_id": 10
},
{
"service": "Another service!",
"service_id": 11
},
{
"service": "And yet another service!",
"service_id": 12
}
]
}
]
}
}
}
我对 gql 标签的初始设计:
export const NEW_PROPOSAL = gql`
mutation createOneProposal(
$email: String!
$name: String
$cost: Int
$model: Model
$service: Service
) {
createOneProposal(
email: $email
name: $name
cost: $cost
model: $model
service: $service
) {
created_at
proposal_id
types {
services {
service_id
}
}
}
}
`;
但是,我对此有很多错误。
{"errors":[
{"Variable "$service" cannot be non-input type `"Service`".","locations":[{"line":1,"column":97}]},
{"Unknown argument "email" on field "createOneProposal`" of type "Mutation`".","locations":[{"line":2,"column":21}]},
{"Unknown argument "name" on field "createOneProposal`" of type "Mutation`".","locations":[{"line":2,"column":36}]},
{"Unknown argument"cost" on field "createOneProposal\" of type "Mutation`".","locations":[{"line":2,"column":49}]},
{"Unknown argument "model" on field "createOneProposal`" of type "Mutation`".","locations":[{"line":2,"column":62}]},
{"Unknown argument "service" on field "createOneProposal`" of type "Mutation`".","locations":[{"line":2,"column":77}]},
{"Field "createOneProposal" argument "data" of type "ProposalCreateInput!`" is required, but it was not provided.","locations":[{"line":2,"column":3}]}]}
那么,我该怎么做...我想出了查询版本(容易得多...),但我就是想不通!
我的架构,如果有帮助的话:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("MYSQL_URL_PRISMA2")
}
model Post {
content String @default("")
created_at DateTime @default(now())
post_id Int @default(autoincrement()) @id
published Boolean @default(false)
published_at DateTime?
title String @default("")
author User
}
model Profile {
bio String?
profile_id Int @default(autoincrement()) @id
user_id User
}
model Proposal {
email String @unique
name String?
proposal_id Int @default(autoincrement()) @id
created_at DateTime @default(now())
types Type[]
}
model Type {
cost Int?
name String?
model Model? @default(SUBSCRIPTION)
services Service[]
type_id Int @default(autoincrement()) @id
proposal_id Proposal
}
model Service {
service_id Int @default(autoincrement()) @id
service String?
type_id Type
}
model User {
email String @default("") @unique
name String @default("")
password String @default("")
role Role @default(USER)
user_id Int @default(autoincrement()) @id
posts Post[]
profiles Profile[]
}
enum Role {
USER ADMIN
}
enum Model {
SUBSCRIPTION PURCHASE CUSTOM
}