Skip to content

Commit

Permalink
fix(core): Fix Asset uploads on Node v13+
Browse files Browse the repository at this point in the history
Fixes #396
  • Loading branch information
michaelbromley committed Feb 18, 2021
1 parent f109436 commit 049c75c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"graphql-iso-date": "^3.6.1",
"graphql-tag": "^2.11.0",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^11.0.0",
"http-proxy-middleware": "^1.0.5",
"i18next": "^19.8.1",
"i18next-express-middleware": "^2.0.0",
Expand Down
17 changes: 14 additions & 3 deletions packages/core/src/api/api.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Module } from '@nestjs/common';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { graphqlUploadExpress } from 'graphql-upload';
import path from 'path';

import { ConfigService } from '../config/config.service';
import { DataImportModule } from '../data-import/data-import.module';
import { I18nModule } from '../i18n/i18n.module';
import { ServiceModule } from '../service/service.module';

import { AdminApiModule, ApiSharedModule, ShopApiModule } from './api-internal-modules';
import { CustomFieldRelationResolverService } from './common/custom-field-relation-resolver.service';
import { RequestContextService } from './common/request-context.service';
import { configureGraphQLModule } from './config/configure-graphql-module';
import { AuthGuard } from './middleware/auth-guard';
Expand Down Expand Up @@ -70,4 +71,14 @@ import { ValidateCustomFieldsInterceptor } from './middleware/validate-custom-fi
},
],
})
export class ApiModule {}
export class ApiModule implements NestModule {
constructor(private configService: ConfigService) {}
configure(consumer: MiddlewareConsumer): any {
const { adminApiPath, shopApiPath } = this.configService.apiOptions;
const { uploadMaxFileSize } = this.configService.assetOptions;

consumer
.apply(graphqlUploadExpress({ maxFileSize: uploadMaxFileSize }))
.forRoutes(adminApiPath, shopApiPath);
}
}
6 changes: 3 additions & 3 deletions packages/core/src/api/config/configure-graphql-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ async function createGraphQLOptions(
typeDefs: printSchema(builtSchema),
include: [options.resolverModule, ...getDynamicGraphQlModulesForPlugins(options.apiType)],
resolvers,
uploads: {
maxFileSize: configService.assetOptions.uploadMaxFileSize,
},
// We no longer rely on the upload facility bundled with Apollo Server, and instead
// manually configure the graphql-upload package. See https://github.com/vendure-ecommerce/vendure/issues/396
uploads: false,
playground: options.playground || false,
debug: options.debug || false,
context: (req: any) => req,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/config/generate-resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StockMovementType } from '@vendure/common/lib/generated-types';
import { GraphQLUpload } from 'apollo-server-core';
import { IFieldResolver, IResolvers } from 'apollo-server-express';
import { GraphQLSchema } from 'graphql';
import { GraphQLDateTime } from 'graphql-iso-date';
import GraphQLJSON from 'graphql-type-json';
import { GraphQLUpload } from 'graphql-upload';

import { REQUEST_CONTEXT_KEY } from '../../common/constants';
import {
Expand Down
32 changes: 31 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9086,6 +9086,11 @@ fs-capacitor@^2.0.4:
resolved "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-2.0.4.tgz#5a22e72d40ae5078b4fe64fe4d08c0d3fc88ad3c"
integrity sha512-8S4f4WsCryNw2mJJchi46YgB6CR5Ze+4L1h8ewl9tEpL4SJ3ZO+c/bS4BWhB8bK+O3TMqhuZarTitd0S0eh2pA==

fs-capacitor@^6.1.0:
version "6.2.0"
resolved "https://registry.npmjs.org/fs-capacitor/-/fs-capacitor-6.2.0.tgz#fa79ac6576629163cb84561995602d8999afb7f5"
integrity sha512-nKcE1UduoSKX27NSZlg879LdQc94OtbOsEmKMN2MBNudXREvijRKx2GEBsTMTfws+BrbkJoEuynbGSVRSpauvw==

fs-constants@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
Expand Down Expand Up @@ -9642,6 +9647,17 @@ graphql-type-json@^0.3.2:
resolved "https://registry.npmjs.org/graphql-type-json/-/graphql-type-json-0.3.2.tgz#f53a851dbfe07bd1c8157d24150064baab41e115"
integrity sha512-J+vjof74oMlCWXSvt0DOf2APEdZOCdubEvGDUAlqH//VBYcOYsGgRW7Xzorr44LvkjiuvecWc8fChxuZZbChtg==

graphql-upload@^11.0.0:
version "11.0.0"
resolved "https://registry.npmjs.org/graphql-upload/-/graphql-upload-11.0.0.tgz#24b245ff18f353bab6715e8a055db9fd73035e10"
integrity sha512-zsrDtu5gCbQFDWsNa5bMB4nf1LpKX9KDgh+f8oL1288ijV4RxeckhVozAjqjXAfRpxOHD1xOESsh6zq8SjdgjA==
dependencies:
busboy "^0.3.1"
fs-capacitor "^6.1.0"
http-errors "^1.7.3"
isobject "^4.0.0"
object-path "^0.11.4"

graphql-upload@^8.0.2:
version "8.1.0"
resolved "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.1.0.tgz#6d0ab662db5677a68bfb1f2c870ab2544c14939a"
Expand Down Expand Up @@ -10968,6 +10984,11 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=

isobject@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0"
integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA==

isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
Expand Down Expand Up @@ -13891,14 +13912,23 @@ [email protected], npm-package-arg@^8.0.0:
semver "^5.6.0"
validate-npm-package-name "^3.0.0"

npm-packlist@1.1.12, npm-packlist@^1.1.12, npm-packlist@^1.1.6, npm-packlist@^1.4.4:
npm-packlist@^1.1.12, npm-packlist@^1.1.6:
version "1.1.12"
resolved "https://registry.yarnpkg.com/npm-packlist/-/npm-packlist-1.1.12.tgz#22bde2ebc12e72ca482abd67afc51eb49377243a"
integrity sha512-WJKFOVMeAlsU/pjXuqVdzU0WfgtIBCupkEVwn+1Y0ERAbUfWw8R4GjgVbaKnUjRoD2FoQbHOCbOyT5Mbs9Lw4g==
dependencies:
ignore-walk "^3.0.1"
npm-bundled "^1.0.1"

npm-packlist@^1.4.4:
version "1.4.8"
resolved "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz#56ee6cc135b9f98ad3d51c1c95da22bbb9b2ef3e"
integrity sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==
dependencies:
ignore-walk "^3.0.1"
npm-bundled "^1.0.1"
npm-normalize-package-bin "^1.0.1"

[email protected]:
version "6.1.0"
resolved "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-6.1.0.tgz#2befed87b0fce956790f62d32afb56d7539c022a"
Expand Down

0 comments on commit 049c75c

Please sign in to comment.