Answers for "graphql yoga access http headers"

0

graphql yoga access http headers

import { GraphQLServer } from 'graphql-yoga'
// ... or using `require()`
// const { GraphQLServer } = require('graphql-yoga')

const typeDefs = `
  type Query {
    showHeader(headerName: String): String!
  }
`

const resolvers = {
  Query: {
    showHeader: (_, { headerName }, ctx) => ctx.request.get(headerName),
  },
}

const server = new GraphQLServer({ typeDefs, resolvers, context: req => ({ ...req }) })
server.start(() => console.log('Server is running on localhost:4000'))
Posted by: Guest on March-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language