Skip to content

Using graphql mesh with graphql shield #4210

Answered by sesmi123
chengyak asked this question in General
Discussion options

You must be logged in to vote

Try like this:

.meshrc.yaml

sources:
  - name: MyApi
    graphql:
    endpoint: http://localhost:4001/graphql
    transforms:
      - resolversComposition:
          mode: wrap
          compositions:
            - resolver: 'Query.*'
              composer: src/composers#isAuth
            - resolver: 'Mutation.*'
              composer: src/composers#isAuth

src/composers.ts

module.exports = {

    isAuth: next => async (root, args, context, info) => {
        // verify token in context.headers.authorization
        if(!authorized){
            throw new Error('Unauthorized')
        }
        return next(root, args, context, info)
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chengyak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants