Skip to content

Commit

Permalink
fix(graphql-server): the resolver always has context as the argument (#…
Browse files Browse the repository at this point in the history
…705)

* feat(types): the resolver always has context as the argument

* make it `patch` release
  • Loading branch information
metrue authored Aug 25, 2024
1 parent 1bd5cdc commit 9cac146
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-peaches-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/graphql-server': patch
---

Make argument (context) for the root resolver function from optional to required.
2 changes: 1 addition & 1 deletion packages/graphql-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { parseBody } from './parse-body'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type RootResolver<E extends Env = any, P extends string = any, I extends Input = {}> = (
// eslint-enable-next-line @typescript-eslint/no-explicit-any
c?: Context<E, P, I>
c: Context<E, P, I>
) => Promise<unknown> | unknown

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-server/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ describe('GraphQL Middleware - Simple way', () => {
}
`)

const rootResolver: RootResolver = (ctx?: Context) => {
const name = ctx?.get('name')
const rootResolver: RootResolver = (c: Context) => {
const name = c.get('name')
return {
hi: `hi ${name}`,
}
Expand Down

0 comments on commit 9cac146

Please sign in to comment.