v0.9.3
v0.9.3 v0.17.3 v0.17.2 v0.17.1 v0.17.0 v0.16.0 v0.15.1 v0.15.0 v0.14.0 v0.13.0 v0.12.2 v0.12.1 v0.12.0 v0.11.3 v0.11.2 v0.11.1 v0.11.0 v0.10.2 v0.10.1 v0.10.0 master

Introspection

Disabling introspection
[edit]
You are looking at the docs for an older version (v0.9.3). The latest version is v0.17.3.

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:

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:

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)
		}),
	),
)