apollo-server-native
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

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}`
  )
)

Package Sidebar

Install

npm i apollo-server-native

Weekly Downloads

2

Version

3.1.0

License

MIT

Unpacked Size

19.4 kB

Total Files

15

Last publish

Collaborators

  • adnsio