Skip to content

Configuring HTTP Allowed Methods on Gateway #6255

Answered by ardatan
curtis-thompson asked this question in Q&A
Discussion options

You must be logged in to vote

You can write a custom plugin (Mesh uses GraphQL Yoga so you can use GraphQL Yoga hooks -> https://the-guild.dev/graphql/yoga-server/docs/features/envelop-plugins#onrequest);

import { MeshPlugin } from '@graphql-mesh/types';

const allowPOSTOnly: MeshPlugin = {
   onRequest({ request, fetchAPI, endResponse }) {
     if (request.method !== 'POST') {
        endResponse(
          new fetchAPI.Response(null, { status: 405, statusText: 'Method Not Allowed' })
     }
   }
}

const plugins = [allowPOSTOnly];

export default plugins];

Then pass it as an additional plugin; https://the-guild.dev/graphql/mesh/docs/plugins/plugins-introduction#additional-plugins

additionalEnvelopPlugins: "./custom-…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@curtis-thompson
Comment options

@ardatan
Comment options

@curtis-thompson
Comment options

Answer selected by curtis-thompson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants