Skip to content

Instantly share code, notes, and snippets.

@jlengstorf
Created December 18, 2017 03:37
Show Gist options
  • Save jlengstorf/9dd909f8240b91ef2e55aa232c66eb95 to your computer and use it in GitHub Desktop.
Save jlengstorf/9dd909f8240b91ef2e55aa232c66eb95 to your computer and use it in GitHub Desktop.
A quickstart server for GrAMPS

GrAMPS Quickstart

This is a minimal GraphQL gateway powered by GrAMPS 1.0. It sets up a /graphql endpoint + a GraphiQL interface and pulls in the xkcd GrAMPS data source.

This is useful for testing the following scenarios:

  1. Seeing @gramps/gramps in action and testing @gramps/cli with a custom gateway (see yarn dev).
  2. Testing the override of local data sources in development.
    • To test this:
      • clone the xkcd data source: git clone git@github.com:gramps-graphql/data-source-xkcd.git
      • run yarn dev -d ../path/to/data-source-xkcd
  3. Testing local development alongside other data sources.
    • To test this:
      • run npx degit gramps-graphql/data-source-base#feat/1.x-refactor my-data-source to create a new data source.
      • run yarn dev -d ../path/to/my-data-source in the quickstart root to fire up the new data source alongside the already installed xkcd data source.
{
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": ["babel-plugin-inline-import"],
"ignore": ["node_modules/**"]
}
import Express from 'express';
import getPort from 'get-port';
import bodyParser from 'body-parser';
import gramps from '@gramps/gramps';
import { GraphQLSchema } from 'graphql';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
// Data sources
import XKCD from '@gramps/data-source-xkcd';
async function startServer(app) {
const PORT = await getPort(8080);
app.listen(PORT, () => {
console.log(`\n=> http://localhost:${PORT}/graphiql`);
});
}
const GraphQLOptions = gramps({
dataSources: [XKCD],
});
const app = new Express();
app.use(bodyParser.json());
app.use('/graphql', graphqlExpress(GraphQLOptions));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
startServer(app);
{
"name": "gramps-quickstart",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
"start": "nodemon -e js,json,graphql index.js --exec babel-node",
"build": "babel index.js -d dist",
"predev": "yarn build",
"dev": "gramps dev -g dist"
},
"dependencies": {
"@gramps/data-source-xkcd": "^1.0.0-beta.4",
"@gramps/gramps": "^1.0.0-beta-7",
"apollo-server-express": "^1.2.0",
"body-parser": "^1.18.2",
"express": "^4.16.2",
"get-port": "^3.2.0",
"graphql": "^0.11.7",
"graphql-tools": "^2.7.2"
},
"devDependencies": {
"@gramps/cli": "^1.0.0-beta.3",
"babel-cli": "^6.26.0",
"babel-plugin-inline-import": "^2.0.6",
"babel-preset-env": "^1.6.1",
"nodemon": "^1.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment