Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require("fs");
const path = require("path");
const express = require("express");
const { postgraphile } = require("postgraphile");
const PostGraphileUploadFieldPlugin = require("postgraphile-plugin-upload-field");
const { graphqlUploadExpress } = require("graphql-upload");
const app = express();
const UPLOAD_DIR_NAME = "uploads";
// Serve uploads as static resources
app.use(`/${UPLOAD_DIR_NAME}`, express.static(path.resolve(UPLOAD_DIR_NAME)));
// Attach multipart request handling middleware
app.use(graphqlUploadExpress());
app.use(
postgraphile("postgres://localhost:5432/upload_example", "public", {
graphiql: true,
enableCors: true,
appendPlugins: [PostGraphileUploadFieldPlugin],
graphileBuildOptions: {
uploadFieldDefinitions: [
{
match: ({ column }) => column === "header_image_file",
resolve: resolveUpload,
},
],
},
})
);
session({
secret: process.env.SESSION_KEY,
resave: false,
saveUninitialized: true,
cookie: { httpOnly: true, maxAge: 86400000 },
}),
);
initPassport(app);
app.use(logger('dev'));
app.use('/account', require('./api/routes/account-route'));
app.use(
'/graphql',
// isAuthenticated,
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
graphqlHTTP({
schema,
graphiql: process.env.NODE_ENV === 'development',
}),
);
app.use((req, res, next) => {
next(createError(404));
});
app.use((err, req, res, next) => {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// 나중에 에러 처리는 상세히
res.status(err.status || 500).json({});
applyGraphQL(app) {
if (!app || !app.use) {
requiredParameter('You must provide an Express.js app instance!');
}
app.use(
this.config.graphQLPath,
graphqlUploadExpress({
maxFileSize: this._transformMaxUploadSizeToBytes(
this.parseServer.config.maxUploadSize || '20mb'
),
})
);
app.use(this.config.graphQLPath, corsMiddleware());
app.use(this.config.graphQLPath, bodyParser.json());
app.use(this.config.graphQLPath, handleParseHeaders);
app.use(this.config.graphQLPath, handleParseErrors);
app.use(
this.config.graphQLPath,
graphqlExpress(async req => await this._getGraphQLOptions(req))
);
}
import { assign } from '@ctx-core/object'
const { graphqlUploadExpress } = require('graphql-upload')
const { ApolloServer } = require('apollo-server-express')
import { GraphQLSchema, TypeDefs, Resolvers, } from '@ctx-core/graphql'
const graphql_upload__express = graphqlUploadExpress()
/**
* @typedef opts__express_graphql
* @property {GraphQLSchema} schema
* @property {boolean} [graphiql]
* @property [rootValue]
* @property {boolean} [pretty]
* @property {function} [formatError]
* @property {[]} [validationRules]
*/
export type opts__express_graphql = {
schema: GraphQLSchema
graphiql?: boolean
rootValue?: any
pretty: boolean
formatError?: Function
validationRules?: []