JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q32306F
  • License MIT

Apollo Server integration for HTTP, HTTPS and HTTP2

Package Exports

  • apollo-server-native

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (apollo-server-native) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Apollo Server integration for HTTP, HTTPS and HTTP2

npm version

This integration of Apollo Server works with native HTTP, HTTPS and HTTP2.

Example

Install apollo-server-native graphql graphql-tag graphql-tools packages

const http = require('http')
const { nativeGraphql, nativeGraphiql } = require('apollo-server-native')
const { gql } = require('apollo-server-core')
const { makeExecutableSchema } = require('graphql-tools')

const typeDefs = gql`
  type Query {
    "A simple type for getting started!"
    hello: String
  }
`

const resolvers = {
  Query: {
    hello: () => 'world'
  }
}

const schema = makeExecutableSchema({
  typeDefs,
  resolvers
})

const server = http.createServer((req, res) => {
  if (req.method === 'GET') {
    const graphiqlHandler = nativeGraphiql({ endpointURL: '/' })
    graphiqlHandler(req, res)
  } else {
    const graphqlHandler = nativeGraphql({ schema })
    graphqlHandler(req, res)
  }
})

server.listen(3000)

Example with GraphQL Playground

Install apollo-server-native graphql graphql-tag graphql-tools graphql-playground-html packages

const http = require('http')
const { nativeGraphql } = require('apollo-server-native')
const { gql } = require('apollo-server-core')
const { makeExecutableSchema } = require('graphql-tools')
const { renderPlaygroundPage } = require('graphql-playground-html')

const typeDefs = gql`
  type Query {
    "A simple type for getting started!"
    hello: String
  }
`

const resolvers = {
  Query: {
    hello: () => 'world'
  }
}

const schema = makeExecutableSchema({
  typeDefs,
  resolvers
})

const server = http.createServer((req, res) => {
  if (req.method === 'GET') {
    const playground = renderPlaygroundPage({ version: '1.7.0' })
    res.setHeader('Content-Type', 'text/html')
    res.write(playground)
    res.end()
  } else {
    const graphqlHandler = nativeGraphql({ schema })
    graphqlHandler(req, res)
  }
})

server.listen(3000)