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}`
));
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!')
})
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',
}));
}
setup(app) {
const IS_DEVELOPMENT = process.env.NODE_ENV === 'development';
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/graphql', parseGraphQLHTTP({ schema }));
if (IS_DEVELOPMENT) {
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
}
},
};
var graphiqlExpress = require('graphql-server-express').graphiqlExpress;
module.exports = graphiqlExpress({
endpointURL: '/graphql',
query:
'{\n' +
' reports {\n' +
' id,\n' +
' type,\n' +
' title\n' +
' }\n' +
'}'
});
var graphiqlExpress = require('graphql-server-express').graphiqlExpress;
module.exports = graphiqlExpress({
endpointURL: '/graphql',
query:
'{\n' +
' reports {\n' +
' id,\n' +
' type,\n' +
' title\n' +
' }\n' +
'}'
});