简体   繁体   English

prisma中嵌套类型的相应graphql-tag突变

[英]corresponding graphql-tag mutation of nested types in prisma

i wonder how you can apply mutation using graphql-tag in nested types because in prisma i use create to assign fields我想知道如何在嵌套类型中使用graphql-tag应用mutation ,因为在 prisma 中我使用create来分配字段

my datamodel.graphql我的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

   }

my schema.graphql我的schema.graphql

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

i did try this so far but it didnt work到目前为止我确实尝试过,但它没有用

    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
          }
     }
   `;

i can apply mutation in graphql playground like this我可以像这样在 graphql 操场上应用突变

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

i did make it work by updating the state with create word我确实通过使用create word 更新 state 使它工作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Graphql 突变与嵌套类型? - Graphql mutation with nested types? GraphQL(Prisma)突变数据未定义 - GraphQL (Prisma) Mutation data undefined 如何在反应更新突变中访问object.id,graphql与棱镜 - How to access object.id in update mutation in react, graphql with prisma 传递给解析器的 [object Object] 的参数不是有效的 GraphQL DocumentNode。 您可能需要使用“graphql-tag”或其他方法进行转换 - Argument of [object Object] passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert 将嵌套的ReactJS值放入GraphQL创建突变 - Put Nested ReactJS values into GraphQL create mutation 为嵌套模式 graphql/apollo/react 添加突变 - Add mutation for nested schema graphql/apollo/react Prisma、GraphQL 和 Apollo 中具有突变的数据关系和连接类型 - Data Relationships and Connection Types with Mutations in Prisma, GraphQL, and Apollo Prisma、graphql 和反应钩子 forms:如何在更新表单突变中使用创建的值 - Prisma, graphql and react hook forms: how to use created values in update form mutation Apollo / graphQL:如何使用开放式UI对嵌套的React组件进行突变? - Apollo/graphQL: How to use optimistic UI for a mutation of a nested react component? GraphQL验证错误突变 - GraphQL Validation Error on mutation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM