applyGraphQL(app) { if (!app || !app.use) { (0, _requiredParameter.default)('You must provide an Express.js app instance!'); } app.use(this.config.graphQLPath, (0, _graphqlUpload.graphqlUploadExpress)({ maxFileSize: this._transformMaxUploadSizeToBytes(this.parseServer.config.maxUploadSize || '20mb') })); app.use(this.config.graphQLPath, (0, _cors.default)()); app.use(this.config.graphQLPath, _bodyParser.default.json()); app.use(this.config.graphQLPath, _middlewares.handleParseHeaders); app.use(this.config.graphQLPath, _middlewares.handleParseErrors); app.use(this.config.graphQLPath, (0, _expressApollo.graphqlExpress)(async req => await this._getGraphQLOptions(req))); }
server.use('/graphql', bodyParser.json(), graphqlExpress(request => ({ schema, rootValue, context: context(request.headers, process.env), })));
//async function due to the async nature of grabbing all of our introspect schemas (async function () { try { //promise.all to grab all remote schemas at the same time, we do not care what order they come back but rather just when they finish allSchemas = await Promise.all(endpoints.map(ep => getIntrospectSchema(ep))); //create function for /graphql endpoint and merge all the schemas app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: mergeSchemas({ schemas: allSchemas }) })); //start up a graphql endpoint for our main server app.listen(PORT, () => console.log('GraphQL API listening on port:' + PORT)); } catch (error) { console.log('ERROR: Failed to grab introspection queries', error); } })();
app.use('/graphql', graphqlExpress(req => { return { schema, context: { showConnector: new ShowConnector(config.tvMazeUrl), postStorage: new PostStorage(conn), commentStorage: new CommentStorage(conn) } } }));
function onDatabaseConnect() { console.log("Connected to database"); const app = express(); app.use("/graphql", bodyParser.json(), graphqlExpress(request => { return { schema: schema, context: { authorization: request.get("authorization"), }, }; })); app.use("/graphiql", graphiqlExpress({ endpointURL: "/graphql" })); app.listen(APP_PORT, () => { console.info(`Server listening at port ${APP_PORT}`); }); }
graphqlExpress(request => ({ schema, rootValue: { request }, debug: __DEV__, context: { request, user: request.user, loaders: createDataLoaders(request), }, formatError: error => { if (__DEV__) { return { message: error.message, locations: error.locations, stack: error.stack, path: error.path, }; } return { message: error.message, }; }, }))
expect(server.post).toHaveBeenCalledWith('/graphql', bodyParser.json(), graphqlExpress()); });
app.use(graphqlEndpoint, bodyParser.json(), graphqlExpress((req) => { console.log("req:",req.user); return { schema, context: { models, SECRET: process.env.SECRET, SECRET2: process.env.SECRET2, user: req.user, isAdmin: req.isAdmin, isTeacher: req.isTeacher, } }}) );
// graphql endpoint app.use('/api', bodyParser.json(), auth, graphqlExpress(req => ({ schema: schema, context: { user: req.user } }) ) )
// connect schema with graphql app.use('/graphql', bodyParser.json(), graphqlExpress(({ currentUser }) => ({ schema, context: { User, currentUser } })) );
app.use('/graphql', bodyParser.json(), graphqlExpress(req => ({ schema, context: req.context })))
//async function due to the async nature of grabbing all of our introspect schemas (async function () { try { //promise.all to grab all remote schemas at the same time, we do not care what order they come back but rather just when they finish allSchemas = await Promise.all(endpoints.map(ep => getIntrospectSchema(ep))); //create function for /graphql endpoint and merge all the schemas app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: mergeSchemas({ schemas: allSchemas }) })); //start up a graphql endpoint for our main server app.listen(PORT, () => console.log('GraphQL API listening on port:' + PORT)); } catch (error) { console.log('ERROR: Failed to grab introspection queries', error); } })();