2.4.8 • Published 5 years ago

apollo-server-uwebsockets v2.4.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

title: uWebSockets.js

description: Setting up Apollo Server with uWebSockets.js

npm version Build Status Coverage Status Join the community on Spectrum

This is the uWebSockets.js integration for the Apollo community GraphQL Server. Read the docs. Read the CHANGELOG.

uWebSockets.js

This example demonstrates how to setup a simple microservice, using uWebSosckets.js, that handles incoming GraphQL requests via the default /graphql endpoint.

1) Package installation.

npm install --save uNetworking/uWebSockets.js#v15.2.0 apollo-server-uwebsockets graphql

2) index.js

const { App } = require('uWebSockets.js')
const { ApolloServer, makeExecutableSchema } = require('apollo-server-uwebsockets')

const schema = makeExecutableSchema({
  typeDefs: `
    type Query {
      foo: String!
    }
  `
})

const apollo = new ApolloServer({
  schema,
  introspection: true,
  mockEntireSchema: true,
})

const app = App({})

apollo.attachHandlers({ app })

app.listen(3000, (token) => {
  if (token) {
    console.log('Listening to port ' + 3000);
  } else {
    console.log('Failed to listen to port ' + 3000);
  }
});

3) package.json

{
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  }
}

4) After an npm start, access http://localhost:3000/graphql in your browser to run queries using graphql-playground, or send GraphQL requests directly to the same URL.

Contribute

Clone the apollo-server repository npm install cd apollo-server/packages/apollo-server-uwebsockets npm pack