apollographql / apollographql/apollo-tooling

Extracting queries in order to preload data

Open
#1,835 1 comment 1 reaction 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.