graphql-yoga
Version:
28 lines (27 loc) • 956 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidMethodForGraphQL = isValidMethodForGraphQL;
exports.useCheckMethodForGraphQL = useCheckMethodForGraphQL;
const graphql_1 = require("graphql");
function isValidMethodForGraphQL(method) {
return method === 'GET' || method === 'POST';
}
function useCheckMethodForGraphQL() {
return {
onRequestParse({ request }) {
if (!isValidMethodForGraphQL(request.method)) {
throw new graphql_1.GraphQLError('GraphQL only supports GET and POST requests.', {
extensions: {
http: {
status: 405,
headers: {
Allow: 'GET, POST',
},
},
code: 'BAD_REQUEST',
},
});
}
},
};
}