Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dflor003/graphql-anywhere-mongodb-express
express middleware for graphql-anywhere-mongodb
https://github.com/dflor003/graphql-anywhere-mongodb-express
Last synced: 3 days ago
JSON representation
express middleware for graphql-anywhere-mongodb
- Host: GitHub
- URL: https://github.com/dflor003/graphql-anywhere-mongodb-express
- Owner: dflor003
- License: mit
- Created: 2017-07-10T02:19:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-19T20:49:39.000Z (almost 7 years ago)
- Last Synced: 2024-10-12T13:28:27.406Z (about 1 month ago)
- Language: TypeScript
- Size: 57.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-anywhere-mongodb-express
Express middleware that serves up an endpoint and optionally graphiql that processes schemaless mongodb graphql requests using [graphql-anywhere-mongodb](https://github.com/dflor003/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](https://github.com/dflor003/graphql-anywhere-mongodb) by itself on the server-side to read unstructured data from MongoDB.
## Installation
Install via `npm`:
```sh
npm install --save graphql-anywhere-mongodb graphql-anywhere-mongodb-express
```Alternatively install via `yarn`:
```sh
yarn add graphql-anywhere-mongodb graphql-anywhere-mongodb-express
```## Usage
Add the app to your expressjs server as an endpoint:
```js
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 URIgraphiql: 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,
}));
```