Skip to content

Commit

Permalink
Switch to a fork of graphql-upload
Browse files Browse the repository at this point in the history
This fork is identical to [email protected] except that it allows graphql@15
as a peer dependency (and bundles the TypeScript type definitions directly).

For #4865.

Note that we do plan to remove this integration in Apollo Server 3, but for now
we want you to be able to combine AS2 with graphql@15 and npm@7.
  • Loading branch information
glasser committed Feb 11, 2021
1 parent 3642ce8 commit c871152
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 44 deletions.
70 changes: 43 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"graphql-extensions": "file:packages/graphql-extensions"
},
"devDependencies": {
"@apollographql/graphql-upload-8-fork": "^8.1.3",
"@types/async-retry": "1.4.2",
"@types/aws-lambda": "8.10.66",
"@types/body-parser": "1.19.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": {
"@apollographql/apollo-tools": "^0.4.3",
"@apollographql/graphql-playground-html": "1.6.26",
"@types/graphql-upload": "^8.0.0",
"@apollographql/graphql-upload-8-fork": "^8.1.3",
"@types/ws": "^7.0.0",
"apollo-cache-control": "file:../apollo-cache-control",
"apollo-datasource": "file:../apollo-datasource",
Expand All @@ -44,7 +44,6 @@
"graphql-extensions": "file:../graphql-extensions",
"graphql-tag": "^2.11.0",
"graphql-tools": "^4.0.0",
"graphql-upload": "^8.0.2",
"loglevel": "^1.6.7",
"lru-cache": "^6.0.0",
"sha.js": "^2.4.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class ApolloServerBase {
}

if (this.uploadsConfig) {
const { GraphQLUpload } = require('graphql-upload');
const { GraphQLUpload } = require('@apollographql/graphql-upload-8-fork');
if (Array.isArray(resolvers)) {
if (resolvers.every(resolver => !resolver.Upload)) {
resolvers.push({ Upload: GraphQLUpload });
Expand Down
19 changes: 10 additions & 9 deletions packages/apollo-server-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ import runtimeSupportsUploads from './utils/runtimeSupportsUploads';
import { GraphQLScalarType } from 'graphql';
export { default as processFileUploads } from './processFileUploads';

// This is a conditional export intended to avoid traversing the
// entire module tree of `graphql-upload`. This only defined if the
// version of Node.js is >= 8.5.0 since those are the only Node.js versions
// which are supported by `graphql-upload@8`. Since the source of
// `graphql-upload` is not transpiled for older targets (in fact, it includes
// experimental ECMAScript modules), this conditional export is necessary
// to avoid modern ECMAScript from failing to parse by versions of Node.js
// which don't support it (yet — eg. Node.js 6 and async/await).
// This is a conditional export intended to avoid traversing the entire module
// tree of `graphql-upload` (or specifically, our fork of it). This only
// defined if the version of Node.js is >= 8.5.0 since those are the only
// Node.js versions which are supported by `graphql-upload@8`. Since the source
// of `graphql-upload` is not transpiled for older targets (in fact, it includes
// experimental ECMAScript modules), this conditional export is necessary to
// avoid modern ECMAScript from failing to parse by versions of Node.js which
// don't support it (yet — eg. Node.js 6 and async/await).
export const GraphQLUpload = runtimeSupportsUploads
? (require('graphql-upload').GraphQLUpload as GraphQLScalarType)
? (require('@apollographql/graphql-upload-8-fork')
.GraphQLUpload as GraphQLScalarType)
: undefined;

export * from './plugin';
6 changes: 3 additions & 3 deletions packages/apollo-server-core/src/processFileUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import runtimeSupportsUploads from './utils/runtimeSupportsUploads';
// change during runtime. In the event that we're using a version of Node.js
// less than 8.5.0, we'll
const processFileUploads:
| typeof import('graphql-upload').processRequest
| typeof import('@apollographql/graphql-upload-8-fork').processRequest
| undefined = (() => {
if (runtimeSupportsUploads) {
return require('graphql-upload')
.processRequest as typeof import('graphql-upload').processRequest;
return require('@apollographql/graphql-upload-8-fork')
.processRequest as typeof import('@apollographql/graphql-upload-8-fork').processRequest;
}
return undefined;
})();
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export interface Config extends BaseConfig {
engine?: boolean | EngineReportingOptions<Context>;
}

// Configuration for how Apollo Server talks to the Apollo registry.
// Configuration for the built-in graphql-upload integration.
export interface FileUploadOptions {
//Max allowed non-file multipart form field size in bytes; enough for your queries (default: 1 MB).
maxFieldSize?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-fastify/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, OutgoingMessage, ServerResponse, Server } from 'http';
import { graphqlFastify } from './fastifyApollo';
import { GraphQLOperation } from 'graphql-upload';
import type { GraphQLOperation } from '@apollographql/graphql-upload-8-fork';

const kMultipart = Symbol('multipart');
const fastJson = require('fast-json-stringify');
Expand Down

0 comments on commit c871152

Please sign in to comment.