apollo-server-native
v3.1.0
Published
Apollo Server integration for native Node.js HTTP
Downloads
15
Maintainers
Readme
Apollo Server integration for native Node.js HTTP
This integration of Apollo Server works with native Node.js HTTP.
Installation
Install package with yarn or npm:
yarn add apollo-server-native graphqlnpm install apollo-server-native graphqlExample 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}`
)
)