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?>}
            })
2
  • You find any solution on this? Commented Mar 13, 2019 at 10:33
  • Looking for the same... No where to see any good documentation on variables Commented Mar 27, 2019 at 13:08

1 Answer 1

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?>}
            })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.