Browse Source

WIP Graphql-upload ESM hell

Michael Bromley 2 years ago
parent
commit
bbe8d52f25

+ 1 - 1
packages/core/package.json

@@ -85,7 +85,7 @@
     "@types/csv-parse": "^1.2.2",
     "@types/express": "^4.17.8",
     "@types/faker": "^4.1.7",
-    "@types/graphql-upload": "^8.0.4",
+    "@types/graphql-upload": "^15.0.2",
     "@types/gulp": "^4.0.7",
     "@types/mime-types": "^2.1.0",
     "@types/ms": "^0.7.31",

+ 3 - 3
packages/core/src/api/api.module.ts

@@ -1,6 +1,5 @@
 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';
@@ -75,10 +74,11 @@ import { ValidateCustomFieldsInterceptor } from './middleware/validate-custom-fi
 })
 export class ApiModule implements NestModule {
     constructor(private configService: ConfigService) {}
-    configure(consumer: MiddlewareConsumer): any {
+    async configure(consumer: MiddlewareConsumer) {
         const { adminApiPath, shopApiPath } = this.configService.apiOptions;
         const { uploadMaxFileSize } = this.configService.assetOptions;
-
+        // @ts-ignore
+        const { default: graphqlUploadExpress } = await import('graphql-upload/graphqlUploadExpress.mjs');
         consumer
             .apply(graphqlUploadExpress({ maxFileSize: uploadMaxFileSize }))
             .forRoutes(adminApiPath, shopApiPath);

+ 1 - 1
packages/core/src/api/config/configure-graphql-module.ts

@@ -92,7 +92,7 @@ async function createGraphQLOptions(
     options: GraphQLApiOptions,
 ): Promise<GqlModuleOptions> {
     const builtSchema = await buildSchemaForApi(options.apiType);
-    const resolvers = generateResolvers(
+    const resolvers = await generateResolvers(
         configService,
         customFieldRelationResolverService,
         options.apiType,

+ 4 - 2
packages/core/src/api/config/generate-resolvers.ts

@@ -2,7 +2,6 @@ import { IFieldResolver, IResolvers } from '@graphql-tools/utils';
 import { StockMovementType } from '@vendure/common/lib/generated-types';
 import { GraphQLFloat, GraphQLSchema } from 'graphql';
 import { GraphQLDateTime, GraphQLJSON, GraphQLSafeInt } from 'graphql-scalars';
-import { GraphQLUpload } from 'graphql-upload';
 
 import { REQUEST_CONTEXT_KEY } from '../../common/constants';
 import {
@@ -25,7 +24,7 @@ import { GraphQLMoney } from './money-scalar';
  * Generates additional resolvers required for things like resolution of union types,
  * custom scalars and "relation"-type custom fields.
  */
-export function generateResolvers(
+export async function generateResolvers(
     configService: ConfigService,
     customFieldRelationResolverService: CustomFieldRelationResolverService,
     apiType: ApiType,
@@ -83,6 +82,9 @@ export function generateResolvers(
         },
     };
 
+    // @ts-ignore
+    const { default: GraphQLUpload } = await import('graphql-upload/GraphQLUpload.mjs');
+
     const commonResolvers = {
         JSON: GraphQLJSON,
         DateTime: GraphQLDateTime,

+ 4 - 4
yarn.lock

@@ -4504,10 +4504,10 @@
   dependencies:
     "@types/node" "*"
 
-"@types/graphql-upload@^8.0.4":
-  version "8.0.12"
-  resolved "https://registry.yarnpkg.com/@types/graphql-upload/-/graphql-upload-8.0.12.tgz#224738b8885bad8d50fb690b67bbe10bbcdef032"
-  integrity sha512-M0ZPZqNUzKNB16q5woEzgG/Q8DjICV80K7JvDSRnDmDFfrRdfFX/n6PbmqAN7gCzECcHVnw1gk6N4Cg0FwxCqA==
+"@types/graphql-upload@^15.0.2":
+  version "15.0.2"
+  resolved "https://registry.yarnpkg.com/@types/graphql-upload/-/graphql-upload-15.0.2.tgz#f6fa1bee2337c6798fb10438a851ed80e3a6f402"
+  integrity sha512-dK4GN/JbMmgHbsKZaUWVYwaLMCwIR0QMBcFz+jb4xj/cRLq1yo2VfnoFvnP5yCw7W4IgGgW7JRwEvM4jn0ahlA==
   dependencies:
     "@types/express" "*"
     "@types/koa" "*"