Skip to content

dflor003/graphql-anywhere-mongodb-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-anywhere-mongodb-express

Express middleware that serves up an endpoint and optionally graphiql that processes schemaless mongodb graphql requests using graphql-anywhere-mongodb.

IMPORTANT: This middleware is mostly for demo purposes. You should not expose arbitrary MongoDB collections via an endpoint. In real-world scenarios, you would just use graphql-anywhere-mongodb by itself on the server-side to read unstructured data from MongoDB.

Installation

Install via npm:

npm install --save graphql-anywhere-mongodb graphql-anywhere-mongodb-express

Alternatively install via yarn:

yarn add graphql-anywhere-mongodb graphql-anywhere-mongodb-express

Usage

Add the app to your expressjs server as an endpoint:

import * as express from 'express';
import mongoGraphql from 'graphql-anywhere-mongodb-express';

const app = express();

...
const mongoUri = process.env.MONGO_URI;
app.use('/graphql', mongoGraphql({
  uri: mongoUri, // Can initialize via mongo URI

  graphiql: true, // Optionally enable graphiql

  // Optional whitelist of collections that can be queried
  whitelist: ['restaurants'],
}));

// Alternatively can pass an existing mongodb connection
// from the official node mongodb driver
app.use('/graphql', mongoGraphql({
  connection: existingConnection,
}));

About

express middleware for graphql-anywhere-mongodb

Resources

License

Stars

Watchers

Forks

Packages

No packages published