Skip to content

Instantly share code, notes, and snippets.

@helfer
Last active August 4, 2016 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save helfer/7f27ad78c7ac17e8358c82026092faba to your computer and use it in GitHub Desktop.
Save helfer/7f27ad78c7ac17e8358c82026092faba to your computer and use it in GitHub Desktop.
Using stored queries in Apollo Server
import express from 'express';
import { apolloExpress, OperationStore } from 'apollo-server';
import Schema from './schema';
const PORT = 3000;
const store = new OperationStore(Schema);
store.put('query testquery{ testString }');
const app = express();
const options = {
schema: Schema,
formatParams(params) {
params['query'] = store.get(params.operationName);
if (!params['query']){
throw new Error(`Only whitelisted queries are allowed. No query stored for ${params.operationName}`);
}
return params;
}
};
app.use('/graphql', apolloExpress(options));
app.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment