JSPM

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

Apollo Server integration for native Node.js HTTP

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 native Node.js HTTP

npm version

This integration of Apollo Server works with native Node.js HTTP.

Installation

Install package with yarn or npm:

yarn add apollo-server-native graphql
npm install apollo-server-native graphql

Example with HTTP

const http = require('http')
const { ApolloServer, gql } = require('apollo-server-native')

const typeDefs = gql`
  type Query {
    hello: String
  }
`

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

const apolloServer = new ApolloServer({ typeDefs, resolvers })

const server = http.createServer()

server.on('request', apolloServer.createHandler())

server.listen({ port: 3000 }, () =>
  console.log(
    `🚀 Server ready at http://localhost:3000${apolloServer.graphqlPath}`
  )
)

Example with HTTPS

const https = require('https')
const { ApolloServer, gql } = require('apollo-server-native')

const typeDefs = gql`
  type Query {
    hello: String
  }
`

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

const apolloServer = new ApolloServer({ typeDefs, resolvers })

const server = https.createServer({
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem'),
})

server.on('request', apolloServer.createHandler())

server.listen({ port: 3000 }, () =>
  console.log(
    `🚀 Server ready at https://localhost:3000${apolloServer.graphqlPath}`
  )
)