【问题标题】:corresponding graphql-tag mutation of nested types in prismaprisma中嵌套类型的相应graphql-tag突变
【发布时间】:2020-01-31 11:18:51
【问题描述】:

我想知道如何在嵌套类型中使用 graphql-tag 来应用 mutation,因为在 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
     }
   }

【问题讨论】:

    标签: reactjs apollo-client prisma graphql-tag


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-12-09
      • 2019-06-18
      • 2019-08-24
      • 2020-04-24
      • 2018-08-24
      • 2021-04-09
      • 2018-05-30
      • 2019-12-19
      • 2019-07-20
      相关资源
      最近更新 更多