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