readQuery without variables
See original GitHub issueIntended outcome: I would like to be able to query the store without having to use the same variables in previous queries. For example, on a list page I have a query that looks like this:
query Company($cursor: String) {
company {
id
locations(first: 10, after: $cursor) {
pageInfo {
# ...
}
edges {
node {
id
# ...
}
}
}
}
}
I have a mutation to add a location and I’m attempting to load all locations associated with the company but it’s forcing me to add the first
and after
field arguments. I would like to grab all locations by using the following query:
const data = this.props.client.readQuery({
query: gql` {
company {
healthySpots {
edges {
node {
id
# ...
}
}
}
}
}`,
});
Actual outcome: The following error is being thrown:
Can't find field locations on object ($ROOT_QUERY.company) {
"name": "App",
"locations({\"first\":10,\"after\":null})": {
"type": "id",
"id": "$ROOT_QUERY.company.locations({\"first\":10,\"after\":null})",
"generated": true
},
"__typename": "Company"
}.
If I include the first
and after
arguments with the same variables used on my list page then it works but this requires me to keep track of those variables from a different location in my app. It would be nice to just be able to skip variables if I preferred to not filter any fields.
How to reproduce the issue: If you are attempting to read a query from the store that was fulfilled with the use of variables then an error will be thrown.
Also, I have to applaud your efforts that have allowed me to be so much more productive than I was before Apollo was open sourced! Thank you for what you’re doing for the community!!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:13 (1 by maintainers)
Top GitHub Comments
Its still not easy, i have to track every single variables. The documentation holds just the easy use cases, but i have pagination, filtering and ordering, and the actions i have, modify records individually. The update mechanism is still hard and complicated
This is really embarrassing, how we cannot access a query without variables. I don’t think it will be much of a problem if we get queries with the same name. And we also can come up with different query names in GraphQL and get directly that query by the custom name, no by the whole GraphQL query with its variables.
It seems very frustrating to store queries with all their variables, just so we can update them later in some of the code. We need to create additional code even though apollo can crate an API that can be easily handled with custom name queries. With the custom names, we will not need to manage additional code for mutating queries.
Currently, in my real project, I have an add todo modal and want to modify the list that shows on the dashboard, to add the todo on top of the list, but I cannot access the query with
readQuery
, because it also requires the variables that are passed to the query. Well, this is a bummer because the components are not related.I’ve been searching for any non-hacking ways, but it seems a bad API implementation to me.
Correct me if I am wrong.