My GraphQLServer query:
query {
sources {
name
id
}
}
returns array of objects like so:
{
"data": {
"sources": [
{
"name": "bootstrap.css",
"id": 1
},
{
"name": "normalize.css",
"id": 2
}
]
}
}
Trying to understand how to call it from React (redux). I tried:
function mapQueriesToProps( {ownProps, state}) {
return {
data: {
query: gql`
query {
sources {
id
name
}
}
`,
forceFetch: false,
returnPartialData: false,
},
};
};
But nothing happens. Just get loading: true. I'm using apollo-client and got it all wired up according to docs (I think). By that I mean I'm using connect(mapQueriesToProps) etc.
- When does the query actually get run?
- Does it automatically get run when component loads?
- Is there a step I need to do to wait for data to return?
- How does the component know to wait for the data?
- Is it alright to return an array? I couldn't find any examples of returning an array in the docs.
- I only want to run this once, not do any polling or anything. Is that the only way?
This is my first test of Apollo. Any guidance appreciated, because the docs are rather skimpy for beginners.