You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rfcs/FragmentArguments.md
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,11 +82,11 @@ However, even to enable this client-compile-time operation transformation, Relay
82
82
83
83
Additionally, the `@argumentDefinitions` directive gets very verbose and unsafe, using strings to represent variable type declarations.
84
84
85
-
Relay has supported `@arguments` in its current form since [v2.0](https://github.com/facebook/relay/releases/tag/v2.0.0), released in January 2019. There's now a large body of evidence that allowing fragments to define arguments that can be passed into fragment spreads is a signficant usability improvement, and valuable to the wider GraphQL community. However, if we are to introduce this notion more broadly, we should make sure the ergonomics of it conform to users' expectations.
85
+
Relay has supported `@arguments` in its current form since [v2.0](https://github.com/facebook/relay/releases/tag/v2.0.0), released in January 2019. There's now a large body of evidence that allowing fragments to define arguments that can be passed into fragment spreads is a significant usability improvement, and valuable to the wider GraphQL community. However, if we are to introduce this notion more broadly, we should make sure the ergonomics of it conform to users' expectations.
86
86
87
87
# Proposal: Introduce Fragment Argument Definitions and Fragment Spread Arguments to client-only GraphQL
88
88
89
-
Relay's `@arguments`/`@argumentDefinitions` concepts provide value, and can be applied against GraphQL written for existing GraphQL servers so long as the pre-server compiler transforms the concept away. However, client-focused tooling, like Prettier and GraphiQL, should be able to recognize and work with these new concepts.
89
+
Relay's `@arguments`/`@argumentDefinitions` concepts provide value, and can be applied against GraphQL written for existing GraphQL servers so long as there is a pre-server compiler which transforms the concept away. However, client-focused tooling, like Prettier and GraphiQL, should also be able to parse and work with these new concepts.
90
90
91
91
## New Fragment Variable Definition syntax
92
92
@@ -118,7 +118,7 @@ fragment TopFriendsUserProfile on User {
118
118
119
119
## New Validation Rule: Fragment Argument Definitions Used in Fragment
120
120
121
-
The whole point of fragment defined arguments is to make fragments more composable. Therefore, fragments should only be defining variables that are explicitly used under that fragment.
121
+
The main use case for fragment defined arguments is to make fragments more composable. Therefore, fragments should only be defining variables that are explicitly used under that fragment.
122
122
123
123
Under this rule,
124
124
```
@@ -162,8 +162,8 @@ It's clearly more composable if, when changing a child fragment, you don't need
162
162
163
163
Make the [Required Arguments](https://spec.graphql.org/draft/#sec-Required-Arguments) validation's first two bullets:
164
164
165
-
- For each Field, Fragment Spread or Directive in the document.
166
-
- Let *arguments* be the set of argument definitions of that Field, Fragment or Directive.
165
+
- For each Field, **Fragment Spread** or Directive in the document.
166
+
- Let *arguments* be the set of argument definitions of that Field, **Fragment** or Directive.
167
167
168
168
With this rule, the below example is invalid, even if the argument `User.number(x:)` is nullable in the schema.
169
169
```
@@ -197,6 +197,8 @@ query {
197
197
198
198
Note: today Relay's compiler handles this ambiguity. In an extreme simplification, this is done by producing two unique versions of `UserProfile`, where in `UserProfile_0``$imageSize` is replaced with `100`, and in `UserProfile_1``$imageSize` is replaced with `200`. However, there exist client implementations that are unable to have multiple applications of the same fragment within a single operation (the clients I work on cannot use Relay's trick).
199
199
200
+
This validation rule may end up being more strict than required, but it would be easier to relax the rule than make it more strict later.
201
+
200
202
# Implementation
201
203
202
204
Any client that implements this RFC would have a pre-server compilation step, which transforms all fragment defined variable usages to:
0 commit comments