Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uploads): replace apollo-upload-server v5 with graphql-upload v8 #1764

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Allow an optional function to resolve the `rootValue`, passing the `DocumentNode` AST to determine the value. [PR #1555](https://github.com/apollographql/apollo-server/pull/1555)
- Follow-up on the work in [PR #1516](https://github.com/apollographql/apollo-server/pull/1516) to also fix missing insertion cursor/caret when a custom GraphQL configuration is specified which doesn't specify its own `cursorShape` property. [PR #1607](https://github.com/apollographql/apollo-server/pull/1607)
- Migrate [@apollographql/apollo-upload-server](https://github.com/apollographql/apollo-upload-server) to [graphql-upload](https://github.com/jaydenseric/graphql-upload) to fix [#1509](https://github.com/apollographql/apollo-server/issues/1509) and [1703](https://github.com/apollographql/apollo-server/issues/1703)

### v2.1.0

Expand Down
2 changes: 1 addition & 1 deletion docs/source/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const resolvers = {
Mutation: {
singleUpload: (parent, args) => {
return args.file.then(file => {
//Contents of Upload scalar: https://github.com/jaydenseric/apollo-upload-server#upload-scalar
//Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload
//file.stream is a node stream that contains the contents of the uploaded file
//node stream api: https://nodejs.org/api/stream.html
return file;
Expand Down
72 changes: 45 additions & 27 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"node": ">=6"
},
"dependencies": {
"@apollographql/apollo-upload-server": "^5.0.3",
"@types/ws": "^5.1.2",
"apollo-cache-control": "file:../apollo-cache-control",
"apollo-datasource": "file:../apollo-datasource",
Expand All @@ -42,6 +41,7 @@
"graphql-subscriptions": "^0.5.8",
"graphql-tag": "^2.9.2",
"graphql-tools": "^3.0.4",
"graphql-upload": "^8.0.0",
"hash.js": "^1.1.3",
"lodash": "^4.17.10",
"subscriptions-transport-ws": "^0.9.11",
Expand Down
4 changes: 1 addition & 3 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ export class ApolloServerBase {
);

if (this.uploadsConfig) {
const {
GraphQLUpload,
} = require('@apollographql/apollo-upload-server');
const { GraphQLUpload } = require('graphql-upload');
if (resolvers && !resolvers.Upload) {
resolvers.Upload = GraphQLUpload;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ export const gql: (
) => DocumentNode = gqlTag;

import { GraphQLScalarType } from 'graphql';
import { GraphQLUpload as UploadScalar } from '@apollographql/apollo-upload-server';
import { GraphQLUpload as UploadScalar } from 'graphql-upload';
export const GraphQLUpload = UploadScalar as GraphQLScalarType;
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 @@ -61,7 +61,7 @@ export interface Config
extensions?: Array<() => GraphQLExtension>;
persistedQueries?: PersistedQueryOptions | false;
subscriptions?: Partial<SubscriptionServerOptions> | string | false;
//https://github.com/jaydenseric/apollo-upload-server#options
//https://github.com/jaydenseric/graphql-upload#type-uploadoptions
uploads?: boolean | FileUploadOptions;
playground?: PlaygroundConfig;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '@apollographql/apollo-upload-server' {
declare module 'graphql-upload' {
import { GraphQLScalarType } from 'graphql';

export const GraphQLUpload: GraphQLScalarType;
Expand All @@ -20,8 +20,11 @@ declare module '@apollographql/apollo-upload-server' {

export type Request = any;

export type Response = any;

export function processRequest(
request: Request,
response: Response,
options?: ApolloUploadOptions,
): Promise<any>;
}
2 changes: 1 addition & 1 deletion packages/apollo-server-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"node": ">=6"
},
"dependencies": {
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.0",
"@types/accepts": "^1.3.5",
"@types/body-parser": "1.17.0",
Expand All @@ -43,6 +42,7 @@
"cors": "^2.8.4",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.4",
"graphql-upload": "^8.0.0",
"type-is": "^1.6.16"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-express/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import typeis from 'type-is';

import { graphqlExpress } from './expressApollo';

import { processRequest as processFileUploads } from '@apollographql/apollo-upload-server';
import { processRequest as processFileUploads } from 'graphql-upload';

export { GraphQLOptions, GraphQLExtension } from 'apollo-server-core';

Expand Down Expand Up @@ -45,7 +45,7 @@ const fileUploadMiddleware = (
) => {
// Note: we use typeis directly instead of via req.is for connect support.
if (typeis(req, ['multipart/form-data'])) {
processFileUploads(req, uploadsConfig)
processFileUploads(req, res, uploadsConfig)
.then(body => {
req.body = body;
next();
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"node": ">=8"
},
"dependencies": {
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.0",
"accept": "^3.0.2",
"apollo-server-core": "file:../apollo-server-core",
"boom": "^7.1.0",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.4"
"graphql-tools": "^3.0.4",
"graphql-upload": "^8.0.0"
},
"devDependencies": {
"apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite"
Expand Down
8 changes: 6 additions & 2 deletions packages/apollo-server-hapi/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
renderPlaygroundPage,
RenderPageOptions as PlaygroundRenderPageOptions,
} from '@apollographql/graphql-playground-html';
import { processRequest as processFileUploads } from '@apollographql/apollo-upload-server';
import { processRequest as processFileUploads } from 'graphql-upload';

import { graphqlHapi } from './hapiApollo';

Expand All @@ -19,7 +19,11 @@ function handleFileUploads(uploadsConfig: FileUploadOptions) {
return async (request: hapi.Request) => {
if (request.mime === 'multipart/form-data') {
Object.defineProperty(request, 'payload', {
value: await processFileUploads(request, uploadsConfig),
value: await processFileUploads(
request,
request.response,
uploadsConfig,
),
writable: false,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"node": ">=6"
},
"dependencies": {
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.0",
"@koa/cors": "^2.2.1",
"@types/accepts": "^1.3.5",
Expand All @@ -43,6 +42,7 @@
"apollo-server-core": "file:../apollo-server-core",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.4",
"graphql-upload": "^8.0.0",
"koa": "2.5.3",
"koa-bodyparser": "^3.0.0",
"koa-router": "^7.4.0",
Expand Down
8 changes: 6 additions & 2 deletions packages/apollo-server-koa/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import typeis from 'type-is';

import { graphqlKoa } from './koaApollo';

import { processRequest as processFileUploads } from '@apollographql/apollo-upload-server';
import { processRequest as processFileUploads } from 'graphql-upload';

export { GraphQLOptions, GraphQLExtension } from 'apollo-server-core';
import { GraphQLOptions, FileUploadOptions } from 'apollo-server-core';
Expand All @@ -32,7 +32,11 @@ const fileUploadMiddleware = (
) => async (ctx: Koa.Context, next: Function) => {
if (typeis(ctx.req, ['multipart/form-data'])) {
try {
ctx.request.body = await processFileUploads(ctx.req, uploadsConfig);
ctx.request.body = await processFileUploads(
ctx.req,
ctx.res,
uploadsConfig,
);
return next();
} catch (error) {
if (error.status && error.expose) ctx.status = error.status;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-micro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
},
"homepage": "https://github.com/apollographql/apollo-server#readme",
"dependencies": {
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.0",
"accept": "^3.0.2",
"apollo-server-core": "file:../apollo-server-core",
"graphql-upload": "^8.0.0",
"micro": "^9.3.2"
},
"devDependencies": {
Expand Down
Loading