📜  graphql yoga 访问 http 标头 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:51.898000             🧑  作者: Mango

代码示例1
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'))