graphql-yoga-disable-introspection
Version:
Disable introspection in graphql-yoga with a validation rule
19 lines (18 loc) • 444 B
JavaScript
var graphql = require('graphql');
/**
* No introspection: __schema and __type are disallowed in the query.
*/
module.exports = function NoIntrospection(context) {
return {
Field(node) {
if (node.name.value === '__schema' || node.name.value === '__type') {
context.reportError(
new graphql.GraphQLError(
'GraphQL introspection is not allowed',
[node]
)
);
}
}
};
}