Skip to content

Commit a80d91f

Browse files
sjunglingcabelitos
authored andcommitted
feat: upgrade dependencies to support Apollo Server 3 and latest Apollo Gateway
1 parent 5b57816 commit a80d91f

File tree

9 files changed

+1100
-1218
lines changed

9 files changed

+1100
-1218
lines changed

@types/graphql-upload-extension/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'graphql-upload';
22

33
declare module 'graphql-upload' {
44
// eslint-disable-next-line import/prefer-default-export
5-
export class Upload {
5+
export interface Upload {
66
promise: Promise<FileUpload>;
77
}
88
}

README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Apollo federation file upload
1+
# Apollo Federation file upload
22

33
This library makes it easier to support file uploads to your federated
44
micro-services. It uses the [Apollo](https://www.apollographql.com/docs/apollo-server/data/file-uploads/) server's solution.
5-
It works by simple redirecting the file uploaded stream to the micro-service.
6-
This package do not use third-party services to send the package to your
5+
It works by simply redirecting the file uploaded stream to the micro-service.
6+
This package does not use third-party services to send the package to your
77
micro-services.
88

99
## Using HTTP Transfer-Encoding: chunked
1010

11-
By default the FileUploadDataSource will use chunked transfers and we
12-
advice that you do not change this setup. However, for some reason
13-
you can't support this kind of transfer one can provide the `useChunkedTransfer`
14-
option to the `FileUploadDataSource` constructor as `false` to do not
15-
use chunked transfer (See the example below on how to set this property).
16-
Be advised once again, that this can lead to DDOS attacks.
11+
By default, the `FileUploadDataSource` uses chunked transfers; we
12+
advise that you do not change this setup. However, for some reason
13+
you can't support this kind of transfer, one can provide the `useChunkedTransfer`
14+
option to the `FileUploadDataSource` constructor as `false` to not
15+
use chunked transfer (See the example below on setting this property).
16+
Be advised once again that this can lead to DDOS attacks.
1717

1818
## Example
1919

20-
On your Gateway you must add the FileUploadDataSource in order
20+
On your Gateway, you must add the `FileUploadDataSource` in order
2121
to the micro-service be able to receive the uploaded file(s).
2222

2323

@@ -34,8 +34,7 @@ const runServer = async () => {
3434
serviceList: [
3535
/* The services ... */
3636
],
37-
}),
38-
subscriptions: false,
37+
})
3938
});
4039

4140
const { url } = await server.listen();

lib/FileUploadDataSource.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { RemoteGraphQLDataSource } from '@apollo/gateway';
2-
import { GraphQLResponse, GraphQLRequestContext } from 'apollo-server-types';
1+
import {
2+
GraphQLDataSourceProcessOptions,
3+
RemoteGraphQLDataSource,
4+
} from '@apollo/gateway';
5+
import { GraphQLResponse } from 'apollo-server-types';
36
import { FileUpload, Upload } from 'graphql-upload';
47
import { Request, Headers, Response } from 'apollo-server-env';
58
import { isObject } from '@apollo/gateway/dist/utilities/predicates';
@@ -21,11 +24,6 @@ export type FileUploadDataSourceArgs = ConstructorArgs & {
2124
useChunkedTransfer?: boolean;
2225
};
2326

