0

我想知道如何在嵌套类型中应用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
     }
   }
4

1 回答 1

0

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

state = {
  title: '',
  price: 0,
  laptop: {
    create: {
      brand: ''
    }
  },
  description: '',
};
于 2019-10-02T09:01:29.293 回答