1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const axios_1 = require("axios");
|
4 | const axios_fetch_1 = require("axios-fetch");
|
5 | const NodeCache = require("node-cache");
|
6 | const http_1 = require("../internal/util/http");
|
7 | const logger_1 = require("../util/logger");
|
8 | const ApolloGraphClient_1 = require("./ApolloGraphClient");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | class ApolloGraphClientFactory {
|
15 | create(workspaceId, configuration) {
|
16 | this.init();
|
17 | let graphClient = this.graphClients.get(workspaceId);
|
18 | if (graphClient) {
|
19 | return graphClient;
|
20 | }
|
21 | else {
|
22 | const headers = {
|
23 | "Authorization": `Bearer ${configuration.apiKey}`,
|
24 | "apollographql-client-name": `${configuration.name}/${workspaceId}`,
|
25 | "apollographql-client-version": configuration.version,
|
26 | };
|
27 | graphClient = new ApolloGraphClient_1.ApolloGraphClient(`${configuration.endpoints.graphql}/${workspaceId}`, headers, this.configure(configuration), configuration.graphql.listeners);
|
28 | this.graphClients.set(workspaceId, graphClient);
|
29 | return graphClient;
|
30 | }
|
31 | logger_1.logger.debug("Unable to create graph client for team '%s'", workspaceId);
|
32 | return null;
|
33 | }
|
34 | configure(configuration) {
|
35 | return axios_fetch_1.buildAxiosFetch(axios_1.default.create(http_1.configureProxy({})));
|
36 | }
|
37 | init() {
|
38 | if (!this.graphClients) {
|
39 | this.graphClients = new NodeCache({
|
40 | stdTTL: 1 * 60,
|
41 | checkperiod: 1 * 30,
|
42 | useClones: false,
|
43 | });
|
44 | }
|
45 | }
|
46 | }
|
47 | exports.ApolloGraphClientFactory = ApolloGraphClientFactory;
|
48 |
|
\ | No newline at end of file |