【问题标题】:apollo (graphQL) - how to send array of object in queriesapollo (graphQL) - 如何在查询中发送对象数组
【发布时间】:2018-08-07 08:34:16
【问题描述】:

我想在 graphQL 查询中发送一个对象数组。但我不知道如何在查询 $gallery 中键入指针:其中 Type 将是一个简单的数据结构,如类或字典。

 apollo_client.mutate({mutation: gql`
          mutation m(
            $title: String!, $gallery:<Type?>){
              mutatePmaGallery(pmaData:
                {title: $title, gallery: $gallery}) {
                  pma{
                    id
                  }
                }
              }`,
            variables: {
              title:      _this.state.title,
              gallery:    {<Type?>}
            })

【问题讨论】:

  • 你找到解决办法了吗?
  • 正在寻找相同的... 找不到关于变量的任何好的文档

标签: graphql apollo


【解决方案1】:

您首先需要根据您的图库结构定义输入类型:

input GalleryType {
   id:ID!
   name: String!
}

那么你可以简单地这样做:

apollo_client.mutate({mutation: gql`
          mutation m(
            $title: String!, $gallery:[GalleryType!]!){ //changed part
              mutatePmaGallery(pmaData:
                {title: $title, gallery: $gallery}) {
                  pma{
                    id
                  }
                }
              }`,
            variables: {
              title:      _this.state.title,
              gallery:    {<Type?>}
            })

【讨论】:

    猜你喜欢
    • 2021-04-23
    • 2018-11-21
    • 1970-01-01
    • 2018-10-19
    • 2021-07-22
    • 2020-10-10
    • 2016-08-23
    • 2021-01-01
    • 2021-08-14
    相关资源
    最近更新 更多