Last active
August 4, 2016 22:17
-
-
Save helfer/7f27ad78c7ac17e8358c82026092faba to your computer and use it in GitHub Desktop.
Using stored queries in Apollo Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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