@ownzones/connect-sdk 0.1.0 → 0.1.2
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.
- package/dist/sdk/index.d.ts +23 -15
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +23 -12
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/runtime/batcher.d.ts +106 -0
- package/dist/sdk/runtime/batcher.d.ts.map +1 -0
- package/dist/sdk/runtime/batcher.js +204 -0
- package/dist/sdk/runtime/batcher.js.map +1 -0
- package/dist/sdk/runtime/createClient.d.ts +18 -0
- package/dist/sdk/runtime/createClient.d.ts.map +1 -0
- package/dist/sdk/runtime/createClient.js +25 -0
- package/dist/sdk/runtime/createClient.js.map +1 -0
- package/dist/sdk/runtime/error.d.ts +19 -0
- package/dist/sdk/runtime/error.d.ts.map +1 -0
- package/dist/sdk/runtime/error.js +20 -0
- package/dist/sdk/runtime/error.js.map +1 -0
- package/dist/sdk/runtime/fetcher.d.ts +11 -0
- package/dist/sdk/runtime/fetcher.d.ts.map +1 -0
- package/dist/sdk/runtime/fetcher.js +66 -0
- package/dist/sdk/runtime/fetcher.js.map +1 -0
- package/dist/sdk/runtime/generateGraphqlOperation.d.ts +27 -4
- package/dist/sdk/runtime/generateGraphqlOperation.d.ts.map +1 -1
- package/dist/sdk/runtime/generateGraphqlOperation.js +128 -1
- package/dist/sdk/runtime/generateGraphqlOperation.js.map +1 -1
- package/dist/sdk/runtime/index.d.ts +12 -0
- package/dist/sdk/runtime/index.d.ts.map +1 -0
- package/dist/sdk/runtime/index.js +11 -0
- package/dist/sdk/runtime/index.js.map +1 -0
- package/dist/sdk/runtime/linkTypeMap.d.ts +10 -0
- package/dist/sdk/runtime/linkTypeMap.d.ts.map +1 -0
- package/dist/sdk/runtime/linkTypeMap.js +96 -0
- package/dist/sdk/runtime/linkTypeMap.js.map +1 -0
- package/dist/sdk/runtime/typeSelection.d.ts +29 -0
- package/dist/sdk/runtime/typeSelection.d.ts.map +1 -0
- package/dist/sdk/runtime/typeSelection.js +4 -0
- package/dist/sdk/runtime/typeSelection.js.map +1 -0
- package/dist/sdk/runtime/types.d.ts +54 -9
- package/dist/sdk/runtime/types.d.ts.map +1 -1
- package/dist/sdk/runtime/types.js +1 -0
- package/dist/sdk/runtime/types.js.map +1 -1
- package/dist/sdk/schema.d.ts +73127 -0
- package/dist/sdk/schema.d.ts.map +1 -0
- package/dist/sdk/schema.js +10616 -0
- package/dist/sdk/schema.js.map +1 -0
- package/dist/sdk/types.d.ts +26204 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +68876 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/queries.d.ts +228 -0
- package/dist/src/queries.d.ts.map +1 -0
- package/dist/src/queries.js +123 -0
- package/dist/src/queries.js.map +1 -0
- package/package.json +1 -1
package/dist/sdk/index.d.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* from
|
|
6
|
-
*/
|
|
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';
|
|
7
6
|
export interface Client {
|
|
8
|
-
query
|
|
9
|
-
|
|
10
|
-
|
|
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>>;
|
|
11
13
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export
|
|
17
|
-
export declare
|
|
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;
|
|
18
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/sdk/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../sdk/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../sdk/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,KAAK,EACL,sBAAsB,EACtB,QAAQ,EACT,MAAM,UAAU,CAAA;AACjB,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,UAAU,EACX,MAAM,WAAW,CAAA;AAClB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,CAAA;AAGrB,cAAc,UAAU,CAAA;AAGxB,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACjC,OAAO,EAAE,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/B,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IAErC,QAAQ,CAAC,CAAC,SAAS,sBAAsB,EACvC,OAAO,EAAE,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/B,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAA;CACzC;AAED,eAAO,MAAM,YAAY,aAAuB,aAAa,KAAG,MAS/D,CAAA;AAED,eAAO,MAAM,UAAU;;CAEtB,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,mBAAmB,IAAI,eAAe,CAC3E,KAAK,EACL,MAAM,CACP,CAAA;AACD,eAAO,MAAM,eAAe,EAAE,CAC5B,MAAM,EAAE,mBAAmB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC9C,gBAEJ,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,sBAAsB,IAC9D,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;AACnC,eAAO,MAAM,kBAAkB,EAAE,CAC/B,MAAM,EAAE,sBAAsB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KACjD,gBAEJ,CAAA"}
|
package/dist/sdk/index.js
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { linkTypeMap, createClient as createClientOriginal, generateGraphqlOperation, GenqlError, } from './runtime';
|
|
2
|
+
export { GenqlError };
|
|
3
|
+
import types from './types';
|
|
4
|
+
export * from './schema';
|
|
5
|
+
const typeMap = linkTypeMap(types);
|
|
6
|
+
export const createClient = function (options) {
|
|
7
|
+
return createClientOriginal({
|
|
8
|
+
url: undefined,
|
|
9
|
+
...options,
|
|
10
|
+
queryRoot: typeMap.Query,
|
|
11
|
+
mutationRoot: typeMap.Mutation,
|
|
12
|
+
subscriptionRoot: typeMap.Subscription,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export const everything = {
|
|
16
|
+
__scalar: true,
|
|
17
|
+
};
|
|
18
|
+
export const generateQueryOp = function (fields) {
|
|
19
|
+
return generateGraphqlOperation('query', typeMap.Query, fields);
|
|
20
|
+
};
|
|
21
|
+
export const generateMutationOp = function (fields) {
|
|
22
|
+
return generateGraphqlOperation('mutation', typeMap.Mutation, fields);
|
|
23
|
+
};
|
|
13
24
|
//# sourceMappingURL=index.js.map
|
package/dist/sdk/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../sdk/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../sdk/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,WAAW,EACX,YAAY,IAAI,oBAAoB,EACpC,wBAAwB,EAIxB,UAAU,GACX,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,UAAU,EAAE,CAAA;AAErB,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,MAAM,OAAO,GAAG,WAAW,CAAC,KAAY,CAAC,CAAA;AAYzC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,OAAuB;IAC3D,OAAO,oBAAoB,CAAC;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;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,QAAQ,EAAE,IAAI;CACf,CAAA;AAMD,MAAM,CAAC,MAAM,eAAe,GAEJ,UAAU,MAAM;IACtC,OAAO,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAM,EAAE,MAAa,CAAC,CAAA;AACzE,CAAC,CAAA;AAID,MAAM,CAAC,MAAM,kBAAkB,GAEP,UAAU,MAAM;IACtC,OAAO,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,QAAS,EAAE,MAAa,CAAC,CAAA;AAC/E,CAAC,CAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
/**
|
|
29
|
+
* Create a batcher client.
|
|
30
|
+
* @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
|
|
31
|
+
* @param {Options} options - the options to be used by client
|
|
32
|
+
* @param {boolean} options.shouldBatch - should the client batch requests. (default true)
|
|
33
|
+
* @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
|
|
34
|
+
* @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
|
|
35
|
+
* @param {boolean} options.defaultHeaders - default headers to include with every request
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const fetcher = batchedQuery => fetch('path/to/graphql', {
|
|
39
|
+
* method: 'post',
|
|
40
|
+
* headers: {
|
|
41
|
+
* Accept: 'application/json',
|
|
42
|
+
* 'Content-Type': 'application/json',
|
|
43
|
+
* },
|
|
44
|
+
* body: JSON.stringify(batchedQuery),
|
|
45
|
+
* credentials: 'include',
|
|
46
|
+
* })
|
|
47
|
+
* .then(response => response.json())
|
|
48
|
+
*
|
|
49
|
+
* const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
|
|
50
|
+
*/
|
|
51
|
+
export declare class QueryBatcher {
|
|
52
|
+
fetcher: Fetcher;
|
|
53
|
+
_options: Options;
|
|
54
|
+
_queue: Queue;
|
|
55
|
+
constructor(fetcher: Fetcher, { batchInterval, shouldBatch, maxBatchSize, }?: Options);
|
|
56
|
+
/**
|
|
57
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
58
|
+
* @param {string} query - the graphql query.
|
|
59
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
60
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
61
|
+
* @param {Options} overrides - the client options overrides.
|
|
62
|
+
*
|
|
63
|
+
* @return {promise} resolves to parsed json of server response
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* client.fetch(`
|
|
67
|
+
* query getHuman($id: ID!) {
|
|
68
|
+
* human(id: $id) {
|
|
69
|
+
* name
|
|
70
|
+
* height
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* `, { id: "1001" }, 'getHuman')
|
|
74
|
+
* .then(human => {
|
|
75
|
+
* // do something with human
|
|
76
|
+
* console.log(human);
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
79
|
+
fetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
|
|
80
|
+
/**
|
|
81
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
82
|
+
* @param {string} query - the graphql query.
|
|
83
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
84
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
85
|
+
* @param {Options} overrides - the client options overrides.
|
|
86
|
+
*
|
|
87
|
+
* @return {Promise<Array<Result>>} resolves to parsed json of server response
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* client.forceFetch(`
|
|
91
|
+
* query getHuman($id: ID!) {
|
|
92
|
+
* human(id: $id) {
|
|
93
|
+
* name
|
|
94
|
+
* height
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* `, { id: "1001" }, 'getHuman')
|
|
98
|
+
* .then(human => {
|
|
99
|
+
* // do something with human
|
|
100
|
+
* console.log(human);
|
|
101
|
+
* });
|
|
102
|
+
*/
|
|
103
|
+
forceFetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=batcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batcher.d.ts","sourceRoot":"","sources":["../../../sdk/runtime/batcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAGlE,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEpC,KAAK,UAAU,GAAG,KAAK,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IAEf,SAAS,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACjB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAChC,CAAA;AACD,KAAK,MAAM,GAAG;IACV,IAAI,EA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CAAC,MAAM,CAAC;CA6BrB"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { GenqlError } from './error';
|
|
2
|
+
/**
|
|
3
|
+
* takes a list of requests (queue) and batches them into a single server request.
|
|
4
|
+
* It will then resolve each individual requests promise with the appropriate data.
|
|
5
|
+
* @private
|
|
6
|
+
* @param {QueryBatcher} client - the client to use
|
|
7
|
+
* @param {Queue} queue - the list of requests to batch
|
|
8
|
+
*/
|
|
9
|
+
function dispatchQueueBatch(client, queue) {
|
|
10
|
+
let batchedQuery = queue.map((item) => item.request);
|
|
11
|
+
if (batchedQuery.length === 1) {
|
|
12
|
+
batchedQuery = batchedQuery[0];
|
|
13
|
+
}
|
|
14
|
+
(() => {
|
|
15
|
+
try {
|
|
16
|
+
return client.fetcher(batchedQuery);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
})().then((responses) => {
|
|
22
|
+
if (queue.length === 1 && !Array.isArray(responses)) {
|
|
23
|
+
if (responses.errors && responses.errors.length) {
|
|
24
|
+
queue[0].reject(new GenqlError(responses.errors, responses.data));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
queue[0].resolve(responses);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
else if (responses.length !== queue.length) {
|
|
31
|
+
throw new Error('response length did not match query length');
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < queue.length; i++) {
|
|
34
|
+
if (responses[i].errors && responses[i].errors.length) {
|
|
35
|
+
queue[i].reject(new GenqlError(responses[i].errors, responses[i].data));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
queue[i].resolve(responses[i]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
.catch((e) => {
|
|
43
|
+
for (let i = 0; i < queue.length; i++) {
|
|
44
|
+
queue[i].reject(e);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* creates a list of requests to batch according to max batch size.
|
|
50
|
+
* @private
|
|
51
|
+
* @param {QueryBatcher} client - the client to create list of requests from from
|
|
52
|
+
* @param {Options} options - the options for the batch
|
|
53
|
+
*/
|
|
54
|
+
function dispatchQueue(client, options) {
|
|
55
|
+
const queue = client._queue;
|
|
56
|
+
const maxBatchSize = options.maxBatchSize || 0;
|
|
57
|
+
client._queue = [];
|
|
58
|
+
if (maxBatchSize > 0 && maxBatchSize < queue.length) {
|
|
59
|
+
for (let i = 0; i < queue.length / maxBatchSize; i++) {
|
|
60
|
+
dispatchQueueBatch(client, queue.slice(i * maxBatchSize, (i + 1) * maxBatchSize));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
dispatchQueueBatch(client, queue);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a batcher client.
|
|
69
|
+
* @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
|
|
70
|
+
* @param {Options} options - the options to be used by client
|
|
71
|
+
* @param {boolean} options.shouldBatch - should the client batch requests. (default true)
|
|
72
|
+
* @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
|
|
73
|
+
* @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
|
|
74
|
+
* @param {boolean} options.defaultHeaders - default headers to include with every request
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const fetcher = batchedQuery => fetch('path/to/graphql', {
|
|
78
|
+
* method: 'post',
|
|
79
|
+
* headers: {
|
|
80
|
+
* Accept: 'application/json',
|
|
81
|
+
* 'Content-Type': 'application/json',
|
|
82
|
+
* },
|
|
83
|
+
* body: JSON.stringify(batchedQuery),
|
|
84
|
+
* credentials: 'include',
|
|
85
|
+
* })
|
|
86
|
+
* .then(response => response.json())
|
|
87
|
+
*
|
|
88
|
+
* const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
|
|
89
|
+
*/
|
|
90
|
+
export class QueryBatcher {
|
|
91
|
+
fetcher;
|
|
92
|
+
_options;
|
|
93
|
+
_queue;
|
|
94
|
+
constructor(fetcher, { batchInterval = 6, shouldBatch = true, maxBatchSize = 0, } = {}) {
|
|
95
|
+
this.fetcher = fetcher;
|
|
96
|
+
this._options = {
|
|
97
|
+
batchInterval,
|
|
98
|
+
shouldBatch,
|
|
99
|
+
maxBatchSize,
|
|
100
|
+
};
|
|
101
|
+
this._queue = [];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
105
|
+
* @param {string} query - the graphql query.
|
|
106
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
107
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
108
|
+
* @param {Options} overrides - the client options overrides.
|
|
109
|
+
*
|
|
110
|
+
* @return {promise} resolves to parsed json of server response
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* client.fetch(`
|
|
114
|
+
* query getHuman($id: ID!) {
|
|
115
|
+
* human(id: $id) {
|
|
116
|
+
* name
|
|
117
|
+
* height
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* `, { id: "1001" }, 'getHuman')
|
|
121
|
+
* .then(human => {
|
|
122
|
+
* // do something with human
|
|
123
|
+
* console.log(human);
|
|
124
|
+
* });
|
|
125
|
+
*/
|
|
126
|
+
fetch(query, variables, operationName, overrides = {}) {
|
|
127
|
+
const request = {
|
|
128
|
+
query,
|
|
129
|
+
};
|
|
130
|
+
const options = Object.assign({}, this._options, overrides);
|
|
131
|
+
if (variables) {
|
|
132
|
+
request.variables = variables;
|
|
133
|
+
}
|
|
134
|
+
if (operationName) {
|
|
135
|
+
request.operationName = operationName;
|
|
136
|
+
}
|
|
137
|
+
const promise = new Promise((resolve, reject) => {
|
|
138
|
+
this._queue.push({
|
|
139
|
+
request,
|
|
140
|
+
resolve,
|
|
141
|
+
reject,
|
|
142
|
+
});
|
|
143
|
+
if (this._queue.length === 1) {
|
|
144
|
+
if (options.shouldBatch) {
|
|
145
|
+
setTimeout(() => dispatchQueue(this, options), options.batchInterval);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
dispatchQueue(this, options);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return promise;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
156
|
+
* @param {string} query - the graphql query.
|
|
157
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
158
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
159
|
+
* @param {Options} overrides - the client options overrides.
|
|
160
|
+
*
|
|
161
|
+
* @return {Promise<Array<Result>>} resolves to parsed json of server response
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* client.forceFetch(`
|
|
165
|
+
* query getHuman($id: ID!) {
|
|
166
|
+
* human(id: $id) {
|
|
167
|
+
* name
|
|
168
|
+
* height
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
* `, { id: "1001" }, 'getHuman')
|
|
172
|
+
* .then(human => {
|
|
173
|
+
* // do something with human
|
|
174
|
+
* console.log(human);
|
|
175
|
+
* });
|
|
176
|
+
*/
|
|
177
|
+
forceFetch(query, variables, operationName, overrides = {}) {
|
|
178
|
+
const request = {
|
|
179
|
+
query,
|
|
180
|
+
};
|
|
181
|
+
const options = Object.assign({}, this._options, overrides, {
|
|
182
|
+
shouldBatch: false,
|
|
183
|
+
});
|
|
184
|
+
if (variables) {
|
|
185
|
+
request.variables = variables;
|
|
186
|
+
}
|
|
187
|
+
if (operationName) {
|
|
188
|
+
request.operationName = operationName;
|
|
189
|
+
}
|
|
190
|
+
const promise = new Promise((resolve, reject) => {
|
|
191
|
+
const client = new QueryBatcher(this.fetcher, this._options);
|
|
192
|
+
client._queue = [
|
|
193
|
+
{
|
|
194
|
+
request,
|
|
195
|
+
resolve,
|
|
196
|
+
reject,
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
dispatchQueue(client, options);
|
|
200
|
+
});
|
|
201
|
+
return promise;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=batcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batcher.js","sourceRoot":"","sources":["../../../sdk/runtime/batcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAiCpC;;;;;;GAMG;AACH,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,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CACnD,CAAA;gBACD,OAAM;YACV,CAAC;YAED,KAAK,CAAC,CAAC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MAAM;iBACT;aACJ,CAAA;YACD,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 }: ClientOptions & {
|
|
14
|
+
queryRoot?: LinkedType;
|
|
15
|
+
mutationRoot?: LinkedType;
|
|
16
|
+
subscriptionRoot?: LinkedType;
|
|
17
|
+
}) => any;
|
|
18
|
+
//# sourceMappingURL=createClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../sdk/runtime/createClient.ts"],"names":[],"mappings":"AAEA,OAAQ,EAAE,KAAK,YAAY,EAAiB,MAAM,WAAW,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAEH,KAAK,gBAAgB,EACxB,MAAM,4BAA4B,CAAA;AAEnC,MAAM,MAAM,OAAO,GACb,WAAW,GACX,CAAC,MAAM,WAAW,CAAC,GACnB,CAAC,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC,CAAA;AAElC,MAAM,MAAM,WAAW,GAAG,CACtB,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,KAC/C,OAAO,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,CAAA;AAEjD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IAChE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,YAAY,GAAG,OAAO,CAAA;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,YAAY,8DAKtB,aAAa,GAAG;IACf,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,YAAY,CAAC,EAAE,UAAU,CAAA;IACzB,gBAAgB,CAAC,EAAE,UAAU,CAAA;CAChC,KA+BoB,GACpB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { createFetcher } from './fetcher';
|
|
3
|
+
import { generateGraphqlOperation, } from './generateGraphqlOperation';
|
|
4
|
+
export const createClient = ({ queryRoot, mutationRoot, subscriptionRoot, ...options }) => {
|
|
5
|
+
const fetcher = createFetcher(options);
|
|
6
|
+
const client = {};
|
|
7
|
+
if (queryRoot) {
|
|
8
|
+
client.query = (request) => {
|
|
9
|
+
if (!queryRoot)
|
|
10
|
+
throw new Error('queryRoot argument is missing');
|
|
11
|
+
const resultPromise = fetcher(generateGraphqlOperation('query', queryRoot, request));
|
|
12
|
+
return resultPromise;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (mutationRoot) {
|
|
16
|
+
client.mutation = (request) => {
|
|
17
|
+
if (!mutationRoot)
|
|
18
|
+
throw new Error('mutationRoot argument is missing');
|
|
19
|
+
const resultPromise = fetcher(generateGraphqlOperation('mutation', mutationRoot, request));
|
|
20
|
+
return resultPromise;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return client;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=createClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createClient.js","sourceRoot":"","sources":["../../../sdk/runtime/createClient.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,OAAQ,EAAqB,aAAa,EAAE,MAAM,WAAW,CAAA;AAE7D,OAAO,EACH,wBAAwB,GAE3B,MAAM,4BAA4B,CAAA;AAmBnC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EACzB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,GAAG,OAAO,EAKb,EAAE,EAAE;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,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,wBAAwB,CAAC,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,wBAAwB,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,CAAC,CAC9D,CAAA;YAED,OAAO,aAAa,CAAA;QACxB,CAAC,CAAA;IACL,CAAC;IAED,OAAO,MAAa,CAAA;AACxB,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class GenqlError extends Error {
|
|
2
|
+
errors: Array<GraphqlError>;
|
|
3
|
+
/**
|
|
4
|
+
* Partial data returned by the server
|
|
5
|
+
*/
|
|
6
|
+
data?: any;
|
|
7
|
+
constructor(errors: any[], data: any);
|
|
8
|
+
}
|
|
9
|
+
interface GraphqlError {
|
|
10
|
+
message: string;
|
|
11
|
+
locations?: Array<{
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
}>;
|
|
15
|
+
path?: string[];
|
|
16
|
+
extensions?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../sdk/runtime/error.ts"],"names":[],"mappings":"AACA,qBAAa,UAAW,SAAQ,KAAK;IACjC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAK;IAChC;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAA;gBACE,MAAM,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG;CAWvC;AAED,UAAU,YAAY;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACjB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACnC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
export class GenqlError extends Error {
|
|
3
|
+
errors = [];
|
|
4
|
+
/**
|
|
5
|
+
* Partial data returned by the server
|
|
6
|
+
*/
|
|
7
|
+
data;
|
|
8
|
+
constructor(errors, data) {
|
|
9
|
+
let message = Array.isArray(errors)
|
|
10
|
+
? errors.map((x) => x?.message || '').join('\n')
|
|
11
|
+
: '';
|
|
12
|
+
if (!message) {
|
|
13
|
+
message = 'GraphQL error';
|
|
14
|
+
}
|
|
15
|
+
super(message);
|
|
16
|
+
this.errors = errors;
|
|
17
|
+
this.data = data;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../sdk/runtime/error.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,MAAM,GAAwB,EAAE,CAAA;IAChC;;OAEG;IACH,IAAI,CAAM;IACV,YAAY,MAAa,EAAE,IAAS;QAChC,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAChD,CAAC,CAAC,EAAE,CAAA;QACR,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,GAAG,eAAe,CAAA;QAC7B,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;CACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClientOptions } from './createClient';
|
|
2
|
+
import type { GraphqlOperation } from './generateGraphqlOperation';
|
|
3
|
+
export interface Fetcher {
|
|
4
|
+
(gql: GraphqlOperation): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export type BatchOptions = {
|
|
7
|
+
batchInterval?: number;
|
|
8
|
+
maxBatchSize?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const createFetcher: ({ url, headers, fetcher, fetch: _fetch, batch, ...rest }: ClientOptions) => Fetcher;
|
|
11
|
+
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../sdk/runtime/fetcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAGlE,MAAM,WAAW,OAAO;IACpB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,YAAY,GAAG;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAOD,eAAO,MAAM,aAAa,6DAOvB,aAAa,KAAG,OAoElB,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { QueryBatcher } from './batcher';
|
|
3
|
+
import { GenqlError } from './error';
|
|
4
|
+
const DEFAULT_BATCH_OPTIONS = {
|
|
5
|
+
maxBatchSize: 10,
|
|
6
|
+
batchInterval: 40,
|
|
7
|
+
};
|
|
8
|
+
export const createFetcher = ({ url, headers = {}, fetcher, fetch: _fetch, batch = false, ...rest }) => {
|
|
9
|
+
if (!url && !fetcher) {
|
|
10
|
+
throw new Error('url or fetcher is required');
|
|
11
|
+
}
|
|
12
|
+
fetcher = fetcher || (async (body) => {
|
|
13
|
+
let headersObject = typeof headers == 'function' ? await headers() : headers;
|
|
14
|
+
headersObject = headersObject || {};
|
|
15
|
+
if (typeof fetch === 'undefined' && !_fetch) {
|
|
16
|
+
throw new Error('Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`');
|
|
17
|
+
}
|
|
18
|
+
let fetchImpl = _fetch || fetch;
|
|
19
|
+
const res = await fetchImpl(url, {
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...headersObject,
|
|
23
|
+
},
|
|
24
|
+
method: 'POST',
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
...rest,
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
throw new Error(`${res.statusText}: ${await res.text()}`);
|
|
30
|
+
}
|
|
31
|
+
const json = await res.json();
|
|
32
|
+
return json;
|
|
33
|
+
});
|
|
34
|
+
if (!batch) {
|
|
35
|
+
return async (body) => {
|
|
36
|
+
const json = await fetcher(body);
|
|
37
|
+
if (Array.isArray(json)) {
|
|
38
|
+
return json.map((json) => {
|
|
39
|
+
if (json?.errors?.length) {
|
|
40
|
+
throw new GenqlError(json.errors || [], json.data);
|
|
41
|
+
}
|
|
42
|
+
return json.data;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (json?.errors?.length) {
|
|
47
|
+
throw new GenqlError(json.errors || [], json.data);
|
|
48
|
+
}
|
|
49
|
+
return json.data;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const batcher = new QueryBatcher(async (batchedQuery) => {
|
|
54
|
+
// console.log(batchedQuery) // [{ query: 'query{user{age}}', variables: {} }, ...]
|
|
55
|
+
const json = await fetcher(batchedQuery);
|
|
56
|
+
return json;
|
|
57
|
+
}, batch === true ? DEFAULT_BATCH_OPTIONS : batch);
|
|
58
|
+
return async ({ query, variables }) => {
|
|
59
|
+
const json = await batcher.fetch(query, variables);
|
|
60
|
+
if (json?.data) {
|
|
61
|
+
return json.data;
|
|
62
|
+
}
|
|
63
|
+
throw new Error('Genql batch fetcher returned unexpected result ' + JSON.stringify(json));
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../../sdk/runtime/fetcher.ts"],"names":[],"mapp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,EAAE,EAAE,EAAE;QAClC,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QAClD,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;YACb,OAAO,IAAI,CAAC,IAAI,CAAA;QACpB,CAAC;QACD,MAAM,IAAI,KAAK,CACX,iDAAiD,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAC3E,CAAA;IACL,CAAC,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { LinkedField, LinkedType } from './types';
|
|
2
|
+
export interface Args {
|
|
3
|
+
[arg: string]: any | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface Fields {
|
|
6
|
+
[field: string]: Request;
|
|
7
|
+
}
|
|
8
|
+
export type Request = boolean | number | Fields;
|
|
9
|
+
export interface Variables {
|
|
10
|
+
[name: string]: {
|
|
11
|
+
value: any;
|
|
12
|
+
typing: [LinkedType, string];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Context {
|
|
16
|
+
root: LinkedType;
|
|
17
|
+
varCounter: number;
|
|
18
|
+
variables: Variables;
|
|
19
|
+
fragmentCounter: number;
|
|
20
|
+
fragments: string[];
|
|
21
|
+
}
|
|
4
22
|
export interface GraphqlOperation {
|
|
5
23
|
query: string;
|
|
6
|
-
variables?:
|
|
24
|
+
variables?: {
|
|
25
|
+
[name: string]: any;
|
|
26
|
+
};
|
|
27
|
+
operationName?: string;
|
|
7
28
|
}
|
|
29
|
+
export declare const generateGraphqlOperation: (operation: "query" | "mutation" | "subscription", root: LinkedType, fields?: Fields) => GraphqlOperation;
|
|
30
|
+
export declare const getFieldFromPath: (root: LinkedType | undefined, path: string[]) => LinkedField;
|
|
8
31
|
//# sourceMappingURL=generateGraphqlOperation.d.ts.map
|