Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Last active January 7, 2021 09:28
Show Gist options
  • Save brendanmckenzie/0e2005ffa9cab3a7ccf89e98f9ecbef0 to your computer and use it in GitHub Desktop.
Save brendanmckenzie/0e2005ffa9cab3a7ccf89e98f9ecbef0 to your computer and use it in GitHub Desktop.
import { PostGraphilePlugin } from "postgraphile";
import * as graphql from "graphql";
const DisableIntrospection: PostGraphilePlugin = {
["postgraphile:validationRules:static"](args, _context) {
if (process.env.ALLOW_INTROSPECTION) {
return [args];
}
return [
...args,
(context: graphql.ValidationContext) => {
return {
Field(node) {
if (
node.name.value === "__schema" ||
node.name.value === "__type"
) {
context.reportError(
new graphql.GraphQLError(
"GraphQL introspection is not allowed, but the query contained __schema or __type",
[node]
)
);
}
},
};
},
];
},
};
export default DisableIntrospection;
@benjie
Copy link

benjie commented Jan 7, 2021

On line 7 you need to return the args too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment