Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apollo (graphQL) - how to send array of object in queries

Tags:

graphql

apollo

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?>}
            })
like image 653
Mr Bonjour Avatar asked Feb 27 '18 16:02

Mr Bonjour


1 Answers

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?>}
            })
like image 138
Sihoon Kim Avatar answered Oct 08 '22 09:10

Sihoon Kim