Skip to content

Commit d9f7fd2

Browse files
committed
Added an example on using resolver extensions to docs and added a changeset
1 parent debc6e3 commit d9f7fd2

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.changeset/nice-eels-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphql-modules': minor
3+
'website': patch
4+
---
5+
6+
Enabled support for resolver extensions for compatibility with such libraries as grafast or graphql-query-complexity

website/src/content/essentials/resolvers.mdx

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ npm i @graphql-tools/load-files
6060
Next, use it to load your files dynamically:
6161

6262
```ts
63-
import MyQueryType from './query.type.graphql'
6463
import { createModule } from 'graphql-modules'
65-
import { loadFilesSync } from '@graphql-tools/load-files'
66-
import { join } from 'path'
64+
import { constant } from "grafast";
6765

6866
export const myModule = createModule({
6967
id: 'my-module',
@@ -72,3 +70,40 @@ export const myModule = createModule({
7270
resolvers: loadFilesSync(join(__dirname, './resolvers/*.ts'))
7371
})
7472
```
73+
74+
## Resolver Extensions
75+
76+
You can use resolver extensions to extend the functionality of your resolvers to make your modules work with such extensions as [Grafast Plan Resolver](https://grafast.org/grafast/plan-resolvers#specifying-a-field-plan-resolver) or [GraphQL Query Complexity](https://github.com/slicknode/graphql-query-complexity/blob/HEAD/src/estimators/fieldExtensions/README.md).
77+
78+
To use resolver extensions, you can use the `extensions` property in your resolvers.
79+
80+
```ts
81+
import { createModule, gql } from 'graphql-modules'
82+
import { constant } from "grafast";
83+
84+
export const myModule = createModule({
85+
id: 'my-module',
86+
dirname: __dirname,
87+
typeDefs: [
88+
gql`
89+
type Query {
90+
meaningOfLife: Int!
91+
}
92+
`
93+
],
94+
resolvers: {
95+
Query: {
96+
meaningOfLife: {
97+
extensions: {
98+
grafast: {
99+
plan() {
100+
return constant(42);
101+
},
102+
},
103+
},
104+
},
105+
}
106+
}
107+
})
108+
```
109+

0 commit comments

Comments
 (0)