I’m new to GraphQL and I’m trying to build a work around project for training purposes.
For this project I’m using an external GraphQL API to get some movies.
I’m making my requests through Apollo-Client the newest version and display them within a small react native app and the useQuery hook from the Apollo-Client library. No particular backend for this app.
I’m currently trying to display 2 different screens :
- The main one with a list of all the movies. Got them with this query :
const GET_MOVIES = gql `
{
allMovies {
movies {
title
id }
}
}
`
Everything is ok so far. But I’m stuck with the next part. I’m trying to use this id i got from a movie (map through movies) as a variable for my next request which i want to use to display my next screen. The movie screen.
I got the id but i don’t know how to use it as a variable and pass it to my query to then get all the movie informations i need from this particular movie.
I found something like this :
const GET_THIS_MOVIE = gql `
{
movie (id : $movieID) {
title
....
....
}
}
`
But i don’t know how to use the id i got as this movieID variable. Knowing this id will change depending on the movie selected.
A precise answer with some code would be really appreciated as im new to GraphQL
Thanks for your help !