facebook / facebook/relay

Feature Request: Flatten fragments in requests

Open
#4,840 9 comments 4 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

## What?

As part of the relay compiler generate "flattened" queries to use in the network request body

Request body example

```graphql
query useAppleQuery(
$requestBody: v1_AppleRequestBody
) {
apple(requestBody: $requestBody) {
__typename
... on Apple {
id
flavour
...OneFragment
...TwoFragment
...ThreeFragment
}
... on Error {
errors {
code
}
}
}
}

fragment OneFragment on Apple {
id
taste
}

fragment TwoFragment on Apple {
id
taste
colour
}

fragment ThreeFragment on Apple {
id
colour
}
```
becomes
```graphql
query useAppleQuery(
$requestBody: v1_AppleRequestBody
) {
apple(requestBody: $requestBody) {
__typename
... on Apple {
id
flavour
taste
colour
}
... on Error {
errors {
code
}
}
}
}
```

## Why?

The server response is identical, so given were already running a compiler, do a bit more computation at build time, to improve server performance (less input to parse) and reduce the amount of data the client needs to send to the server (when not using persisted queries)

For large applications (where theres hundreds of fragments) this could have huge performance improvements

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.