@vertikalx/vtx-backend-client 1.0.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE.md +12 -0
  2. package/index.d.ts +25 -0
  3. package/index.js +44 -0
  4. package/index.js.map +1 -0
  5. package/index.ts +65 -0
  6. package/package.json +15 -0
  7. package/runtime/batcher.d.ts +36 -0
  8. package/runtime/batcher.js +123 -0
  9. package/runtime/batcher.js.map +1 -0
  10. package/runtime/batcher.ts +275 -0
  11. package/runtime/createClient.d.ts +23 -0
  12. package/runtime/createClient.js +28 -0
  13. package/runtime/createClient.js.map +1 -0
  14. package/runtime/createClient.ts +68 -0
  15. package/runtime/error.d.ts +15 -0
  16. package/runtime/error.js +19 -0
  17. package/runtime/error.js.map +1 -0
  18. package/runtime/error.ts +29 -0
  19. package/runtime/fetcher.d.ts +10 -0
  20. package/runtime/fetcher.js +68 -0
  21. package/runtime/fetcher.js.map +1 -0
  22. package/runtime/fetcher.ts +97 -0
  23. package/runtime/generateGraphqlOperation.d.ts +30 -0
  24. package/runtime/generateGraphqlOperation.js +134 -0
  25. package/runtime/generateGraphqlOperation.js.map +1 -0
  26. package/runtime/generateGraphqlOperation.ts +225 -0
  27. package/runtime/index.d.ts +11 -0
  28. package/runtime/index.js +17 -0
  29. package/runtime/index.js.map +1 -0
  30. package/runtime/index.ts +13 -0
  31. package/runtime/linkTypeMap.d.ts +9 -0
  32. package/runtime/linkTypeMap.js +95 -0
  33. package/runtime/linkTypeMap.js.map +1 -0
  34. package/runtime/linkTypeMap.ts +156 -0
  35. package/runtime/typeSelection.d.ts +28 -0
  36. package/runtime/typeSelection.js +3 -0
  37. package/runtime/typeSelection.js.map +1 -0
  38. package/runtime/typeSelection.ts +95 -0
  39. package/runtime/types.d.ts +55 -0
  40. package/runtime/types.js +3 -0
  41. package/runtime/types.js.map +1 -0
  42. package/runtime/types.ts +69 -0
  43. package/schema.d.ts +406 -0
  44. package/schema.graphql +162 -0
  45. package/schema.js +109 -0
  46. package/schema.js.map +1 -0
  47. package/schema.ts +420 -0
  48. package/tsconfig.lib.tsbuildinfo +1 -0
  49. package/types.d.ts +207 -0
  50. package/types.js +518 -0
  51. package/types.js.map +1 -0
  52. package/types.ts +515 -0
