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: docs/source/local-state/local-resolvers.mdx
+117Lines changed: 117 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,6 +165,123 @@ new LocalState<Resolvers, ContextValue>({
165
165
});
166
166
```
167
167
168
+
#### Generating types for local resolvers
169
+
170
+
When using TypeScript, you can generate resolver types for your local resolvers using the `@apollo/client-graphql-codegen` package. This package provides a specialized GraphQL Code Generator plugin that creates resolver types compatible with Apollo Client's `LocalState`.
171
+
172
+
##### Installation
173
+
174
+
Install the GraphQL Code Generator plugin for local state:
175
+
176
+
```bash
177
+
npm install -D @apollo/client-graphql-codegen
178
+
```
179
+
180
+
##### Configuration
181
+
182
+
Add the local-state plugin to your `codegen.ts` configuration. It's recommended to use a separate schema file containing only your local fields to avoid generating resolver types for your entire remote schema:
This approach ensures that your local resolver functions are properly typed and checked against your local schema, providing better development experience and catching type errors at compile time.
284
+
168
285
### Error handling
169
286
170
287
Throwing errors in a resolver will set the field value as `null` and add an error to the response's `errors` array. This follows GraphQL's standard error handling behavior:
0 commit comments