apollo(graphQL)-如何在查询中发送对象数组

Mr *_*our 8 apollo graphql

我想在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?>}
            })
Run Code Online (Sandbox Code Playgroud)

Sih*_*Kim 1

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

input GalleryType {
   id:ID!
   name: String!
}
Run Code Online (Sandbox Code Playgroud)

然后你可以简单地这样做:

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?>}
            })
Run Code Online (Sandbox Code Playgroud)