Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Parse bodies as JSON
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// In development, we use webpack server
if (process.env.NODE_ENV === 'production') {
app.use(express.static(process.env.PUBLIC_DIR, {
maxAge: '180 days'
}))
}
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}))
app.use('/graphql', graphqlExpress({
graphiql: true,
pretty: true,
schema,
mocks,
allowUndefinedInResolve: false
}))
// This middleware should be last. Return the React app only if no other route is hit.
app.use(appRenderer)
app.listen(port, () => {
log.info(`Node app is running on port ${port}`)
})
const express = require('express')
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express')
const bodyParser = require('body-parser')
const cors = require('cors')
const schema = require('./schema')
const app = express()
app.use('/graphql', cors(), bodyParser.json(), graphqlExpress({ schema }))
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))
app.listen(3001, function () {
console.log('Our Node server is up and running on port 3001!')
})
export function startExpress(graphqlOptions) {
app.use(bodyParser.json())
app.use('/graphql', apollo.graphqlExpress(graphqlOptions))
app.use('/', apollo.graphiqlExpress({endpointURL: '/graphql'}))
app.listen(expressPort, () => {
console.log(`Express server is listen on ${expressPort}`)
})
}
constructor(private readonly config: GraphQLServerConfig) {
const app = express();
app.use(cors());
app.get('/', (req, res) => { res.redirect('/graphiql')});
app.use('/graphql', bodyParser.json(), graphqlExpress(() => this.getGraphQLOptions()));
app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
this.server = app.listen(config.port, () => {
console.log(`GraphQL server started on http://localhost:${config.port}.`);
});
}
return new Promise(async (res, rej) => {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api', cors(), graphqlExpress({
schema,
}));
app.use('/graphql-ui', graphiqlExpress({
endpointURL: '/api',
}));
await createSchema().catch((err) => rej(err));
res(app);
});
};
export function addGraphQL(server) {
server.use('/graphql', bodyParser.json(),
graphqlExpress({
schema: jsSchema
}));
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
}
import express from 'express';
//import graphqlExpress from 'express-graphql';
import {
graphqlExpress,
graphiqlExpress
} from 'graphql-server-express';
import bodyParser from 'body-parser';
import schema from './schema';
const PORT = 3000;
const server = express();
const graphiql = true;
server.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
schema,
//context: context(request.headers, process.env),
})));
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
query: `# Welcome to GraphiQL
query PostsForAuthor {
author(id: 1) {
firstName
lastName
posts {
id
title
votes
constructor(private readonly config: GraphQLServerConfig) {
const app = express();
app.use(cors());
app.get('/', (req, res) => { res.redirect('/graphiql')});
app.use('/graphql', bodyParser.json(), graphqlExpress(() => this.getGraphQLOptions()));
app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
this.server = app.listen(config.port, () => {
logger.info(`GraphQL server started on http://localhost:${config.port}.`);
});
}
export default (server, options) => {
if (process.env.NODE_ENV !== 'production') {
server.get('/graphql', graphiqlExpress({ endpointURL: '/graphql' }));
}
const { schema, getContext } = Schema.getSchema();
server.post(
'/graphql',
graphqlExpress(request => ({ schema, context: getContext(request) }))
);
};