Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://github.com/graphql/express-graphql/blob/3fa6e68582d6d933d37fa9e841da5d2aa39261cd/src/index.js#L257
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 {
schema,
context: Object.assign({}, context),
debug: true,
};
}));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}));
app.listen(PORT, () => console.log( // eslint-disable-line no-console
`API Server is now running on http://localhost:${PORT}`
));
// WebSocket server for subscriptions
const websocketServer = createServer((request, response) => {
response.writeHead(404);
response.end();
});
websocketServer.listen(WS_PORT, () => console.log( // eslint-disable-line no-console
`Websocket Server is now running on http://localhost:${WS_PORT}`
));
// 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}`)
})
export default async function startServer (
{isDev = false, isTest = false}, dbConnection?: Connection
) {
const connection = dbConnection || await getConnection()
const app = await getServer(connection, isDev)
// Adds Enviornment variables from .enviornment
const env = (isDev && 'development') || (isTest && 'test') || 'production'
app.use('/graphql',ensureAuthenticated, buildGraphQLRouteHandler());
app.use('/graphiql',ensureAuthenticated, graphiqlExpress({endpointURL: '/graphql'}))
return app
}
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!')
})
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}.`);
});
}
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);
});
};