简体   繁体   English

我尝试从突变中获取 args 数组。 我仍然得到 [对象:null 原型]

[英]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服务器、 PrismaMongodb输入 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.

相关问题 我试图从mongodb获取单个数组值,但是当我尝试时,我得到了整个对象 - I am trying to get a single array value from mongodb, but when i try i get the whole object 如何摆脱 Node.js 中的 [Object: null prototype]? - How do I get rid of [Object: null prototype] in Node.js? 我尝试在我的 mocha nodejs 测试中上传文件,但我得到了 [Object null prototype] { file: {... }} - i try to upload file in my mocha nodejs test but i got [Object null prototype] { file: { ... }} 有没有办法摆脱 GraphQL 中的 [Object: null prototype] - Is there a way to get rid of [Object: null prototype] in GraphQL 尝试将对象推入MongoDB和Nodejs中的数组时,为什么会出现castError? - Why do I get a castError when I try to push an object to an array in MongoDB and Nodejs? 当我尝试将 Object 从 api 添加到我的 mongodb atlas db NODE.JS 时,我变得不确定 - I get undefined when i try to add an Object from an api to my mongodb atlas db NODE JS 在使用 find() 方法从 mongodb 数据库中检索数据时,我在添加 object 后得到 null 数组 - I get null array after adding object to it while retrieving the data from mongodb database in express using find() method 我尝试从托管文本文件中获取文本到技能处理程序中,但是当我测试技能时显示错误“SpeechletResponse 为空” - I try get text from hosted text file into skill handler, but when I test skill show an error "SpeechletResponse was null" 我想从数组中的 object 获取值键 - I want to get values key from object which is in array 如何从数组中获取 object 值? - How can I get an object value from inside an array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM