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: README.md
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ This library is intended to simplify the network aspect of data consumption for
21
21
| ✅ | Build time validations & optimizations ||
22
22
| ✅ | Client-Side Composition | with improved execution planner (based on GraphQL-Mesh) |
23
23
| ✅ | Raw Execution (standalone mode) | without a wrapping GraphQL client |
24
+
| ✅ | Local (client-side) Mutations ||
24
25
| ✅ | Integration with `@apollo/client`||
25
26
| ✅ | Integration with `urql`||
26
27
| ✅ | TypeScript support | with built-in GraphQL Codegen and `TypedDocumentNode`|
@@ -377,6 +378,89 @@ async function main() {
377
378
378
379
> You can find a [TypeScript project example here](./examples/urql/).
379
380
381
+
#### Client-Side Mutations
382
+
383
+
Due to the nature of Graph-Client setup, it is possible to add client-side schema, that you can later bridge to run any arbitrary code.
384
+
385
+
This is helpful since you can implement custom code as part of your GraphQL schema, and have it as unified application schema that is easier to track and develop.
386
+
387
+
> This document explains how to add custom mutations, but in fact you can add any GraphQL operation (query/mutation/subscriptions). See [Extending the unified schema article](https://www.graphql-mesh.com/docs/guides/extending-unified-schema) for more information about this feature.
388
+
389
+
To get started, define a `additionalTypeDefs` section in your config file:
390
+
391
+
```yml
392
+
additionalTypeDefs: |
393
+
type Mutation {
394
+
doSomething(input: SomeCustomInput!): Boolean!
395
+
}
396
+
397
+
input SomeCustomInput {
398
+
field: String!
399
+
}
400
+
```
401
+
402
+
Then, add a pointer to a custom GraphQL resolvers file:
403
+
404
+
```yml
405
+
additionalResolvers:
406
+
- './resolvers'
407
+
```
408
+
409
+
Now, create `resolver.js` (or, `resolvers.ts`) in your project, and implement your custom mutation:
// For example, use `web3` lib, connect a wallet and so on.
435
+
436
+
returntrue
437
+
},
438
+
},
439
+
}
440
+
441
+
exportdefaultresolvers
442
+
```
443
+
444
+
If you need to inject runtime variables into your GraphQL execution `context`, you can use the following snippet:
445
+
446
+
```ts
447
+
client.execute(
448
+
MY_QUERY,
449
+
{},
450
+
{
451
+
myHelper: {}, // this will be available in your Mutation resolver as `context.myHelper`
452
+
},
453
+
)
454
+
```
455
+
456
+
> [You can read more about client-side schema extensions here](https://www.graphql-mesh.com/docs/guides/extending-unified-schema)
457
+
458
+
> [You can also delegate and call Query fields as part of your mutation](https://www.graphql-mesh.com/docs/guides/extending-unified-schema#using-the-sdk-to-fetch-sources)
0 commit comments