9

I would like to send an array of object in a graphQL queries. But I don't have any idea how to type the pointer in the query $gallery: where Type will be a simple datastructure like a class or dictionnary.

 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?>}
            })
Mr Bonjour
  • 3,330
  • 2
  • 23
  • 46

1 Answers1

1

You first need to define an input type according to your gallery structure :

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

Then you can simply do this:

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?>}
            })
Sihoon Kim
  • 1,481
  • 2
  • 13
  • 32