dotansimha / dotansimha/graphql-code-generator

Add an @inline direction in client-preset to unmask actual GraphQL fragments

Open
#9,689 5 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Is your feature request related to a problem? Please describe.

A user may have prior-existing fragments, or want to use fragments, that are not 1:1 directly associated with a specific component. For example:

```
fragment User {
id
name
...
}

query {
user(...) {
...User
}
}
```

With the current fragment masking in `client-preset`, these fragments are assumed to be components, which will then fail to work.

### Describe the solution you'd like

My suggestion is to mirror how Relay is designed, with an `@inline` or `@relay(mask: false)` directive. This directive indicates that a fragment is _not_ a component's fragment and allows intermixing of actual fragments with component fragments:

```
query {
user(...) {
...UserAvatar_User
...User @inline
}
}
```
this will expand the `User` fragment, but continue to mask the `UserAvatar_User` fragment (which might itself want to expand the `User` fragment)

### Describe alternatives you've considered

One alternative is to simply suggest that fragments themselves are an antipattern because repeated GraphQL entire objects should be abstracted to a component. I think this is an unrealistic approach, especially when considering transitioning onto fragment masking from an existing codebase.

### Is your feature request related to a problem? Please describe.

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.