Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let graphQLServer = express();
// Configure multer to accept a single file per post
const storage = multer.memoryStorage();
graphQLServer.use(multer({
storage,
}).single('file'));
graphQLServer.use('/graphql', bodyParser.json(), apolloExpress((req) => ({
schema,
rootValue: req,
})
));
graphQLServer.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
WebApp.connectHandlers.use(Meteor.bindEnvironment(graphQLServer));
const Connectors = require('./connectors');
const executableSchema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers,
});
app.use('/graphql', bodyParser.json(), apolloExpress({
schema: executableSchema,
context: {
constructor: Connectors,
},
rootValue: 'Hello World',
}));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
app.listen(PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${PORT}/graphql`
));
const PORT = 8080;
const app = express();
app.use('/graphql', bodyParser.json(), apolloExpress({
schema,
resolvers,
context: {},
formatError(error) {
console.error(error.stack);
return error;
},
}));
app.use(
'/graphiql',
graphiqlExpress({
endpointURL: '/graphql',
})
);
app.listen(PORT, () => console.log(
`GraphQL Server is now running on http://localhost:${PORT}/graphiql`
));
process.on('exit', () => {
console.log('Shutting down!');
for (const connector of Object.values(connectors)) {
connector.close();
}
});
},
formatError: (error: Error) => {
console.error('GraphQL execution error:', error.stack);
return error.message;
},
formatResponse: (data: any) => {
console.info('✅ Outgoing GraphQL Response');
console.info('----------------------------');
console.info(JSON.stringify(data, null, ' '));
console.info('');
console.info('');
return data;
}
}));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
app.listen(PORT, () => console.info(`
🎉 GraphQL endpoint available at http://${HOST}:${PORT}/graphql
GraphiQL IDE available at http://${HOST}:${PORT}/graphiql
`));
});
try {
this.executableSchema = makeExecutableSchema({
typeDefs: typeDefs(Types, Query, Mutation),
resolvers: Resolvers,
logger: { log: this.customLogger.bind(this) },
});
} catch (err) {
this.logger(err);
}
collections.filter(this.hasPropertyInitialize.bind(this))
.forEach(this.executeInitialize.bind(this));
const apollo = apolloExpress(this.requestApolloExpress.bind(this));
this.Graphite.use('/graphql', cors(), bodyParser.json(), apollo);
this.Graphite.use('/graphiql', bodyParser.json(), graphiqlExpress({
endpointURL: '/graphql',
}));
this.Graphite.listen(GRAPHQL_PORT, this.listenGraphQl.bind(this, GRAPHQL_PORT));
this.Graphite.getSchema = () => getSchema(`http://localhost:${GRAPHQL_PORT}/graphql`);
return this.Graphite;
}