Skip to content

Commit a8d7b85

Browse files
committed
📘 doc: add mobius mention to graphql yoga
1 parent efc5025 commit a8d7b85

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/plugins/graphql-yoga.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@ optional: you can install custom version of optional peer dependencies as well:
5252
bun add graphql graphql-yoga
5353
```
5454

55+
## Resolver
56+
Elysia use [Mobius](https://github.com/saltyaom/mobius) to infers type from **typeDefs** field automatically, allowing you to get full type-safety and auto-complete when typing **resolver** types.
57+
58+
## Context
59+
You can add custom context to resolver function by adding **context**
60+
```ts
61+
import { Elysia } from 'elysia'
62+
import { yoga } from '@elysiajs/graphql-yoga'
63+
64+
const app = new Elysia()
65+
.use(
66+
yoga({
67+
typeDefs: /* GraphQL */`
68+
type Query {
69+
hi: String
70+
}
71+
`,
72+
context: {
73+
name: 'Mobius'
74+
},
75+
// If context is a function on this doesn't present
76+
// for some reason it won't infer context type
77+
useContext(_) {}
78+
resolvers: {
79+
Query: {
80+
hi: async (parent, args, context) => context.name
81+
}
82+
}
83+
})
84+
)
85+
.listen(8080)
86+
```
87+
5588
## Config
5689
This plugin extends [GraphQL Yoga's createYoga options, please refers to the GraphQL Yoga documentation](https://the-guild.dev/graphql/yoga-server/docs) with inlining `schema` config to root.
5790

0 commit comments

Comments
 (0)