graphql-yoga
Version:
24 lines (23 loc) • 801 B
JavaScript
import { GraphQLError } from 'graphql';
export function isValidMethodForGraphQL(method) {
return method === 'GET' || method === 'POST' || method === 'QUERY';
}
export function useCheckMethodForGraphQL() {
return {
onRequestParse({ request }) {
if (!isValidMethodForGraphQL(request.method)) {
throw new GraphQLError('GraphQL only supports GET, POST and QUERY requests.', {
extensions: {
http: {
status: 405,
headers: {
Allow: 'GET, POST, QUERY',
},
},
code: 'BAD_REQUEST',
},
});
}
},
};
}