apollographql / apollographql/apollo-tooling
Extracting queries in order to preload data
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
We've built a routing system where links preload relevant code when hovering them. Currently, I have to wait for the code (which contains the query) to load, before I can start the query.
Simplified route definition:
```typescript
{
loadCode: () => import("./FilterRoute"),
loadData: match => {
import("./FilterRoute").then(({ QUERY }) => {
apolloClient.query({
query: QUERY,
variables: { filter: match }
});
});
}
}
```
However, I would like to initiate the query and load the code at the same time:
```typescript
import QUERY from './__generated__/FilterQuery';
// ...
loadData: match => {
apolloClient.query({
query: QUERY,
variables: { filter: match }
});
```
Preferably, we would extract the queries to a separate file which is then imported at the route definition, similar to what the relay compiler does.
The `apollo client:extract` command already extracts the necessary information but not in way that is easy to consume.
One solution would be a flag instructing `extract` to export a map of operations instead of an array.
I've tried googling for tools that compile and extract queries based on `graphql-tag` usage, but have not found anything.
Contributor guide
Research direction
Start with the `apollo client:extract` command and inspect how it currently emits its array of operations. Compare that output with the `./__generated__/FilterQuery` import shown in the issue; done means extracted queries can be consumed independently so route data loading does not wait for `FilterRoute` code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100