Skip to content

Commit 7edb688

Browse files
committed
Add support for uploading files
Now it is possible to upload files via the Apollo-Client. Also Apollo v3 is implemented now.
1 parent 21f7fd9 commit 7edb688

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@
2424
},
2525
"homepage": "https://github.com/snek-at/client#readme",
2626
"dependencies": {
27-
"apollo-cache-inmemory": "^1.6.5",
28-
"apollo-client": "^2.6.8",
29-
"apollo-link-http": "^1.5.16",
30-
"graphql": "^14.6.0",
27+
"@apollo/client": "^3.1.5",
28+
"apollo-upload-client": "^14.1.1",
29+
"graphql": "^14.7.0",
3130
"graphql-tag": "^2.10.3",
32-
"js-cookie": "^2.2.1"
31+
"js-cookie": "^2.2.1",
32+
"react": "^16.13.1",
33+
"subscriptions-transport-ws": "^0.9.18"
3334
},
3435
"devDependencies": {
3536
"@babel/core": "^7.9.6",
3637
"@babel/plugin-proposal-class-properties": "^7.8.3",
38+
"@types/apollo-upload-client": "^14.1.0",
3739
"@types/js-cookie": "^2.2.6",
38-
"typescript": "^3.8.3"
40+
"@types/mocha": "^8.0.3",
41+
"@types/node": "^14.6.4",
42+
"@types/react": "^16.9.49",
43+
"typescript": "^3.9.7"
3944
}
4045
}

src/endpoints/apollo.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
//#region > Imports
2-
//#PACKAGE "apollo-client"
3-
//## npm install "apollo-client"@2.6.8
4-
// Contains the client for graphql handling
5-
import { ApolloClient } from "apollo-client";
6-
//#PACKAGE "apollo-link-http"
7-
//## npm install "apollo-link-http"@1.5.16
8-
// Contains the link for the apollo client
9-
import { HttpLink } from "apollo-link-http";
10-
//#PACKAGE "apollo-cache-inmemory"
11-
//## npm install "apollo-cache-inmemory"@1.6.5
12-
// Contains cache handling for apollo
2+
//#PACKAGE "@apollo/client"
133
import {
4+
ApolloClient,
5+
ApolloLink,
146
InMemoryCache,
15-
IntrospectionFragmentMatcher,
167
NormalizedCacheObject,
17-
} from "apollo-cache-inmemory";
8+
HttpLink,
9+
} from "@apollo/client";
10+
//#PACKAGE "'apollo-upload-client"
11+
// Contains the link for the apollo client
12+
import { createUploadLink } from "apollo-upload-client";
1813
//#PACKAGE "graphql"
1914
//## npm install "graphql"@14.6.0
2015
// Contains the interface for gql queries, mutations and subscriptions
@@ -32,7 +27,7 @@ import { ApolloResult } from "./index";
3227
/** @class Apollo client for graphql handling */
3328
class Apollo implements ApolloEndpoint {
3429
//> Fields
35-
private link: HttpLink;
30+
private link: ApolloLink;
3631
private cache: InMemoryCache;
3732
private client: ApolloClient<NormalizedCacheObject>;
3833

@@ -49,26 +44,18 @@ class Apollo implements ApolloEndpoint {
4944
*/
5045
constructor(uri: string, options: Options) {
5146
this.headers = options.headers;
52-
const fragmentMatcher = new IntrospectionFragmentMatcher({
53-
introspectionQueryResultData: {
54-
__schema: {
55-
types: [],
56-
},
57-
},
58-
});
5947

6048
try {
61-
this.cache = new InMemoryCache({ fragmentMatcher });
49+
this.cache = new InMemoryCache();
6250
} catch {
6351
//#ERROR
6452
throw new Error("An error occurred while initializing the cache!");
6553
}
6654

6755
try {
68-
this.link = new HttpLink({
69-
uri,
70-
headers: options.headers,
71-
});
56+
const uploadLink = createUploadLink({ uri, headers: options.headers });
57+
58+
this.link = ApolloLink.from([uploadLink]);
7259
} catch {
7360
//#ERROR
7461
throw new Error("An error occurred while initializing the API link!");

src/endpoints/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//## npm install "graphql"@14.6.0
55
// Contains the interface for gql queries, mutations and subscriptions
66
import { DocumentNode } from "graphql";
7-
import { FetchResult } from "apollo-link";
8-
import { ApolloQueryResult } from "apollo-client";
7+
import { ApolloQueryResult, FetchResult } from "@apollo/client";
98
//#endregion
109

1110
//#region > Types

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
/**
3434
* Allow json modules.
3535
*/
36-
"resolveJsonModule": true
36+
"resolveJsonModule": true,
37+
/**
38+
* Skip type checking of declaration files.
39+
*/
40+
"skipLibCheck": true
3741
},
3842
/**
3943
* The files to not type check.

0 commit comments

Comments
 (0)