package/LICENSE.md ADDED
@@ -0,0 +1,12 @@
1
+ THIS IS A PRIVATE USE LICENSE.
2
+ THIS IS NOT AN OPEN SOURCE LICENSE.
3
+
4
+ USE IS ONLY ALLOWED FOR PROJECTS PRODUCED BY:
5
+ VERTIKAL X, INC.
6
+
7
+ ALL OTHER USES MUST FIRST OBTAIN WRITTEN PERMISSION OF EITHER OF THE ABOVE COMPANIES.
8
+
9
+ FOR FURTHER INFORMATION CONTACT
10
+ José Carlos Sarmiento - c@vtxathlete.com
11
+ or
12
+ Daniel Castañeda - daniel@vtxathlete.com
package/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { QueryGenqlSelection, Query, MutationGenqlSelection, Mutation } from './schema';
2
+ import { type FieldsSelection, type GraphqlOperation, type ClientOptions, GenqlError } from './runtime';
3
+ export type { FieldsSelection } from './runtime';
4
+ export { GenqlError };
5
+ export * from './schema';
6
+ export interface Client {
7
+ query<R extends QueryGenqlSelection>(request: R & {
8
+ __name?: string;
9
+ }): Promise<FieldsSelection<Query, R>>;
10
+ mutation<R extends MutationGenqlSelection>(request: R & {
11
+ __name?: string;
12
+ }): Promise<FieldsSelection<Mutation, R>>;
13
+ }
14
+ export declare const createClient: (options?: ClientOptions) => Client;
15
+ export declare const everything: {
16
+ __scalar: boolean;
17
+ };
18
+ export type QueryResult<fields extends QueryGenqlSelection> = FieldsSelection<Query, fields>;
19
+ export declare const generateQueryOp: (fields: QueryGenqlSelection & {
20
+ __name?: string;
21
+ }) => GraphqlOperation;
22
+ export type MutationResult<fields extends MutationGenqlSelection> = FieldsSelection<Mutation, fields>;
23
+ export declare const generateMutationOp: (fields: MutationGenqlSelection & {
24
+ __name?: string;
25
+ }) => GraphqlOperation;
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.generateMutationOp = exports.generateQueryOp = exports.everything = exports.createClient = exports.GenqlError = void 0;
18
+ const runtime_1 = require("./runtime");
19
+ Object.defineProperty(exports, "GenqlError", { enumerable: true, get: function () { return runtime_1.GenqlError; } });
20
+ const types_1 = require("./types");
21
+ __exportStar(require("./schema"), exports);
22
+ const typeMap = (0, runtime_1.linkTypeMap)(types_1.default);
23
+ const createClient = function (options) {
24
+ return (0, runtime_1.createClient)({
25
+ url: undefined,
26
+ ...options,
27
+ queryRoot: typeMap.Query,
28
+ mutationRoot: typeMap.Mutation,
29
+ subscriptionRoot: typeMap.Subscription,
30
+ });
31
+ };
32
+ exports.createClient = createClient;
33
+ exports.everything = {
34
+ __scalar: true,
35
+ };
36
+ const generateQueryOp = function (fields) {
37
+ return (0, runtime_1.generateGraphqlOperation)('query', typeMap.Query, fields);
38
+ };
39
+ exports.generateQueryOp = generateQueryOp;
40
+ const generateMutationOp = function (fields) {
41
+ return (0, runtime_1.generateGraphqlOperation)('mutation', typeMap.Mutation, fields);
42
+ };
43
+ exports.generateMutationOp = generateMutationOp;
44
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/vtx-backend-client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAOA,uCAQkB;AAET,2FAHP,oBAAU,OAGO;AAEnB,mCAA2B;AAC3B,2CAAwB;AACxB,MAAM,OAAO,GAAG,IAAA,qBAAW,EAAC,eAAY,CAAC,CAAA;AAYlC,MAAM,YAAY,GAAG,UAAU,OAAuB;IAC3D,OAAO,IAAA,sBAAoB,EAAC;QAC1B,GAAG,EAAE,SAAS;QAEd,GAAG,OAAO;QACV,SAAS,EAAE,OAAO,CAAC,KAAM;QACzB,YAAY,EAAE,OAAO,CAAC,QAAS;QAC/B,gBAAgB,EAAE,OAAO,CAAC,YAAa;KACxC,CAAQ,CAAA;AACX,CAAC,CAAA;AATY,QAAA,YAAY,gBASxB;AAEY,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE,IAAI;CACf,CAAA;AAMM,MAAM,eAAe,GAEJ,UAAU,MAAM;IACtC,OAAO,IAAA,kCAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,KAAM,EAAE,MAAa,CAAC,CAAA;AACzE,CAAC,CAAA;AAJY,QAAA,eAAe,mBAI3B;AAIM,MAAM,kBAAkB,GAEP,UAAU,MAAM;IACtC,OAAO,IAAA,kCAAwB,EAAC,UAAU,EAAE,OAAO,CAAC,QAAS,EAAE,MAAa,CAAC,CAAA;AAC/E,CAAC,CAAA;AAJY,QAAA,kBAAkB,sBAI9B"}
package/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ // @ts-nocheck
2
+ import type {
3
+ QueryGenqlSelection,
4
+ Query,
5
+ MutationGenqlSelection,
6
+ Mutation,
7
+ } from './schema'
8
+ import {
9
+ linkTypeMap,
10
+ createClient as createClientOriginal,
11
+ generateGraphqlOperation,
12
+ type FieldsSelection,
13
+ type GraphqlOperation,
14
+ type ClientOptions,
15
+ GenqlError,
16
+ } from './runtime'
17
+ export type { FieldsSelection } from './runtime'
18
+ export { GenqlError }
19
+
20
+ import types from './types'
21
+ export * from './schema'
22
+ const typeMap = linkTypeMap(types as any)
23
+
24
+ export interface Client {
25
+ query<R extends QueryGenqlSelection>(
26
+ request: R & { __name?: string },
27
+ ): Promise<FieldsSelection<Query, R>>
28
+
29
+ mutation<R extends MutationGenqlSelection>(
30
+ request: R & { __name?: string },
31
+ ): Promise<FieldsSelection<Mutation, R>>
32
+ }
33
+
34
+ export const createClient = function (options?: ClientOptions): Client {
35
+ return createClientOriginal({
36
+ url: undefined,
37
+
38
+ ...options,
39
+ queryRoot: typeMap.Query!,
40
+ mutationRoot: typeMap.Mutation!,
41
+ subscriptionRoot: typeMap.Subscription!,
42
+ }) as any
43
+ }
44
+
45
+ export const everything = {
46
+ __scalar: true,
47
+ }
48
+
49
+ export type QueryResult<fields extends QueryGenqlSelection> = FieldsSelection<
50
+ Query,
51
+ fields
52
+ >
53
+ export const generateQueryOp: (
54
+ fields: QueryGenqlSelection & { __name?: string },
55
+ ) => GraphqlOperation = function (fields) {
56
+ return generateGraphqlOperation('query', typeMap.Query!, fields as any)
57
+ }
58
+
59
+ export type MutationResult<fields extends MutationGenqlSelection> =
60
+ FieldsSelection<Mutation, fields>
61
+ export const generateMutationOp: (
62
+ fields: MutationGenqlSelection & { __name?: string },
63
+ ) => GraphqlOperation = function (fields) {
64
+ return generateGraphqlOperation('mutation', typeMap.Mutation!, fields as any)
65
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@vertikalx/vtx-backend-client",
3
+ "version": "1.0.0-dev.0",
4
+ "description": "GraphQL API generated client for VTX",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "GraphQL",
11
+ "VTX"
12
+ ],
13
+ "author": "Daniel Castañeda <daniel@vtxathlete.com>",
14
+ "license": "SEE LICENSE IN LICENSE.md"
15
+ }
@@ -0,0 +1,36 @@
1
+ import type { GraphqlOperation } from './generateGraphqlOperation';
2
+ type Variables = Record<string, any>;
3
+ type QueryError = Error & {
4
+ message: string;
5
+ locations?: Array<{
6
+ line: number;
7
+ column: number;
8
+ }>;
9
+ path?: any;
10
+ rid: string;
11
+ details?: Record<string, any>;
12
+ };
13
+ type Result = {
14
+ data: Record<string, any>;
15
+ errors: Array<QueryError>;
16
+ };
17
+ type Fetcher = (batchedQuery: GraphqlOperation | Array<GraphqlOperation>) => Promise<Array<Result>>;
18
+ type Options = {
19
+ batchInterval?: number;
20
+ shouldBatch?: boolean;
21
+ maxBatchSize?: number;
22
+ };
23
+ type Queue = Array<{
24
+ request: GraphqlOperation;
25
+ resolve: (...args: Array<any>) => any;
26
+ reject: (...args: Array<any>) => any;
27
+ }>;
28
+ export declare class QueryBatcher {
29
+ fetcher: Fetcher;
30
+ _options: Options;
31
+ _queue: Queue;
32
+ constructor(fetcher: Fetcher, { batchInterval, shouldBatch, maxBatchSize, }?: Options);
33
+ fetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
34
+ forceFetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
35
+ }
36
+ export {};
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryBatcher = void 0;
4
+ const error_1 = require("./error");
5
+ function dispatchQueueBatch(client, queue) {
6
+ let batchedQuery = queue.map((item) => item.request);
7
+ if (batchedQuery.length === 1) {
8
+ batchedQuery = batchedQuery[0];
9
+ }
10
+ (() => {
11
+ try {
12
+ return client.fetcher(batchedQuery);
13
+ }
14
+ catch (e) {
15
+ return Promise.reject(e);
16
+ }
17
+ })().then((responses) => {
18
+ if (queue.length === 1 && !Array.isArray(responses)) {
19
+ if (responses.errors && responses.errors.length) {
20
+ queue[0].reject(new error_1.GenqlError(responses.errors, responses.data));
21
+ return;
22
+ }
23
+ queue[0].resolve(responses);
24
+ return;
25
+ }
26
+ else if (responses.length !== queue.length) {
27
+ throw new Error('response length did not match query length');
28
+ }
29
+ for (let i = 0; i < queue.length; i++) {
30
+ if (responses[i].errors && responses[i].errors.length) {
31
+ queue[i].reject(new error_1.GenqlError(responses[i].errors, responses[i].data));
32
+ }
33
+ else {
34
+ queue[i].resolve(responses[i]);
35
+ }
36
+ }
37
+ })
38
+ .catch((e) => {
39
+ for (let i = 0; i < queue.length; i++) {
40
+ queue[i].reject(e);
41
+ }
42
+ });
43
+ }
44
+ function dispatchQueue(client, options) {
45
+ const queue = client._queue;
46
+ const maxBatchSize = options.maxBatchSize || 0;
47
+ client._queue = [];
48
+ if (maxBatchSize > 0 && maxBatchSize < queue.length) {
49
+ for (let i = 0; i < queue.length / maxBatchSize; i++) {
50
+ dispatchQueueBatch(client, queue.slice(i * maxBatchSize, (i + 1) * maxBatchSize));
51
+ }
52
+ }
53
+ else {
54
+ dispatchQueueBatch(client, queue);
55
+ }
56
+ }
57
+ class QueryBatcher {
58
+ constructor(fetcher, { batchInterval = 6, shouldBatch = true, maxBatchSize = 0, } = {}) {
59
+ this.fetcher = fetcher;
60
+ this._options = {
61
+ batchInterval,
62
+ shouldBatch,
63
+ maxBatchSize,
64
+ };
65
+ this._queue = [];
66
+ }
67
+ fetch(query, variables, operationName, overrides = {}) {
68
+ const request = {
69
+ query,
70
+ };
71
+ const options = Object.assign({}, this._options, overrides);
72
+ if (variables) {
73
+ request.variables = variables;
74
+ }
75
+ if (operationName) {
76
+ request.operationName = operationName;
77
+ }
78
+ const promise = new Promise((resolve, reject) => {
79
+ this._queue.push({
80
+ request,
81
+ resolve,
82
+ reject,
83
+ });
84
+ if (this._queue.length === 1) {
85
+ if (options.shouldBatch) {
86
+ setTimeout(() => dispatchQueue(this, options), options.batchInterval);
87
+ }
88
+ else {
89
+ dispatchQueue(this, options);
90
+ }
91
+ }
92
+ });
93
+ return promise;
94
+ }
95
+ forceFetch(query, variables, operationName, overrides = {}) {
96
+ const request = {
97
+ query,
98
+ };
99
+ const options = Object.assign({}, this._options, overrides, {
100
+ shouldBatch: false,
101
+ });
102
+ if (variables) {
103
+ request.variables = variables;
104
+ }
105
+ if (operationName) {
106
+ request.operationName = operationName;
107
+ }
108
+ const promise = new Promise((resolve, reject) => {
109
+ const client = new QueryBatcher(this.fetcher, this._options);
110
+ client._queue = [
111
+ {
112
+ request,
113
+ resolve,
114
+ reject,
115
+ },
116
+ ];
117
+ dispatchQueue(client, options);
118
+ });
119
+ return promise;
120
+ }
121
+ }
122
+ exports.QueryBatcher = QueryBatcher;
123
+ //# sourceMappingURL=batcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batcher.js","sourceRoot":"","sources":["../../../../libs/vtx-backend-client/runtime/batcher.ts"],"names":[],"mappings":";;;AAEA,mCAAoC;AAwCpC,SAAS,kBAAkB,CAAC,MAAoB,EAAE,KAAY;IAC1D,IAAI,YAAY,GAAQ,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAEzD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;IAClC,CAAC;IACD,CAAC,GAAG,EAAE;QACF,IAAI,CAAC;YACD,OAAO,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC;QAAC,OAAM,CAAC,EAAE,CAAC;YACR,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACL,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,SAAc,EAAE,EAAE;QACzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAClD,IAAI,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC9C,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CACX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AAO,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AA9ID,oCA8IC"}
@@ -0,0 +1,275 @@
1
+ // @ts-nocheck
2
+ import type { GraphqlOperation } from './generateGraphqlOperation'
3
+ import { GenqlError } from './error'
4
+
5
+ type Variables = Record<string, any>
6
+
7
+ type QueryError = Error & {
8
+ message: string
9
+
10
+ locations?: Array<{
11
+ line: number
12
+ column: number
13
+ }>
14
+ path?: any
15
+ rid: string
16
+ details?: Record<string, any>
17
+ }
18
+ type Result = {
19
+ data: Record<string, any>
20
+ errors: Array<QueryError>
21
+ }
22
+ type Fetcher = (
23
+ batchedQuery: GraphqlOperation | Array<GraphqlOperation>,
24
+ ) => Promise<Array<Result>>
25
+ type Options = {
26
+ batchInterval?: number
27
+ shouldBatch?: boolean
28
+ maxBatchSize?: number
29
+ }
30
+ type Queue = Array<{
31
+ request: GraphqlOperation
32
+ resolve: (...args: Array<any>) => any
33
+ reject: (...args: Array<any>) => any
34
+ }>
35
+
36
+ /**
37
+ * takes a list of requests (queue) and batches them into a single server request.
38
+ * It will then resolve each individual requests promise with the appropriate data.
39
+ * @private
40
+ * @param {QueryBatcher} client - the client to use
41
+ * @param {Queue} queue - the list of requests to batch
42
+ */
43
+ function dispatchQueueBatch(client: QueryBatcher, queue: Queue): void {
44
+ let batchedQuery: any = queue.map((item) => item.request)
45
+
46
+ if (batchedQuery.length === 1) {
47
+ batchedQuery = batchedQuery[0]
48
+ }
49
+ (() => {
50
+ try {
51
+ return client.fetcher(batchedQuery);
52
+ } catch(e) {
53
+ return Promise.reject(e);
54
+ }
55
+ })().then((responses: any) => {
56
+ if (queue.length === 1 && !Array.isArray(responses)) {
57
+ if (responses.errors && responses.errors.length) {
58
+ queue[0].reject(
59
+ new GenqlError(responses.errors, responses.data),
60
+ )
61
+ return
62
+ }
63
+
64
+ queue[0].resolve(responses)
65
+ return
66
+ } else if (responses.length !== queue.length) {
67
+ throw new Error('response length did not match query length')
68
+ }
69
+
70
+ for (let i = 0; i < queue.length; i++) {
71
+ if (responses[i].errors && responses[i].errors.length) {
72
+ queue[i].reject(
73
+ new GenqlError(responses[i].errors, responses[i].data),
74
+ )
75
+ } else {
76
+ queue[i].resolve(responses[i])
77
+ }
78
+ }
79
+ })
80
+ .catch((e) => {
81
+ for (let i = 0; i < queue.length; i++) {
82
+ queue[i].reject(e)
83
+ }
84
+ });
85
+ }
86
+
87
+ /**
88
+ * creates a list of requests to batch according to max batch size.
89
+ * @private
90
+ * @param {QueryBatcher} client - the client to create list of requests from from
91
+ * @param {Options} options - the options for the batch
92
+ */
93
+ function dispatchQueue(client: QueryBatcher, options: Options): void {
94
+ const queue = client._queue
95
+ const maxBatchSize = options.maxBatchSize || 0
96
+ client._queue = []
97
+
98
+ if (maxBatchSize > 0 && maxBatchSize < queue.length) {
99
+ for (let i = 0; i < queue.length / maxBatchSize; i++) {
100
+ dispatchQueueBatch(
101
+ client,
102
+ queue.slice(i * maxBatchSize, (i + 1) * maxBatchSize),
103
+ )
104
+ }
105
+ } else {
106
+ dispatchQueueBatch(client, queue)
107
+ }
108
+ }
109
+ /**
110
+ * Create a batcher client.
111
+ * @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
112
+ * @param {Options} options - the options to be used by client
113
+ * @param {boolean} options.shouldBatch - should the client batch requests. (default true)
114
+ * @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
115
+ * @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
116
+ * @param {boolean} options.defaultHeaders - default headers to include with every request
117
+ *
118
+ * @example
119
+ * const fetcher = batchedQuery => fetch('path/to/graphql', {
120
+ * method: 'post',
121
+ * headers: {
122
+ * Accept: 'application/json',
123
+ * 'Content-Type': 'application/json',
124
+ * },
125
+ * body: JSON.stringify(batchedQuery),
126
+ * credentials: 'include',
127
+ * })
128
+ * .then(response => response.json())
129
+ *
130
+ * const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
131
+ */
132
+
133
+ export class QueryBatcher {
134
+ fetcher: Fetcher
135
+ _options: Options
136
+ _queue: Queue
137
+
138
+ constructor(
139
+ fetcher: Fetcher,
140
+ {
141
+ batchInterval = 6,
142
+ shouldBatch = true,
143
+ maxBatchSize = 0,
144
+ }: Options = {},
145
+ ) {
146
+ this.fetcher = fetcher
147
+ this._options = {
148
+ batchInterval,
149
+ shouldBatch,
150
+ maxBatchSize,
151
+ }
152
+ this._queue = []
153
+ }
154
+
155
+ /**
156
+ * Fetch will send a graphql request and return the parsed json.
157
+ * @param {string} query - the graphql query.
158
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
159
+ * @param {[string]} operationName - the graphql operationName.
160
+ * @param {Options} overrides - the client options overrides.
161
+ *
162
+ * @return {promise} resolves to parsed json of server response
163
+ *
164
+ * @example
165
+ * client.fetch(`
166
+ * query getHuman($id: ID!) {
167
+ * human(id: $id) {
168
+ * name
169
+ * height
170
+ * }
171
+ * }
172
+ * `, { id: "1001" }, 'getHuman')
173
+ * .then(human => {
174
+ * // do something with human
175
+ * console.log(human);
176
+ * });
177
+ */
178
+ fetch(
179
+ query: string,
180
+ variables?: Variables,
181
+ operationName?: string,
182
+ overrides: Options = {},
183
+ ): Promise<Result> {
184
+ const request: GraphqlOperation = {
185
+ query,
186
+ }
187
+ const options = Object.assign({}, this._options, overrides)
188
+
189
+ if (variables) {
190
+ request.variables = variables
191
+ }
192
+
193
+ if (operationName) {
194
+ request.operationName = operationName
195
+ }
196
+
197
+ const promise = new Promise<Result>((resolve, reject) => {
198
+ this._queue.push({
199
+ request,
200
+ resolve,
201
+ reject,
202
+ })
203
+
204
+ if (this._queue.length === 1) {
205
+ if (options.shouldBatch) {
206
+ setTimeout(
207
+ () => dispatchQueue(this, options),
208
+ options.batchInterval,
209
+ )
210
+ } else {
211
+ dispatchQueue(this, options)
212
+ }
213
+ }
214
+ })
215
+ return promise
216
+ }
217
+
218
+ /**
219
+ * Fetch will send a graphql request and return the parsed json.
220
+ * @param {string} query - the graphql query.
221
+ * @param {Variables} variables - any variables you wish to inject as key/value pairs.
222
+ * @param {[string]} operationName - the graphql operationName.
223
+ * @param {Options} overrides - the client options overrides.
224
+ *
225
+ * @return {Promise<Array<Result>>} resolves to parsed json of server response
226
+ *
227
+ * @example
228
+ * client.forceFetch(`
229
+ * query getHuman($id: ID!) {
230
+ * human(id: $id) {
231
+ * name
232
+ * height
233
+ * }
234
+ * }
235
+ * `, { id: "1001" }, 'getHuman')
236
+ * .then(human => {
237
+ * // do something with human
238
+ * console.log(human);
239
+ * });
240
+ */
241
+ forceFetch(
242
+ query: string,
243
+ variables?: Variables,
244
+ operationName?: string,
245
+ overrides: Options = {},
246
+ ): Promise<Result> {
247
+ const request: GraphqlOperation = {
248
+ query,
249
+ }
250
+ const options = Object.assign({}, this._options, overrides, {
251
+ shouldBatch: false,
252
+ })
253
+
254
+ if (variables) {
255
+ request.variables = variables
256
+ }
257
+
258
+ if (operationName) {
259
+ request.operationName = operationName
260
+ }
261
+
262
+ const promise = new Promise<Result>((resolve, reject) => {
263
+ const client = new QueryBatcher(this.fetcher, this._options)
264
+ client._queue = [
265
+ {
266
+ request,
267
+ resolve,
268
+ reject,
269
+ },
270
+ ]
271
+ dispatchQueue(client, options)
272
+ })
273
+ return promise
274
+ }
275
+ }
@@ -0,0 +1,23 @@
1
+ import { type BatchOptions } from './fetcher';
2
+ import type { ExecutionResult, LinkedType } from './types';
3
+ import { type GraphqlOperation } from './generateGraphqlOperation';
4
+ export type Headers = HeadersInit | (() => HeadersInit) | (() => Promise<HeadersInit>);
5
+ export type BaseFetcher = (operation: GraphqlOperation | GraphqlOperation[]) => Promise<ExecutionResult | ExecutionResult[]>;
6
+ export type ClientOptions = Omit<RequestInit, 'body' | 'headers'> & {
7
+ url?: string;
8
+ batch?: BatchOptions | boolean;
9
+ fetcher?: BaseFetcher;
10
+ fetch?: Function;
11
+ headers?: Headers;
12
+ };
13
+ export declare const createClient: ({ queryRoot, mutationRoot, subscriptionRoot, ...options }: Omit<RequestInit, "body" | "headers"> & {
14
+ url?: string | undefined;
15
+ batch?: boolean | BatchOptions | undefined;
16
+ fetcher?: BaseFetcher | undefined;
17
+ fetch?: Function | undefined;
18
+ headers?: Headers | undefined;
19
+ } & {
20
+ queryRoot?: LinkedType | undefined;
21
+ mutationRoot?: LinkedType | undefined;
22
+ subscriptionRoot?: LinkedType | undefined;
23
+ }) => any;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClient = void 0;
4
+ const fetcher_1 = require("./fetcher");
5
+ const generateGraphqlOperation_1 = require("./generateGraphqlOperation");
6
+ const createClient = ({ queryRoot, mutationRoot, subscriptionRoot, ...options }) => {
7
+ const fetcher = (0, fetcher_1.createFetcher)(options);
8
+ const client = {};
9
+ if (queryRoot) {
10
+ client.query = (request) => {
11
+ if (!queryRoot)
12
+ throw new Error('queryRoot argument is missing');
13
+ const resultPromise = fetcher((0, generateGraphqlOperation_1.generateGraphqlOperation)('query', queryRoot, request));
14
+ return resultPromise;
15
+ };
16
+ }
17
+ if (mutationRoot) {
18
+ client.mutation = (request) => {
19
+ if (!mutationRoot)
20
+ throw new Error('mutationRoot argument is missing');
21
+ const resultPromise = fetcher((0, generateGraphqlOperation_1.generateGraphqlOperation)('mutation', mutationRoot, request));
22
+ return resultPromise;
23
+ };
24
+ }
25
+ return client;
26
+ };
27
+ exports.createClient = createClient;
28
+ //# sourceMappingURL=createClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClient.js","sourceRoot":"","sources":["../../../../libs/vtx-backend-client/runtime/createClient.ts"],"names":[],"mappings":";;;AAEA,uCAA6D;AAE7D,yEAGmC;AAmB5B,MAAM,YAAY,GAAG,CAAC,EACzB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,GAAG,OAAO,EAKb,EAAE,EAAE;IACD,MAAM,OAAO,GAAG,IAAA,uBAAa,EAAC,OAAO,CAAC,CAAA;IACtC,MAAM,MAAM,GAGR,EAAE,CAAA;IAEN,IAAI,SAAS,EAAE,CAAC;QACZ,MAAM,CAAC,KAAK,GAAG,CAAC,OAAY,EAAE,EAAE;YAC5B,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;YAEhE,MAAM,aAAa,GAAG,OAAO,CACzB,IAAA,mDAAwB,EAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CACxD,CAAA;YAED,OAAO,aAAa,CAAA;QACxB,CAAC,CAAA;IACL,CAAC;IACD,IAAI,YAAY,EAAE,CAAC;QACf,MAAM,CAAC,QAAQ,GAAG,CAAC,OAAY,EAAE,EAAE;YAC/B,IAAI,CAAC,YAAY;gBACb,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;YAEvD,MAAM,aAAa,GAAG,OAAO,CACzB,IAAA,mDAAwB,EAAC,UAAU,EAAE,YAAY,EAAE,OAAO,CAAC,CAC9D,CAAA;YAED,OAAO,aAAa,CAAA;QACxB,CAAC,CAAA;IACL,CAAC;IAED,OAAO,MAAa,CAAA;AACxB,CAAC,CAAA;AAzCY,QAAA,YAAY,gBAyCxB"}