graphql-yoga
Version:
<div align="center"><img src="./website/public/cover.png" width="720" /></div>
23 lines (22 loc) • 736 B
JavaScript
import { createGraphQLError } from '@graphql-tools/utils';
export function isValidMethodForGraphQL(method) {
return method === 'GET' || method === 'POST';
}
export function useCheckMethodForGraphQL() {
return {
onRequest({ request }) {
if (!isValidMethodForGraphQL(request.method)) {
throw createGraphQLError('GraphQL only supports GET and POST requests.', {
extensions: {
http: {
status: 405,
headers: {
Allow: 'GET, POST',
},
},
},
});
}
},
};
}