-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from 99designs/disable-introspection
Add config option to disable introspection
- Loading branch information
Showing
17 changed files
with
261 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: 'Disabling introspection' | ||
description: Prevent users from introspecting schemas in production. | ||
linkTitle: Introspection | ||
menu: { main: { parent: 'reference' } } | ||
--- | ||
|
||
One of the best features of GraphQL is it's powerful discoverability, but sometimes you don't want to allow others to explore your endpoint. | ||
|
||
## Disable introspection for the whole server | ||
|
||
To turn introspection on and off at runtime, pass the `IntrospectionEnabled` handler option when starting the server: | ||
|
||
```go | ||
srv := httptest.NewServer( | ||
handler.GraphQL( | ||
NewExecutableSchema(Config{Resolvers: resolvers}), | ||
handler.IntrospectionEnabled(false), | ||
), | ||
) | ||
``` | ||
|
||
## Disabling introspection based on authentication | ||
|
||
Introspection can also be enabled on a per-request context basis. For example, you could modify it in a middleware based on user authentication: | ||
|
||
```go | ||
srv := httptest.NewServer( | ||
handler.GraphQL( | ||
NewExecutableSchema(Config{Resolvers: resolvers}), | ||
handler.RequestMiddleware(func(ctx context.Context, next func(ctx context.Context) []byte) []byte { | ||
if userForContext(ctx).IsAdmin { | ||
graphql.GetRequestContext(ctx).DisableIntrospection = true | ||
} | ||
|
||
return next(ctx) | ||
}), | ||
), | ||
) | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.