[英]I try get args array from the mutation. And i still get [Object: null prototype]
I try to type server by Apollo
server, Prisma
and Mongodb
.我尝试通过
Apollo
服务器、 Prisma
和Mongodb
输入 server 。 I got to the stage when trying to test API for mutation by playground
.当我尝试通过 Playground 测试
playground
的突变时,我到了舞台。 I want to make a field with images URL but when I type mutation to the playground then got this mutation and error from the playground and when I try to print args to the console I got this我想用图像 URL 制作一个字段,但是当我在操场上输入突变时,然后从操场上得到这个突变和错误,当我尝试将 args 打印到控制台时,我得到了这个
{
name: 'test',
imageInput: [Object: null prototype] { image: [ 'url_1', 'url_2' ] }
}
I already try use restructuring like {args} or {...args} but its not working.我已经尝试使用 {args} 或 {...args} 之类的重组,但它不起作用。
Please can somebody explain to me what I do wrong?请有人向我解释我做错了什么?
This is my source schemas and resolver.这是我的源模式和解析器。
schema.graphql架构.graphql
type Query {
allProducts: [Product!]!
product(id: ID!): Product
}
type Mutation {
createProduct(
name: String
description: String
price: Float
discount: Int
pieces: Int
imageInput: ProductImageInput!
): Product!
}
type Product {
id: ID!
name: String!
description: String!
image: [String]
price: Float!
discount: Int
pieces: Int!
}
input ProductImageInput{
image: [String]!
}
schema.prisma模式棱镜
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb"]
}
model Product {
id String @id @default(auto()) @map("_id") @db.ObjectId
productImage String[]
name String
description String
price Float
discount Int
pieces Int
createdAt DateTime @default(now())
resolver解析器
const resolvers = {
Query: {
allProducts: async (parent, args, context) => {
return context.prisma.product.findMany()
},
},
Mutation: {
createProduct: (parent, args, context, info) => {
console.log(args)
// const newProduct = context.prisma.product.create({
// data: {
// name: args.name,
// description: args.description,
// productImage: args.imageInput.image,
// price:args.price,
// discount: args.discount,
// pieces: args.pieces,
// },
// })
// return newProduct
}
}
}
try something like this.尝试这样的事情。
JSON.parse(JSON.stringify(args))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.