Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 18, 2025
1 parent 0538f0a commit ff3243e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/plugins/disable-introspection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ type UseDisableIntrospectionArgs = {
isDisabled?: (request: Request, context: Record<string, unknown>) => PromiseOrValue<boolean>;
};

export const useDisableIntrospection = (props?: UseDisableIntrospectionArgs): Plugin => {
export function useDisableIntrospection<TContext extends Record<string, unknown>>(
props?: UseDisableIntrospectionArgs,
): Plugin<TContext> {
const store = new WeakMap<Request, boolean>();
return {
async onRequestParse({ request, serverContext }) {
Expand All @@ -19,4 +21,4 @@ export const useDisableIntrospection = (props?: UseDisableIntrospectionArgs): Pl
}
},
};
};
}
4 changes: 4 additions & 0 deletions website/src/pages/docs/features/introspection.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ via another auth plugin like [JWT Plugin](/docs/features/jwt).
```ts "Disabling GraphQL schema introspection based on the context" {7}
import { createYoga } from 'graphql-yoga'
import { useDisableIntrospection } from '@graphql-yoga/plugin-disable-introspection'
import { useJWT } from '@graphql-yoga/plugin-jwt'

// Provide your schema
const yoga = createYoga({
graphiql: false,
plugins: [
useJWT({
/* .. */
}),
useDisableIntrospection({
isDisabled: (_req, ctx) => !ctx.jwt
})
Expand Down

0 comments on commit ff3243e

Please sign in to comment.