24-
interface DataSourceArgs {
25-
request: GraphQLRequestContext['request'];
26-
context: GraphQLRequestContext['context'];
27-
}
28-
2927
type AddDataHandler = (
3028
form: FormData,
3129
resolvedFiles: FileUpload[],
@@ -148,7 +146,9 @@ export default class FileUploadDataSource extends RemoteGraphQLDataSource {
148146
: addDataToForm;
149147
}
150148

151-
async process(args: DataSourceArgs): Promise<GraphQLResponse> {
149+
async process(
150+
args: GraphQLDataSourceProcessOptions,
151+
): Promise<GraphQLResponse> {
152152
const fileVariables = FileUploadDataSource.extractFileVariables(
153153
args.request.variables,
154154
);
@@ -159,7 +159,7 @@ export default class FileUploadDataSource extends RemoteGraphQLDataSource {
159159
}
160160

161161
private async processFiles(
162-
args: DataSourceArgs,
162+
args: GraphQLDataSourceProcessOptions,
163163
fileVariables: FileVariablesTuple[],
164164
): Promise<GraphQLResponse> {
165165
const { context, request } = args;
@@ -215,7 +215,7 @@ export default class FileUploadDataSource extends RemoteGraphQLDataSource {
215215
const options = {
216216
...request.http,
217217
// Apollo types are not up-to-date, make TS happy
218-
body: (form as unknown) as string,
218+
body: form as unknown as string,
219219
};
220220

221221
const httpRequest = new Request(request.http.url, options);
@@ -240,7 +240,7 @@ export default class FileUploadDataSource extends RemoteGraphQLDataSource {
240240

241241
return response;
242242
} catch (error) {
243-
this.didEncounterError(error, httpRequest, httpResponse);
243+
this.didEncounterError(error as Error, httpRequest, httpResponse);
244244
throw error;
245245
}
246246
}

lib/FormData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export default class FormData extends BaseFormData {
1111
if (err || !Number.isNaN(length)) {
1212
callback(err, length);
1313
} else {
14-
callback(null, (null as unknown) as number);
14+
callback(null, null as unknown as number);
1515
}
1616
};
1717
super.getLength(cb);
1818
}
1919

2020
getLengthSync(): number {
2121
const len = super.getLengthSync();
22-
return Number.isNaN(len) ? ((null as unknown) as number) : len;
22+
return Number.isNaN(len) ? (null as unknown as number) : len;
2323
}
2424
}

package.json

+26-26
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"lodash.set": "^4.3.2"
2323
},
2424
"peerDependencies": {
25-
"@apollo/gateway": "^0.24.4",
26-
"apollo-server-env": "^3.0.0",
27-
"apollo-server-types": "^0.6.3",
28-
"graphql-upload": "^11.0.0"
25+
"@apollo/gateway": "^0.41.0",
26+
"apollo-server-env": "^4.0.3",
27+
"apollo-server-types": "^3.2.0",
28+
"graphql-upload": "^12.0.0"
2929
},
3030
"husky": {
3131
"hooks": {
@@ -35,38 +35,38 @@
3535
}
3636
},
3737
"devDependencies": {
38-
"@apollo/federation": "^0.22.0",
39-
"@commitlint/cli": "^12.0.1",
40-
"@commitlint/config-angular": "^12.0.1",
38+
"@apollo/federation": "^0.32.0",
39+
"@commitlint/cli": "^13.1.0",
40+
"@commitlint/config-angular": "^13.1.0",
4141
"@istanbuljs/nyc-config-typescript": "^1.0.1",
42-
"@types/graphql-upload": "^8.0.4",
42+
"@types/graphql-upload": "^8.0.7",
4343
"@types/lodash.clonedeep": "^4.5.6",
4444
"@types/lodash.set": "^4.3.6",
45-
"@types/newman": "^5.1.3",
46-
"@types/node": "^14.14.33",
47-
"@typescript-eslint/eslint-plugin": "^4.17.0",
48-
"@typescript-eslint/parser": "^4.17.0",
49-
"apollo-graphql": "^0.6.1",
50-
"apollo-server-core": "^2.21.1",
51-
"apollo-server-express": "^2.21.1",
45+
"@types/newman": "^5.1.4",
46+
"@types/node": "^16.9.1",
47+
"@typescript-eslint/eslint-plugin": "^4.31.0",
48+
"@typescript-eslint/parser": "^4.31.0",
49+
"apollo-graphql": "^0.9.3",
50+
"apollo-server-core": "^3.3.0",
51+
"apollo-server-express": "^3.3.0",
5252
"dotenv-safe": "^8.2.0",
53-
"eslint": "^7.21.0",
53+
"eslint": "^7.32.0",
5454
"eslint-config-airbnb-base": "^14.2.1",
55-
"eslint-config-prettier": "^8.1.0",
55+
"eslint-config-prettier": "^8.3.0",
5656
"eslint-import-resolver-typescript": "^2.4.0",
5757
"eslint-plugin-filenames": "^1.3.2",
58-
"eslint-plugin-import": "^2.22.1",
59-
"eslint-plugin-prettier": "^3.3.1",
60-
"express": "^4.17.1",
61-
"graphql": "^14.7.0",
62-
"husky": "^4.3.8",
58+
"eslint-plugin-import": "^2.24.2",
59+
"eslint-plugin-prettier": "^4.0.0",
60+
"express": "4.17.1",
61+
"graphql": "^15.5.3",
62+
"husky": "^7.0.0",
6363
"install-peers-cli": "^2.2.0",
64-
"newman": "^5.2.2",
64+
"newman": "^5.3.0",
6565
"npm-run-all": "^4.1.5",
6666
"nyc": "^15.1.0",
67-
"prettier": "^2.2.1",
68-
"source-map-support": "^0.5.19",
69-
"ts-node": "^9.1.1",
67+
"prettier": "^2.4.0",
68+
"source-map-support": "^0.5.20",
69+
"ts-node": "^10.2.1",
7070
"typescript": "^4.2.3"
7171
}
7272
}

test/gateway.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ const gateway = async (): Promise<
3939
const server = new ApolloServer({
4040
gateway: apolloGateway,
4141
plugins: [ApolloServerPluginInlineTraceDisabled()],
42-
subscriptions: false,
43-
uploads: false,
4442
});
43+
await server.start();
4544
server.applyMiddleware({ app, path: '/' });
4645

4746
const expressServer = await new Promise<http.Server>(resolve => {

test/gen-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ const genService = (
135135
typeDefs,
136136
},
137137
]),
138-
subscriptions: false,
139-
uploads: false,
140138
});
139+
await server.start();
141140
server.applyMiddleware({ app });
142141

143142
const expressServer = await new Promise<http.Server>(resolve => {

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"strictPropertyInitialization": false,
2020
"declaration": true,
2121
"baseUrl": ".",
22-
"outDir": "./build"
22+
"outDir": "./build",
23+
"skipLibCheck": true
2324
},
2425
"include": [
2526
"lib",

0 commit comments

Comments
 (0)