首页 > 解决方案 > prisma中嵌套类型的相应graphql-tag突变

问题描述

我想知道如何在嵌套类型中应用mutationgraphql-tag因为在 prisma 中我create用来分配字段

我的datamodel.graphql

    type Item {
      id: ID! @id @unique
      title: String
      description: String 
      price: Int
      laptop: Laptop @relation(link: INLINE)


   }

    type Laptop {
       id: ID! @id
       brand: String

   }

我的schema.graphql

    type Mutation {
      createItem(
        title: String
        description: String
        price: Int
        laptop: LaptopCreateOneInput
     ): Item!
    }

到目前为止我确实尝试过,但它没有用

    const CREATE_ITEM_MUTATION = gql`
       mutation CREATE_ITEM_MUTATION(
         $title: String!
         $description: String!
         $price: Int!
         $laptop: LaptopCreateOneInput

      ) {
        createItem(
          title: $title
          description: $description
          price: $price
          laptop:$laptop
        ) {
           id
          }
     }
   `;

我可以像这样在graphql操场上应用突变

    mutation {
      createItem(
        title: "computer"
        description: "some computer"
        price: 1000
        laptop: { create: { brand: "some brand" } }
     ) {
      title
     description
     }
   }

标签: reactjsapollo-clientprismagraphql-tag

解决方案


create我确实通过用word更新状态来使它工作

state = {
  title: '',
  price: 0,
  laptop: {
    create: {
      brand: ''
    }
  },
  description: '',
};

推荐阅读