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

Use community provided types for graphql-upload #2844

Merged
merged 13 commits into from
Jul 30, 2019
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The version headers in this history reflect the versions of Apollo Server itself
- `apollo-engine-reporting`: Add missing `apollo-server-caching` dependency. [PR #3054](https://github.com/apollographql/apollo-server/pull/3054)
- `apollo-server-hapi`: Revert switch from `accept` and `boom` which took place in v2.8.0. [PR #3089](https://github.com/apollographql/apollo-server/pull/3089)
- `@apollo/gateway`: Change the `setInterval` timer, which is used to continuously check for updates to a federated graph from the Apollo Graph Manager, to be an `unref`'d timer. Without this change, the server wouldn't terminate properly once polling had started since the event-loop would continue to have unprocessed events on it. [PR #3105](https://github.com/apollographql/apollo-server/pull/3105)
- Switch to using community `@types/graphql-upload` types.
- `apollo-server-fastify`: Change the typing of the HTTP `response` from `OutgoingMessage` to `ServerResponse`. [Commit](https://github.com/apollographql/apollo-server/commit/7638f643fa0445f5f8151ef884da779d85fb954c)
- `apollo-server-hapi`: Pass the `raw` request and response objects to `graphql-upload`s `processRequest` method to align on the same TypeScript types. [Commit](https://github.com/apollographql/apollo-server/commit/8e49b288a6aecd0e134637e64ef4ed751aa8d304)

### v2.8.0

Expand Down
14 changes: 12 additions & 2 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 packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@apollographql/apollo-tools": "^0.4.0",
"@apollographql/graphql-playground-html": "1.6.24",
"@types/graphql-upload": "^8.0.0",
"@types/ws": "^6.0.0",
"apollo-cache-control": "file:../apollo-cache-control",
"apollo-datasource": "file:../apollo-datasource",
Expand Down
2 changes: 0 additions & 2 deletions packages/apollo-server-core/src/processFileUploads.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="./types/graphql-upload.d.ts" />

import runtimeSupportsUploads from './utils/runtimeSupportsUploads';

// We'll memoize this function once at module load time since it should never
Expand Down
30 changes: 0 additions & 30 deletions packages/apollo-server-core/src/types/graphql-upload.d.ts

This file was deleted.

13 changes: 7 additions & 6 deletions packages/apollo-server-fastify/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
processFileUploads,
} from 'apollo-server-core';
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import { IncomingMessage, OutgoingMessage, Server } from 'http';
import { IncomingMessage, ServerResponse, Server } from 'http';
import { graphqlFastify } from './fastifyApollo';
import { GraphQLOperation } from 'graphql-upload';

const kMultipart = Symbol('multipart');
const fastJson = require('fast-json-stringify');
Expand All @@ -35,19 +36,19 @@ const fileUploadMiddleware = (
server: ApolloServerBase,
) => (
req: FastifyRequest<IncomingMessage>,
reply: FastifyReply<OutgoingMessage>,
reply: FastifyReply<ServerResponse>,
done: (err: Error | null, body?: any) => void,
) => {
if (
(req.req as any)[kMultipart] &&
typeof processFileUploads === 'function'
) {
processFileUploads(req.req, reply.res, uploadsConfig)
.then(body => {
.then((body: GraphQLOperation | GraphQLOperation[]) => {
req.body = body;
done(null);
})
.catch(error => {
.catch((error: any) => {
if (error.status && error.expose) reply.status(error.status);

throw formatApolloErrors([error], {
Expand Down Expand Up @@ -79,7 +80,7 @@ export class ApolloServer extends ApolloServerBase {
const promiseWillStart = this.willStart();

return async (
app: FastifyInstance<Server, IncomingMessage, OutgoingMessage>,
app: FastifyInstance<Server, IncomingMessage, ServerResponse>,
) => {
await promiseWillStart;

Expand Down Expand Up @@ -120,7 +121,7 @@ export class ApolloServer extends ApolloServerBase {
const beforeHandlers = [
(
req: FastifyRequest<IncomingMessage>,
reply: FastifyReply<OutgoingMessage>,
reply: FastifyReply<ServerResponse>,
done: () => void,
) => {
// Note: if you enable playground in production and expect to be able to see your
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-hapi/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function handleFileUploads(uploadsConfig: FileUploadOptions) {
) {
Object.defineProperty(request, 'payload', {
value: await processFileUploads(
request,
request.response,
request.raw.req,
request.raw.res,
uploadsConfig,
),
writable: false,
Expand Down