[Feature Request] A way to combine several identical queries instead of looping
- Dominant language
- Go
- Stars
- 1.3k
- Forks
- 143
- Avg merge
- 4h 50m
- Merged PRs (30d)
- 1
Description
I understand that this isn't production ready yet nor is it complete but I'd like to request a feature if you guys are taking those requests.
I have a small app that hits a graphql endpoint and returns ~50-60 product handles. I then need to individually query data about those products through their handle. The query for each individual product looks like this:
```
productByHandle(handle:$handle) {
variants(first: 35) {
edges {
node {
id
price
}
}
}
}
```
If I were to loop through each one and run the query individually I would hit a rate limit unless I specified something like `time.Sleep(500 * time.Millisecond)` after each query. But that adds up and takes time.
So what I ended up doing was writing a function that combines all the queries into named/aliased queries like this:
```
query {
product1: productByHandle(handle:"ABC") {
variants(first: 35) {
edges {
node {
id
price
}
}
}
}
product2: productByHandle(handle:"ZYX") {
variants(first: 35) {
edges {
node {
id
price
}
}
}
}
product3: productByHandle(handle:"XYZ") {
variants(first: 35) {
edges {
node {
id
price
}
}
}
}
product4: productByHandle(handle:"CBA") {
variants(first: 35) {
edges {
node {
id
price
}
}
}
}
...
...
...
}
```
which allows me to send it as one query instead of 50-60 individual ones.
So essentially what I am proposing is a method for doing essentially the same with genqlient; to be able to combine several identical queries into one large one. Thoughts?
Contributor guide
Research direction
No file or test is named in the issue. Start by tracing genqlient's query-generation and request entry points, then compare them with the aliased GraphQL example; done means repeated identical queries can be sent as one type-safe request with results mapped back to each product.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, graphql
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100