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: rescript-relay-documentation/docs/getting-started.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,9 @@ module.exports = {
82
82
schema:"./schema.graphql", // Path to the schema.graphql you've exported from your API. Don't know what this is? It's a saved introspection of what your schema looks like. You can run `npx get-graphql-schema http://path/to/my/graphql/server > schema.graphql` in your root to generate it
83
83
artifactDirectory:"./src/__generated__", // The directory where all generated files will be emitted
84
84
85
+
// Enable this if you want mutations that return unions to always force selecting all union members. Read more in the docs on unions.
86
+
autoExhaustiveMutations:true,
87
+
85
88
// You can add type definitions for custom scalars here.
86
89
// Whenever a custom scalar is encountered, the type emitted will correspond to the definition defined here. You can then deal with the type as needed when accessing the data.
Copy file name to clipboardExpand all lines: rescript-relay-documentation/docs/unions.md
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,9 +83,83 @@ Let's break down what's going on here:
83
83
2. We fetch our query data, and we switch on `roomOwner` to make sure it's actually there in the data.
84
84
3. We then switch again, but this time on the variant representing the union. This polymorphic variant will have each possible type of the union, and the fields selected on that type. It also adds `UnselectedUnionMember(string)` to every union, which will force you to handle _what happens if there's another member added to the union before you have time to update your app_. The `string` payload is the `__typename` of the retrieved member that wasn't selected. This is pretty neat way to ensure you gracefully handle your schema evolving.
85
85
86
+
## Exhaustiveness Checking with `@exhaustive`
87
+
88
+
RescriptRelay provides an `@exhaustive` directive that helps ensure you've selected all available union members in your GraphQL queries. This directive can be applied to fields or fragment definitions and will trigger exhaustiveness checks at compile time.
89
+
This is useful when you there are unions in your schema where you'll want to be alerted at compile time that the server added new possible return values. This makes unions work just like enums in this regard.
When you use `@exhaustive`, RescriptRelay will check that you've included fragments for all possible union members. If you're missing any, you'll get a compile-time error telling you which union members you haven't selected.
124
+
125
+
### Parameters
126
+
127
+
-**`ignore: [String!]`** - An array of union member type names to ignore during exhaustiveness checking. Use this when you intentionally don't want to handle certain union members.
128
+
129
+
```rescript
130
+
/* Ignore the Group type in exhaustiveness checking */
-**`disabled: Boolean`** - Set to `true` to completely disable exhaustiveness checking for this field while keeping the directive for documentation purposes.
You can also configure RescriptRelay to automatically apply exhaustiveness checking to mutation fields that return unions. Add `autoExhaustiveMutations: true` to your Relay configuration to enable this behavior for any top-level mutation field that returns a union type.
158
+
86
159
## Wrapping up
87
160
88
161
And that's that! Keep the following in mind about unions and everything will be fine:
89
162
90
163
- Remember to select `__typename`
91
164
- Remember to handle `UnselectedUnionMember`
165
+
- Consider using `@exhaustive` to ensure you handle all union members
0 commit comments