This package has been deprecated

Author message:

Please use graphyne-server for Express integration

graphyne-express
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Graphyne Server Express

The Express and Connect integration of Graphyne.

Install

npm i graphyne-express graphql
// or
yarn add graphyne-express graphql

Usage

Check out the example.

const express = require('express');
const { GraphyneServer } = require('graphyne-express');

const graphyne = new GraphyneServer(options);

var app = express();

// GraphQL API
app.all('/graphql', graphyne.createHandler());
// GraphiQL
app.get('/___graphql', graphyle.createHandler({
  path: '/graphql' // Must be set: GraphQL's path, not GraphiQL
  graphiql: true
}))

app.listen(4000);
console.log('Running a GraphQL API server at http://localhost:4000/graphql');

API

new GraphyneServer(options)

Refer to API.

GraphyneServer#createHandler(options)

Create a handler for Express/Connect Router. Refer to API.

When options.path and options.graphiql.path is not set, they do not default to /graphql and /___graphql respectively. Instead, graphyne-express wouuld response to all incoming requests. This is because routing is delegated to Express/Connect Router (see in Usage).

Using with GraphiQL

If options.graphiql is to be used, options.path must be set. This is because routing is delegated to Express/Connect Router, so Graphyle is not aware of where the GraphQL endpoint is exposed.

Using with Connect

Connect router only has .use, which matches only the beginning of the URL. Therefore, GraphQL endpoints will also be exposed in sub-directories if path is not set.

connect.use('/graphql', graphyne.createHandler())
// `/graphql`, `/graphql/foo`, `/graphql/foo/bar` are all GraphQL endpoint.
// You should explicitly defining options.path
connect.use('/graphql', graphyne.createHandler({
  path: '/graphql'
}))

Same things applies to options.graphiql.path.

License

MIT

Package Sidebar

Install

npm i graphyne-express

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

7.05 kB

Total Files

7

Last publish

Collaborators

  • hoangvvo