Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function(app, db) {
// Register graphql server
app.use("/graphql", auth.isAuthenticatedOrApiKey, ApolloServer( (req) => {
const query = req.query.query || req.body.query;
if (query && query.length > 2000) {
// None of our app's queries are this long
// Probably indicates someone trying to send an overly expensive query
throw new Error("Query too large.");
}
return {
graphiql: config.isDevMode(),
pretty: config.isDevMode(),
printErrors: config.isDevMode(),
schema: Schema,
resolvers: Resolvers,
logger: { log: (e) => console.error(e.stack) },
context: {
user: req.user,
export const createApolloServer = (givenOptions, givenConfig) => {
const config = _.extend(defaultConfig, givenConfig);
const graphQLServer = express();
graphQLServer.use(config.path, apolloServer(async (req) => {
let options,
user = null;
if (_.isFunction(givenOptions))
options = givenOptions(req);
else
options = givenOptions;
options = Object.assign({}, options)
// Get the token from the header
if (req.headers.authorization) {
const token = req.headers.authorization;
check(token, String);
const hashedToken = Accounts._hashLoginToken(token);
import express from 'express';
import { apolloServer } from 'apollo-server';
import Schema from './schema';
import Mocks from './mocks';
const GRAPHQL_PORT = 4321;
const graphQLServer = express();
graphQLServer.use('/graphql', apolloServer((req) => {
let headerCheck = req.headers['test-header'] === 'test-header';
return {
graphiql: true,
pretty: true,
schema: Schema,
mocks: Mocks(headerCheck)
};
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`
));
let app = express();
graphQLServer.use('/', apolloServer({
graphiql: true,
pretty: true,
schema: Definitions,
resolvers: Resolvers
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));
app.use(require('prerender-node').set('prerenderToken', privateSettings.prerenderToken ));
app.use(express.static('./dist'));
app.use('/graphql', apolloServer({
graphiql: true,
pretty: true,
schema: Definitions,
resolvers: Resolvers
}));
app.get('*', function response(req, res, next) {
res.sendFile(path.join(__dirname, '/index.html'));
});
app.listen(APP_PORT, () => {
console.log(`App is now running on http://localhost:${APP_PORT}`);
});
export default function ({ schema, resolvers }) {
const graphQLServer = express();
const GRAPHQL_PORT = 4000;
graphQLServer.use('/graphql', apolloServer({
graphiql: true,
pretty: true,
schema,
resolvers,
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));
WebApp.rawConnectHandlers.use(proxyMiddleware(`http://localhost:${GRAPHQL_PORT}/graphql`));
}
function registerGraphqlEndpoints(app, endpoints) {
for (var i = 0; i < endpoints.length; i++) {
var endpoint = endpoints[i];
app.use(endpoint.url, apollo.apolloServer({
graphiql: true,
pretty: true,
schema: endpoint.schema,
mocks: mocks
}));
}
}
export default function(app) {
app.use('/graphql', apolloServer((req) => ({
graphiql: true,
pretty: true,
context: {
Profiles: new Profiles
},
schema,
resolvers
})));
}