eth-graph-query 2.0.21 → 3.0.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.
- package/LICENSE +21 -0
- package/README.md +59 -28
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +58 -27
- package/dist/index.js +160 -130
- package/package.json +14 -10
- package/dist/.vite/manifest.json +0 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phạm Hồng Phúc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
# eth-graph-query
|
|
2
2
|
|
|
3
|
-
A lightweight and
|
|
3
|
+
A lightweight GraphQL query builder and client with first-class support for The Graph. Build queries using JSON, avoid string concatenation, and keep strong TypeScript types.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/eth-graph-query)
|
|
6
6
|
[](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/LICENSE)
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Features
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
12
|
+
- JSON to GraphQL: Convert nested JSON structures into valid GraphQL query strings.
|
|
13
|
+
- Multiple collections: Query multiple collections in a single HTTP request.
|
|
14
|
+
- Deep nesting: Support nested collection queries and entity relationships.
|
|
15
|
+
- Advanced filtering: The Graph operators via `$` prefix (e.g., `$gt`, `$in`, `$contains`).
|
|
16
|
+
- Inline fragments: Support GraphQL inline fragments (`... on Type`).
|
|
17
|
+
- Generic GraphQL args: Pass schema-agnostic arguments via `params.args`.
|
|
18
|
+
- TypeScript first: Full type definitions for parameters, filters, and metadata.
|
|
19
|
+
- Metadata support: Fetch subgraph metadata (`_meta`) when using The Graph.
|
|
19
20
|
|
|
20
21
|
---
|
|
21
22
|
|
|
22
|
-
##
|
|
23
|
+
## Installation
|
|
23
24
|
|
|
24
25
|
```shell
|
|
25
26
|
# npm
|
|
@@ -29,23 +30,28 @@ npm install eth-graph-query
|
|
|
29
30
|
yarn add eth-graph-query
|
|
30
31
|
|
|
31
32
|
# bun
|
|
32
|
-
bun
|
|
33
|
+
bun add eth-graph-query
|
|
33
34
|
```
|
|
34
35
|
|
|
35
36
|
---
|
|
36
37
|
|
|
37
|
-
##
|
|
38
|
-
|
|
39
|
-
### 1. Initialize the Client
|
|
38
|
+
## Quick Start
|
|
40
39
|
|
|
41
40
|
```typescript
|
|
42
41
|
import { EthGraphQuery } from 'eth-graph-query';
|
|
43
42
|
|
|
44
43
|
const rootUrl = 'https://api.thegraph.com/subgraphs/name/username/subgraph-name';
|
|
45
|
-
const client = new EthGraphQuery(rootUrl
|
|
44
|
+
const client = new EthGraphQuery(rootUrl, {
|
|
45
|
+
headers: { Authorization: 'Bearer <token>' },
|
|
46
|
+
timeoutMs: 10_000,
|
|
47
|
+
});
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### 1. Single Collection Query (The Graph)
|
|
49
55
|
|
|
50
56
|
```typescript
|
|
51
57
|
const result = await client.query({
|
|
@@ -60,9 +66,7 @@ const result = await client.query({
|
|
|
60
66
|
});
|
|
61
67
|
```
|
|
62
68
|
|
|
63
|
-
###
|
|
64
|
-
|
|
65
|
-
Fetch data from multiple collections in a single round-trip.
|
|
69
|
+
### 2. Multiple Collections Query
|
|
66
70
|
|
|
67
71
|
```typescript
|
|
68
72
|
const result = await client.multipleQuery([
|
|
@@ -77,9 +81,7 @@ const result = await client.multipleQuery([
|
|
|
77
81
|
]);
|
|
78
82
|
```
|
|
79
83
|
|
|
80
|
-
###
|
|
81
|
-
|
|
82
|
-
Build complex queries with nested collections and operators.
|
|
84
|
+
### 3. Advanced Nested Query & Filters (The Graph)
|
|
83
85
|
|
|
84
86
|
```typescript
|
|
85
87
|
const result = await client.query({
|
|
@@ -107,15 +109,42 @@ const result = await client.query({
|
|
|
107
109
|
});
|
|
108
110
|
```
|
|
109
111
|
|
|
112
|
+
### 4. Generic GraphQL Arguments (Schema-Agnostic)
|
|
113
|
+
|
|
114
|
+
Use `params.args` to pass arbitrary GraphQL arguments for non-The-Graph schemas.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const result = await client.query({
|
|
118
|
+
collection: 'users',
|
|
119
|
+
params: {
|
|
120
|
+
args: {
|
|
121
|
+
first: 20,
|
|
122
|
+
orderBy: 'name',
|
|
123
|
+
filter: { active: true },
|
|
124
|
+
},
|
|
125
|
+
elements: ['id', 'name'],
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## API Reference
|
|
133
|
+
|
|
134
|
+
Documentation for all functions and types can be found in the API docs:
|
|
135
|
+
|
|
136
|
+
- [API Docs](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/documents/api.md)
|
|
137
|
+
|
|
110
138
|
---
|
|
111
139
|
|
|
112
|
-
##
|
|
140
|
+
## Notes
|
|
113
141
|
|
|
114
|
-
|
|
142
|
+
- This library uses the native `fetch` API (Node 20+). No Axios dependency.
|
|
143
|
+
- The Graph-specific features (`where`, `_meta`, `block`) remain supported.
|
|
115
144
|
|
|
116
145
|
---
|
|
117
146
|
|
|
118
|
-
##
|
|
147
|
+
## For Developers
|
|
119
148
|
|
|
120
149
|
### Run Tests
|
|
121
150
|
|
|
@@ -125,11 +154,13 @@ npm run test
|
|
|
125
154
|
|
|
126
155
|
---
|
|
127
156
|
|
|
128
|
-
##
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE).
|
|
129
160
|
|
|
130
|
-
|
|
161
|
+
---
|
|
131
162
|
|
|
132
|
-
##
|
|
163
|
+
## References
|
|
133
164
|
|
|
134
165
|
- [The Graph Documentation](https://thegraph.com/docs/)
|
|
135
166
|
- [GraphQL Specification](https://spec.graphql.org)
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y={Accept:"application/json","Content-Type":"application/json"};class f{root;config;constructor(e,t={}){this.root=e,this.config={...t,headers:{...y,...t.headers||{}}}}async request(e,t,s,r){const i=`${this.root}${t}`,o={...this.config,...r,headers:{...this.config.headers||{},...r?.headers||{}}},c=new AbortController,l=o.timeoutMs,u=typeof l=="number"&&l>0?setTimeout(()=>c.abort(),l):void 0;try{const n=await fetch(i,{method:e.toUpperCase(),headers:o.headers,body:e==="get"||e==="delete"?void 0:JSON.stringify(s??{}),signal:o.signal??c.signal});if(!n.ok)throw new Error(`HTTP Error: ${n.status} ${n.statusText}`);return await n.json()}finally{u&&clearTimeout(u)}}async get(e,t){return this.request("get",e,void 0,t)}async post(e,t,s){return this.request("post",e,t,s)}async put(e,t,s){return this.request("put",e,t,s)}async del(e,t){return this.request("delete",e,void 0,t)}}const p=["contains","contains_nocase","ends_with","ends_with_nocase","end_with_nocase","starts_with","starts_with_nocase","not_contains","not_contains_nocase","not_ends_with","not_ends_with_nocase","not_starts_with","not_starts_with_nocase","gt","gte","lt","lte","not","in","not_in"],d=1e3,b=5e3,g=new Set(p);class a{static escapeGraphqlString(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}static serializeValue(e){return e===null?"null":typeof e=="string"?`"${this.escapeGraphqlString(e)}"`:`${e}`}static serializeArgValue(e){return e===null||e===void 0?"null":typeof e=="string"?this.serializeValue(e):typeof e=="number"||typeof e=="boolean"?`${e}`:Array.isArray(e)?`[${e.map(s=>this.serializeArgValue(s)).join(", ")}]`:`{${this.buildArgs(e).join(", ")}}`}static buildArgs(e){const t=[];for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const r=e[s];r!==void 0&&t.push(`${s}: ${this.serializeArgValue(r)}`)}return t}static buildJsonQuery(e){const t=[];for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const r=e[s];if(r!==void 0)if(r===null)t.push(`${s}: null`);else if(Array.isArray(r)){const i=r;t.push(`${s}: [${i.map(o=>typeof o=="string"?this.serializeValue(o):o).join(", ")}]`)}else if(typeof r=="string")t.push(`${s}: ${this.serializeValue(r)}`);else if(typeof r=="object"){const i={},o={},c=r;for(const l in c){if(!Object.prototype.hasOwnProperty.call(c,l))continue;const u=c[l];if(l.startsWith("$")){let n=l.slice(1);n==="end_with_nocase"&&(n="ends_with_nocase"),g.has(n)?o[`${s}_${n}`]=u:i[l]=u}else i[l]=u}Object.keys(i).length>0&&t.push(`${s}: {${this.buildJsonQuery(i)}}`),Object.keys(o).length>0&&t.push(this.buildJsonQuery(o))}else t.push(`${s}: ${r}`)}return t.join(", ")}static buildElements(e){return e.map(t=>{if(typeof t=="string")return t;const s=t;return this.buildQuery({collection:s.collection,params:s.params})})}static buildMetadata(e){let t="";const s=[];e.blockQuery&&(e.blockQuery.hash&&s.push(`hash: "${e.blockQuery.hash}"`),e.blockQuery.number!==void 0&&s.push(`number: ${e.blockQuery.number}`),e.blockQuery.number_gte!==void 0&&s.push(`number_gte: ${e.blockQuery.number_gte}`));const r=s.join(", ");r.length>0&&(t+=`(block: {${r}})`);const i=new Set,o=new Set;if(e.elements){for(const u of e.elements)u==="deployment"||u==="hasIndexingErrors"?i.add(u):o.add(u);const c=Array.from(o).join(" ");c.length>0&&i.add(`block{${c}}`);const l=Array.from(i).join(" ");l.length>0&&(t+=`{${l}}`)}return t.length>0?`_meta${t}`:""}static _buildInlineFragment(e){const t=e.params?.elements?.length?this.buildElements(e.params.elements):["id"];return`... on ${e.collection}{${t.join(" ")}}`}static buildInlineFragments(e){return e.map(t=>this._buildInlineFragment(t)).join(" ")}static buildQuery(e,t){const{collection:s,params:r}=e,i=[];if(r?.id!==void 0&&i.push(`id: ${this.serializeValue(r.id)}`),r?.orderBy&&i.push(`orderBy: ${r.orderBy}`),r?.orderDirection&&i.push(`orderDirection: ${r.orderDirection}`),r?.subgraphError&&i.push(`subgraphError: ${r.subgraphError}`),r?.args){const n=this.buildArgs(r.args);n.length>0&&i.push(...n)}if(r?.first!==void 0){const n=Math.max(0,Math.min(r.first,d));i.push(`first: ${n}`)}if(r?.skip!==void 0){const n=Math.max(0,Math.min(r.skip,b));i.push(`skip: ${n}`)}if(r?.where){const n=this.buildJsonQuery(r.where);n.length>0&&i.push(`where: {${n}}`)}if(r?.block){const n=this.buildJsonQuery(r.block);n.length>0&&i.push(`block: {${n}}`)}const o=i.length>0?`(${i.join(", ")})`:"";let c=["id"];r?.elements&&r.elements.length>0&&(c=this.buildElements(r.elements));let l="";r?.inlineFragments&&r.inlineFragments.length>0&&(l=` ${this.buildInlineFragments(r.inlineFragments)}`);const u=`${s}${o} {${c.join(" ")}${l}}`;if(t){const n=this.buildMetadata(t);return n?`${n} ${u}`:u}return u}static buildMultipleQuery(e,t){const r=e.map(i=>this.buildQuery({collection:i.collection,params:i.params})).join(" ");if(t){const i=this.buildMetadata(t);return i?`${i} ${r}`:r}return r}static makeFullQuery(e,t="query"){return`query ${t} {${e}}`}}class $ extends f{queryName;constructor(e,t){super(e,t),this.queryName="query"}async stringQuery(e){const t=await this.post("",{query:e});if(t&&typeof t=="object"&&"errors"in t){const r=t.errors.map(i=>i.message).join("; ");throw new Error(`GraphQL Error: ${r}`)}return t.data}async query(e,t){const s=a.buildQuery(e,t);return this.stringQuery(a.makeFullQuery(s,this.queryName))}async multipleQuery(e,t){const s=a.buildMultipleQuery(e,t);return this.stringQuery(a.makeFullQuery(s,this.queryName))}}exports.EthGraphQuery=$;exports.OptionKeys=p;exports.QueryBuilder=a;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* Base class for handling API requests using
|
|
2
|
+
* Base class for handling API requests using fetch.
|
|
5
3
|
* Provides protected methods for common HTTP verbs.
|
|
6
4
|
*/
|
|
7
5
|
declare class ApiQuery {
|
|
8
6
|
/** The root URL for all API requests. */
|
|
9
7
|
root: string;
|
|
10
|
-
/**
|
|
11
|
-
config:
|
|
8
|
+
/** Request options used for all requests. */
|
|
9
|
+
config: RequestOptions;
|
|
12
10
|
/**
|
|
13
11
|
* Initializes a new instance of the ApiQuery class.
|
|
14
12
|
* @param rootUrl - The base URL for the API.
|
|
15
|
-
* @param config - Optional
|
|
13
|
+
* @param config - Optional request configuration.
|
|
16
14
|
*/
|
|
17
|
-
constructor(rootUrl: string, config?:
|
|
15
|
+
constructor(rootUrl: string, config?: RequestOptions);
|
|
18
16
|
/**
|
|
19
17
|
* Performs an API request.
|
|
20
18
|
* @template T - The expected response type.
|
|
21
19
|
* @param method - The HTTP method to use.
|
|
22
20
|
* @param url - The relative URL for the request.
|
|
23
21
|
* @param data - The request payload (for POST, PUT).
|
|
24
|
-
* @param config - Optional
|
|
22
|
+
* @param config - Optional request configuration to override defaults.
|
|
25
23
|
* @returns A promise that resolves to the response data.
|
|
26
24
|
*/
|
|
27
25
|
private request;
|
|
@@ -29,38 +27,38 @@ declare class ApiQuery {
|
|
|
29
27
|
* Performs a GET request.
|
|
30
28
|
* @template T - The expected response type.
|
|
31
29
|
* @param url - The relative URL for the request.
|
|
32
|
-
* @param config - Optional
|
|
30
|
+
* @param config - Optional request configuration to override defaults.
|
|
33
31
|
* @returns A promise that resolves to the response data.
|
|
34
32
|
*/
|
|
35
|
-
protected get<T = any>(url: string, config?:
|
|
33
|
+
protected get<T = any>(url: string, config?: RequestOptions): Promise<T>;
|
|
36
34
|
/**
|
|
37
35
|
* Performs a POST request.
|
|
38
36
|
* @template B - The request body type.
|
|
39
37
|
* @template T - The expected response type.
|
|
40
38
|
* @param url - The relative URL for the request.
|
|
41
39
|
* @param data - The request payload.
|
|
42
|
-
* @param config - Optional
|
|
40
|
+
* @param config - Optional request configuration to override defaults.
|
|
43
41
|
* @returns A promise that resolves to the response data.
|
|
44
42
|
*/
|
|
45
|
-
protected post<B = any, T = any>(url: string, data?: B, config?:
|
|
43
|
+
protected post<B = any, T = any>(url: string, data?: B, config?: RequestOptions): Promise<T>;
|
|
46
44
|
/**
|
|
47
45
|
* Performs a PUT request.
|
|
48
46
|
* @template B - The request body type.
|
|
49
47
|
* @template T - The expected response type.
|
|
50
48
|
* @param url - The relative URL for the request.
|
|
51
49
|
* @param data - The request payload.
|
|
52
|
-
* @param config - Optional
|
|
50
|
+
* @param config - Optional request configuration to override defaults.
|
|
53
51
|
* @returns A promise that resolves to the response data.
|
|
54
52
|
*/
|
|
55
|
-
protected put<B = any, T = any>(url: string, data?: B, config?:
|
|
53
|
+
protected put<B = any, T = any>(url: string, data?: B, config?: RequestOptions): Promise<T>;
|
|
56
54
|
/**
|
|
57
55
|
* Performs a DELETE request.
|
|
58
56
|
* @template T - The expected response type.
|
|
59
57
|
* @param url - The relative URL for the request.
|
|
60
|
-
* @param config - Optional
|
|
58
|
+
* @param config - Optional request configuration to override defaults.
|
|
61
59
|
* @returns A promise that resolves to the response data.
|
|
62
60
|
*/
|
|
63
|
-
protected del<T = any>(url: string, config?:
|
|
61
|
+
protected del<T = any>(url: string, config?: RequestOptions): Promise<T>;
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
/**
|
|
@@ -76,8 +74,6 @@ export declare type BlockQuery = {
|
|
|
76
74
|
hash?: string;
|
|
77
75
|
/** Filter by exact block number. */
|
|
78
76
|
number?: number;
|
|
79
|
-
/** Filter by blocks with number greater than or equal to. */
|
|
80
|
-
number_gte?: number;
|
|
81
77
|
};
|
|
82
78
|
|
|
83
79
|
/**
|
|
@@ -127,9 +123,9 @@ export declare class EthGraphQuery extends ApiQuery {
|
|
|
127
123
|
/**
|
|
128
124
|
* Initializes a new EthGraphQuery instance.
|
|
129
125
|
* @param rootUrl - The endpoint URL of the subgraph.
|
|
130
|
-
* @param config - Optional
|
|
126
|
+
* @param config - Optional request configuration for custom headers or timeouts.
|
|
131
127
|
*/
|
|
132
|
-
constructor(rootUrl: string, config?:
|
|
128
|
+
constructor(rootUrl: string, config?: RequestOptions);
|
|
133
129
|
/**
|
|
134
130
|
* Executes a raw GraphQL query string.
|
|
135
131
|
* @template T - The expected return type of the data.
|
|
@@ -174,24 +170,35 @@ export declare interface GraphParams {
|
|
|
174
170
|
elements?: Array<ElementType>;
|
|
175
171
|
/** Inline fragments for selecting fields on specific types. */
|
|
176
172
|
inlineFragments?: Array<InlineFragmentType>;
|
|
177
|
-
/**
|
|
173
|
+
/** Generic GraphQL arguments (schema-agnostic). */
|
|
174
|
+
args?: {
|
|
175
|
+
[key: string]: GraphQLArgValue;
|
|
176
|
+
};
|
|
177
|
+
/** The Graph-specific 'where' filter conditions. */
|
|
178
178
|
where?: QueryJson;
|
|
179
179
|
/** Filter by specific entity ID (shortcut for where: { id: ... }). */
|
|
180
180
|
id?: string;
|
|
181
|
-
/** Number of items to return
|
|
181
|
+
/** Number of items to return. */
|
|
182
182
|
first?: number;
|
|
183
183
|
/** Field to sort the results by. */
|
|
184
184
|
orderBy?: string;
|
|
185
185
|
/** Direction of the sort (asc or desc). */
|
|
186
186
|
orderDirection?: 'asc' | 'desc';
|
|
187
|
-
/** Number of items to skip
|
|
187
|
+
/** Number of items to skip. */
|
|
188
188
|
skip?: number;
|
|
189
189
|
/** Re-run the query even if the subgraph has indexing errors. */
|
|
190
190
|
subgraphError?: 'allow' | 'deny';
|
|
191
|
-
/** Query the collection state at a specific block. */
|
|
191
|
+
/** Query the collection state at a specific block (The Graph). */
|
|
192
192
|
block?: BlockQuery;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Generic GraphQL argument value for schema-agnostic queries.
|
|
197
|
+
*/
|
|
198
|
+
export declare type GraphQLArgValue = string | number | boolean | null | undefined | Array<GraphQLArgValue> | {
|
|
199
|
+
[key: string]: GraphQLArgValue;
|
|
200
|
+
};
|
|
201
|
+
|
|
195
202
|
/**
|
|
196
203
|
* Represents an inline fragment for polymorphic types.
|
|
197
204
|
*/
|
|
@@ -199,7 +206,9 @@ export declare type InlineFragmentType = {
|
|
|
199
206
|
/** The collection name for the fragment (e.g., 'User'). */
|
|
200
207
|
collection: string;
|
|
201
208
|
/** Fields to select within the fragment. */
|
|
202
|
-
params?:
|
|
209
|
+
params?: {
|
|
210
|
+
elements?: Array<ElementType>;
|
|
211
|
+
};
|
|
203
212
|
};
|
|
204
213
|
|
|
205
214
|
/**
|
|
@@ -209,7 +218,19 @@ export declare type Metadata = {
|
|
|
209
218
|
/** Specific metadata elements to fetch. */
|
|
210
219
|
elements?: Array<'deployment' | 'hasIndexingErrors' | 'hash' | 'number' | 'timestamp'>;
|
|
211
220
|
/** Query metadata for a specific block. */
|
|
212
|
-
blockQuery?:
|
|
221
|
+
blockQuery?: MetadataBlockQuery;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Metadata block query supports number_gte in The Graph _meta.
|
|
226
|
+
*/
|
|
227
|
+
export declare type MetadataBlockQuery = {
|
|
228
|
+
/** Filter by block hash. */
|
|
229
|
+
hash?: string;
|
|
230
|
+
/** Filter by exact block number. */
|
|
231
|
+
number?: number;
|
|
232
|
+
/** Filter by blocks with number greater than or equal to. */
|
|
233
|
+
number_gte?: number;
|
|
213
234
|
};
|
|
214
235
|
|
|
215
236
|
/**
|
|
@@ -220,9 +241,13 @@ export declare type OptionKey = (typeof OptionKeys)[number];
|
|
|
220
241
|
/**
|
|
221
242
|
* Valid operator suffixes for The Graph queries (e.g., _gt, _in, _contains).
|
|
222
243
|
*/
|
|
223
|
-
export declare const OptionKeys: readonly ["contains", "contains_nocase", "ends_with", "end_with_nocase", "starts_with", "starts_with_nocase", "not_contains", "not_contains_nocase", "not_ends_with", "not_ends_with_nocase", "not_starts_with", "not_starts_with_nocase", "gt", "gte", "lt", "lte", "not", "in", "not_in"];
|
|
244
|
+
export declare const OptionKeys: readonly ["contains", "contains_nocase", "ends_with", "ends_with_nocase", "end_with_nocase", "starts_with", "starts_with_nocase", "not_contains", "not_contains_nocase", "not_ends_with", "not_ends_with_nocase", "not_starts_with", "not_starts_with_nocase", "gt", "gte", "lt", "lte", "not", "in", "not_in"];
|
|
224
245
|
|
|
225
246
|
export declare class QueryBuilder {
|
|
247
|
+
private static escapeGraphqlString;
|
|
248
|
+
static serializeValue(value: string | number | boolean | null): string;
|
|
249
|
+
private static serializeArgValue;
|
|
250
|
+
private static buildArgs;
|
|
226
251
|
/**
|
|
227
252
|
* Converts a JSON query object into a GraphQL-compatible string.
|
|
228
253
|
* Handles nested objects and operator mapping (e.g., $gt -> _gt).
|
|
@@ -286,6 +311,12 @@ export declare type QueryJson = {
|
|
|
286
311
|
[key: string]: QueryJson | WhereOptions | BaseQueryType;
|
|
287
312
|
};
|
|
288
313
|
|
|
314
|
+
declare type RequestOptions = {
|
|
315
|
+
headers?: Record<string, string>;
|
|
316
|
+
timeoutMs?: number;
|
|
317
|
+
signal?: AbortSignal;
|
|
318
|
+
};
|
|
319
|
+
|
|
289
320
|
/**
|
|
290
321
|
* Filter options for text-based fields.
|
|
291
322
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import y from "axios";
|
|
2
1
|
const p = { Accept: "application/json", "Content-Type": "application/json" };
|
|
3
|
-
|
|
4
|
-
return a.data;
|
|
5
|
-
}
|
|
6
|
-
class d {
|
|
2
|
+
class y {
|
|
7
3
|
/** The root URL for all API requests. */
|
|
8
4
|
root;
|
|
9
|
-
/**
|
|
5
|
+
/** Request options used for all requests. */
|
|
10
6
|
config;
|
|
11
7
|
/**
|
|
12
8
|
* Initializes a new instance of the ApiQuery class.
|
|
13
9
|
* @param rootUrl - The base URL for the API.
|
|
14
|
-
* @param config - Optional
|
|
10
|
+
* @param config - Optional request configuration.
|
|
15
11
|
*/
|
|
16
|
-
constructor(
|
|
17
|
-
this.root =
|
|
18
|
-
...
|
|
19
|
-
headers: {
|
|
20
|
-
...p,
|
|
21
|
-
...e.headers || {}
|
|
22
|
-
}
|
|
12
|
+
constructor(e, t = {}) {
|
|
13
|
+
this.root = e, this.config = {
|
|
14
|
+
...t,
|
|
15
|
+
headers: { ...p, ...t.headers || {} }
|
|
23
16
|
};
|
|
24
17
|
}
|
|
25
18
|
/**
|
|
@@ -28,22 +21,38 @@ class d {
|
|
|
28
21
|
* @param method - The HTTP method to use.
|
|
29
22
|
* @param url - The relative URL for the request.
|
|
30
23
|
* @param data - The request payload (for POST, PUT).
|
|
31
|
-
* @param config - Optional
|
|
24
|
+
* @param config - Optional request configuration to override defaults.
|
|
32
25
|
* @returns A promise that resolves to the response data.
|
|
33
26
|
*/
|
|
34
|
-
async request(t,
|
|
35
|
-
const
|
|
36
|
-
|
|
27
|
+
async request(e, t, s, r) {
|
|
28
|
+
const i = `${this.root}${t}`, o = {
|
|
29
|
+
...this.config,
|
|
30
|
+
...r,
|
|
31
|
+
headers: { ...this.config.headers || {}, ...r?.headers || {} }
|
|
32
|
+
}, c = new AbortController(), l = o.timeoutMs, u = typeof l == "number" && l > 0 ? setTimeout(() => c.abort(), l) : void 0;
|
|
33
|
+
try {
|
|
34
|
+
const n = await fetch(i, {
|
|
35
|
+
method: e.toUpperCase(),
|
|
36
|
+
headers: o.headers,
|
|
37
|
+
body: e === "get" || e === "delete" ? void 0 : JSON.stringify(s ?? {}),
|
|
38
|
+
signal: o.signal ?? c.signal
|
|
39
|
+
});
|
|
40
|
+
if (!n.ok)
|
|
41
|
+
throw new Error(`HTTP Error: ${n.status} ${n.statusText}`);
|
|
42
|
+
return await n.json();
|
|
43
|
+
} finally {
|
|
44
|
+
u && clearTimeout(u);
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* Performs a GET request.
|
|
40
49
|
* @template T - The expected response type.
|
|
41
50
|
* @param url - The relative URL for the request.
|
|
42
|
-
* @param config - Optional
|
|
51
|
+
* @param config - Optional request configuration to override defaults.
|
|
43
52
|
* @returns A promise that resolves to the response data.
|
|
44
53
|
*/
|
|
45
|
-
async get(
|
|
46
|
-
return this.request("get",
|
|
54
|
+
async get(e, t) {
|
|
55
|
+
return this.request("get", e, void 0, t);
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
49
58
|
* Performs a POST request.
|
|
@@ -51,11 +60,11 @@ class d {
|
|
|
51
60
|
* @template T - The expected response type.
|
|
52
61
|
* @param url - The relative URL for the request.
|
|
53
62
|
* @param data - The request payload.
|
|
54
|
-
* @param config - Optional
|
|
63
|
+
* @param config - Optional request configuration to override defaults.
|
|
55
64
|
* @returns A promise that resolves to the response data.
|
|
56
65
|
*/
|
|
57
|
-
async post(
|
|
58
|
-
return this.request("post",
|
|
66
|
+
async post(e, t, s) {
|
|
67
|
+
return this.request("post", e, t, s);
|
|
59
68
|
}
|
|
60
69
|
/**
|
|
61
70
|
* Performs a PUT request.
|
|
@@ -63,27 +72,28 @@ class d {
|
|
|
63
72
|
* @template T - The expected response type.
|
|
64
73
|
* @param url - The relative URL for the request.
|
|
65
74
|
* @param data - The request payload.
|
|
66
|
-
* @param config - Optional
|
|
75
|
+
* @param config - Optional request configuration to override defaults.
|
|
67
76
|
* @returns A promise that resolves to the response data.
|
|
68
77
|
*/
|
|
69
|
-
async put(
|
|
70
|
-
return this.request("put",
|
|
78
|
+
async put(e, t, s) {
|
|
79
|
+
return this.request("put", e, t, s);
|
|
71
80
|
}
|
|
72
81
|
/**
|
|
73
82
|
* Performs a DELETE request.
|
|
74
83
|
* @template T - The expected response type.
|
|
75
84
|
* @param url - The relative URL for the request.
|
|
76
|
-
* @param config - Optional
|
|
85
|
+
* @param config - Optional request configuration to override defaults.
|
|
77
86
|
* @returns A promise that resolves to the response data.
|
|
78
87
|
*/
|
|
79
|
-
async del(
|
|
80
|
-
return this.request("delete",
|
|
88
|
+
async del(e, t) {
|
|
89
|
+
return this.request("delete", e, void 0, t);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
|
-
const
|
|
92
|
+
const f = [
|
|
84
93
|
"contains",
|
|
85
94
|
"contains_nocase",
|
|
86
95
|
"ends_with",
|
|
96
|
+
"ends_with_nocase",
|
|
87
97
|
"end_with_nocase",
|
|
88
98
|
"starts_with",
|
|
89
99
|
"starts_with_nocase",
|
|
@@ -100,54 +110,70 @@ const b = [
|
|
|
100
110
|
"not",
|
|
101
111
|
"in",
|
|
102
112
|
"not_in"
|
|
103
|
-
],
|
|
104
|
-
class
|
|
113
|
+
], d = 1e3, b = 5e3, g = new Set(f);
|
|
114
|
+
class a {
|
|
115
|
+
static escapeGraphqlString(e) {
|
|
116
|
+
return e.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
117
|
+
}
|
|
118
|
+
static serializeValue(e) {
|
|
119
|
+
return e === null ? "null" : typeof e == "string" ? `"${this.escapeGraphqlString(e)}"` : `${e}`;
|
|
120
|
+
}
|
|
121
|
+
static serializeArgValue(e) {
|
|
122
|
+
return e === null || e === void 0 ? "null" : typeof e == "string" ? this.serializeValue(e) : typeof e == "number" || typeof e == "boolean" ? `${e}` : Array.isArray(e) ? `[${e.map((s) => this.serializeArgValue(s)).join(", ")}]` : `{${this.buildArgs(e).join(", ")}}`;
|
|
123
|
+
}
|
|
124
|
+
static buildArgs(e) {
|
|
125
|
+
const t = [];
|
|
126
|
+
for (const s in e) {
|
|
127
|
+
if (!Object.prototype.hasOwnProperty.call(e, s)) continue;
|
|
128
|
+
const r = e[s];
|
|
129
|
+
r !== void 0 && t.push(`${s}: ${this.serializeArgValue(r)}`);
|
|
130
|
+
}
|
|
131
|
+
return t;
|
|
132
|
+
}
|
|
105
133
|
/**
|
|
106
134
|
* Converts a JSON query object into a GraphQL-compatible string.
|
|
107
135
|
* Handles nested objects and operator mapping (e.g., $gt -> _gt).
|
|
108
136
|
* @param query - The JSON filter object to build.
|
|
109
137
|
* @returns A string representing the GraphQL 'where' or 'block' filter.
|
|
110
138
|
*/
|
|
111
|
-
static buildJsonQuery(
|
|
112
|
-
const
|
|
113
|
-
for (const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
else if (Array.isArray(
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
`${
|
|
139
|
+
static buildJsonQuery(e) {
|
|
140
|
+
const t = [];
|
|
141
|
+
for (const s in e) {
|
|
142
|
+
if (!Object.prototype.hasOwnProperty.call(e, s)) continue;
|
|
143
|
+
const r = e[s];
|
|
144
|
+
if (r !== void 0)
|
|
145
|
+
if (r === null) t.push(`${s}: null`);
|
|
146
|
+
else if (Array.isArray(r)) {
|
|
147
|
+
const i = r;
|
|
148
|
+
t.push(
|
|
149
|
+
`${s}: [${i.map((o) => typeof o == "string" ? this.serializeValue(o) : o).join(", ")}]`
|
|
122
150
|
);
|
|
123
|
-
} else if (typeof
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const n = {}, i = {}, c = s;
|
|
151
|
+
} else if (typeof r == "string") t.push(`${s}: ${this.serializeValue(r)}`);
|
|
152
|
+
else if (typeof r == "object") {
|
|
153
|
+
const i = {}, o = {}, c = r;
|
|
127
154
|
for (const l in c) {
|
|
155
|
+
if (!Object.prototype.hasOwnProperty.call(c, l)) continue;
|
|
128
156
|
const u = c[l];
|
|
129
157
|
if (l.startsWith("$")) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
} else
|
|
133
|
-
n[l] = u;
|
|
158
|
+
let n = l.slice(1);
|
|
159
|
+
n === "end_with_nocase" && (n = "ends_with_nocase"), g.has(n) ? o[`${s}_${n}`] = u : i[l] = u;
|
|
160
|
+
} else i[l] = u;
|
|
134
161
|
}
|
|
135
|
-
Object.keys(
|
|
136
|
-
} else
|
|
137
|
-
e.push(`${r}: ${s}`);
|
|
162
|
+
Object.keys(i).length > 0 && t.push(`${s}: {${this.buildJsonQuery(i)}}`), Object.keys(o).length > 0 && t.push(this.buildJsonQuery(o));
|
|
163
|
+
} else t.push(`${s}: ${r}`);
|
|
138
164
|
}
|
|
139
|
-
return
|
|
165
|
+
return t.join(", ");
|
|
140
166
|
}
|
|
141
167
|
/**
|
|
142
168
|
* Builds the fields/elements part of a GraphQL query from an array of strings or objects.
|
|
143
169
|
* @param elements - An array of fields to query. Can include nested collections as GraphObject.
|
|
144
170
|
* @returns An array of strings representing the selected fields.
|
|
145
171
|
*/
|
|
146
|
-
static buildElements(
|
|
147
|
-
return
|
|
148
|
-
if (typeof
|
|
149
|
-
const
|
|
150
|
-
return this.buildQuery({ collection:
|
|
172
|
+
static buildElements(e) {
|
|
173
|
+
return e.map((t) => {
|
|
174
|
+
if (typeof t == "string") return t;
|
|
175
|
+
const s = t;
|
|
176
|
+
return this.buildQuery({ collection: s.collection, params: s.params });
|
|
151
177
|
});
|
|
152
178
|
}
|
|
153
179
|
/**
|
|
@@ -155,22 +181,22 @@ class h {
|
|
|
155
181
|
* @param metadata - The metadata configuration.
|
|
156
182
|
* @returns A string representing the _meta query fragment.
|
|
157
183
|
*/
|
|
158
|
-
static buildMetadata(
|
|
159
|
-
let
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
166
|
-
for (const u of
|
|
167
|
-
u === "deployment" || u === "hasIndexingErrors" ?
|
|
168
|
-
const c =
|
|
169
|
-
c.length > 0 &&
|
|
170
|
-
const l =
|
|
171
|
-
l.length > 0 && (
|
|
184
|
+
static buildMetadata(e) {
|
|
185
|
+
let t = "";
|
|
186
|
+
const s = [];
|
|
187
|
+
e.blockQuery && (e.blockQuery.hash && s.push(`hash: "${e.blockQuery.hash}"`), e.blockQuery.number !== void 0 && s.push(`number: ${e.blockQuery.number}`), e.blockQuery.number_gte !== void 0 && s.push(`number_gte: ${e.blockQuery.number_gte}`));
|
|
188
|
+
const r = s.join(", ");
|
|
189
|
+
r.length > 0 && (t += `(block: {${r}})`);
|
|
190
|
+
const i = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
|
|
191
|
+
if (e.elements) {
|
|
192
|
+
for (const u of e.elements)
|
|
193
|
+
u === "deployment" || u === "hasIndexingErrors" ? i.add(u) : o.add(u);
|
|
194
|
+
const c = Array.from(o).join(" ");
|
|
195
|
+
c.length > 0 && i.add(`block{${c}}`);
|
|
196
|
+
const l = Array.from(i).join(" ");
|
|
197
|
+
l.length > 0 && (t += `{${l}}`);
|
|
172
198
|
}
|
|
173
|
-
return
|
|
199
|
+
return t.length > 0 ? `_meta${t}` : "";
|
|
174
200
|
}
|
|
175
201
|
/**
|
|
176
202
|
* Builds an inline fragment (... on Collection { ... }) for a query.
|
|
@@ -178,17 +204,17 @@ class h {
|
|
|
178
204
|
* @returns A string representing the inline fragment.
|
|
179
205
|
* @private
|
|
180
206
|
*/
|
|
181
|
-
static _buildInlineFragment(
|
|
182
|
-
const
|
|
183
|
-
return `... on ${
|
|
207
|
+
static _buildInlineFragment(e) {
|
|
208
|
+
const t = e.params?.elements?.length ? this.buildElements(e.params.elements) : ["id"];
|
|
209
|
+
return `... on ${e.collection}{${t.join(" ")}}`;
|
|
184
210
|
}
|
|
185
211
|
/**
|
|
186
212
|
* Builds multiple inline fragments from an array of fragment configurations.
|
|
187
213
|
* @param fragments - An array of inline fragments.
|
|
188
214
|
* @returns A string containing all built inline fragments.
|
|
189
215
|
*/
|
|
190
|
-
static buildInlineFragments(
|
|
191
|
-
return
|
|
216
|
+
static buildInlineFragments(e) {
|
|
217
|
+
return e.map((t) => this._buildInlineFragment(t)).join(" ");
|
|
192
218
|
}
|
|
193
219
|
/**
|
|
194
220
|
* Builds a complete GraphQL query for a single collection.
|
|
@@ -196,33 +222,37 @@ class h {
|
|
|
196
222
|
* @param metadata - Optional metadata configuration.
|
|
197
223
|
* @returns A string containing the GraphQL query for the collection.
|
|
198
224
|
*/
|
|
199
|
-
static buildQuery(
|
|
200
|
-
const { collection:
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
203
|
-
n.push(
|
|
225
|
+
static buildQuery(e, t) {
|
|
226
|
+
const { collection: s, params: r } = e, i = [];
|
|
227
|
+
if (r?.id !== void 0 && i.push(`id: ${this.serializeValue(r.id)}`), r?.orderBy && i.push(`orderBy: ${r.orderBy}`), r?.orderDirection && i.push(`orderDirection: ${r.orderDirection}`), r?.subgraphError && i.push(`subgraphError: ${r.subgraphError}`), r?.args) {
|
|
228
|
+
const n = this.buildArgs(r.args);
|
|
229
|
+
n.length > 0 && i.push(...n);
|
|
230
|
+
}
|
|
231
|
+
if (r?.first !== void 0) {
|
|
232
|
+
const n = Math.max(0, Math.min(r.first, d));
|
|
233
|
+
i.push(`first: ${n}`);
|
|
204
234
|
}
|
|
205
|
-
if (
|
|
206
|
-
const
|
|
207
|
-
|
|
235
|
+
if (r?.skip !== void 0) {
|
|
236
|
+
const n = Math.max(0, Math.min(r.skip, b));
|
|
237
|
+
i.push(`skip: ${n}`);
|
|
208
238
|
}
|
|
209
|
-
if (
|
|
210
|
-
const
|
|
211
|
-
|
|
239
|
+
if (r?.where) {
|
|
240
|
+
const n = this.buildJsonQuery(r.where);
|
|
241
|
+
n.length > 0 && i.push(`where: {${n}}`);
|
|
212
242
|
}
|
|
213
|
-
if (
|
|
214
|
-
const
|
|
215
|
-
|
|
243
|
+
if (r?.block) {
|
|
244
|
+
const n = this.buildJsonQuery(r.block);
|
|
245
|
+
n.length > 0 && i.push(`block: {${n}}`);
|
|
216
246
|
}
|
|
217
|
-
const
|
|
247
|
+
const o = i.length > 0 ? `(${i.join(", ")})` : "";
|
|
218
248
|
let c = ["id"];
|
|
219
|
-
|
|
249
|
+
r?.elements && r.elements.length > 0 && (c = this.buildElements(r.elements));
|
|
220
250
|
let l = "";
|
|
221
|
-
|
|
222
|
-
const u = `${
|
|
223
|
-
if (
|
|
224
|
-
const
|
|
225
|
-
return
|
|
251
|
+
r?.inlineFragments && r.inlineFragments.length > 0 && (l = ` ${this.buildInlineFragments(r.inlineFragments)}`);
|
|
252
|
+
const u = `${s}${o} {${c.join(" ")}${l}}`;
|
|
253
|
+
if (t) {
|
|
254
|
+
const n = this.buildMetadata(t);
|
|
255
|
+
return n ? `${n} ${u}` : u;
|
|
226
256
|
}
|
|
227
257
|
return u;
|
|
228
258
|
}
|
|
@@ -232,15 +262,15 @@ class h {
|
|
|
232
262
|
* @param metadata - Optional metadata configuration that applies to the entire query.
|
|
233
263
|
* @returns A string containing the merged GraphQL query for multiple collections.
|
|
234
264
|
*/
|
|
235
|
-
static buildMultipleQuery(
|
|
236
|
-
const
|
|
237
|
-
(
|
|
265
|
+
static buildMultipleQuery(e, t) {
|
|
266
|
+
const r = e.map(
|
|
267
|
+
(i) => this.buildQuery({ collection: i.collection, params: i.params })
|
|
238
268
|
).join(" ");
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
return
|
|
269
|
+
if (t) {
|
|
270
|
+
const i = this.buildMetadata(t);
|
|
271
|
+
return i ? `${i} ${r}` : r;
|
|
242
272
|
}
|
|
243
|
-
return
|
|
273
|
+
return r;
|
|
244
274
|
}
|
|
245
275
|
/**
|
|
246
276
|
* Wraps a query fragment into a full GraphQL 'query' block.
|
|
@@ -248,20 +278,20 @@ class h {
|
|
|
248
278
|
* @param queryName - An optional name for the GraphQL query (defaults to 'query').
|
|
249
279
|
* @returns The full GraphQL query string.
|
|
250
280
|
*/
|
|
251
|
-
static makeFullQuery(
|
|
252
|
-
return `query ${
|
|
281
|
+
static makeFullQuery(e, t = "query") {
|
|
282
|
+
return `query ${t} {${e}}`;
|
|
253
283
|
}
|
|
254
284
|
}
|
|
255
|
-
class
|
|
285
|
+
class $ extends y {
|
|
256
286
|
/** The name of the GraphQL query, used in makeFullQuery. */
|
|
257
287
|
queryName;
|
|
258
288
|
/**
|
|
259
289
|
* Initializes a new EthGraphQuery instance.
|
|
260
290
|
* @param rootUrl - The endpoint URL of the subgraph.
|
|
261
|
-
* @param config - Optional
|
|
291
|
+
* @param config - Optional request configuration for custom headers or timeouts.
|
|
262
292
|
*/
|
|
263
|
-
constructor(
|
|
264
|
-
super(
|
|
293
|
+
constructor(e, t) {
|
|
294
|
+
super(e, t), this.queryName = "query";
|
|
265
295
|
}
|
|
266
296
|
/**
|
|
267
297
|
* Executes a raw GraphQL query string.
|
|
@@ -270,13 +300,13 @@ class Q extends d {
|
|
|
270
300
|
* @returns A promise resolving to the query result.
|
|
271
301
|
* @throws Error if the response contains any GraphQL errors.
|
|
272
302
|
*/
|
|
273
|
-
async stringQuery(
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
const
|
|
277
|
-
throw new Error(`GraphQL Error: ${
|
|
303
|
+
async stringQuery(e) {
|
|
304
|
+
const t = await this.post("", { query: e });
|
|
305
|
+
if (t && typeof t == "object" && "errors" in t) {
|
|
306
|
+
const r = t.errors.map((i) => i.message).join("; ");
|
|
307
|
+
throw new Error(`GraphQL Error: ${r}`);
|
|
278
308
|
}
|
|
279
|
-
return
|
|
309
|
+
return t.data;
|
|
280
310
|
}
|
|
281
311
|
/**
|
|
282
312
|
* Executes a single collection query using a JSON configuration.
|
|
@@ -285,9 +315,9 @@ class Q extends d {
|
|
|
285
315
|
* @param metadata - Optional metadata fields to include in the query.
|
|
286
316
|
* @returns A promise resolving to the fetched data.
|
|
287
317
|
*/
|
|
288
|
-
async query(
|
|
289
|
-
const
|
|
290
|
-
return this.stringQuery(
|
|
318
|
+
async query(e, t) {
|
|
319
|
+
const s = a.buildQuery(e, t);
|
|
320
|
+
return this.stringQuery(a.makeFullQuery(s, this.queryName));
|
|
291
321
|
}
|
|
292
322
|
/**
|
|
293
323
|
* Executes multiple collection queries in a single request using JSON configurations.
|
|
@@ -296,13 +326,13 @@ class Q extends d {
|
|
|
296
326
|
* @param metadata - Optional metadata fields to include in the query.
|
|
297
327
|
* @returns A promise resolving to the merged results of all queries.
|
|
298
328
|
*/
|
|
299
|
-
async multipleQuery(
|
|
300
|
-
const
|
|
301
|
-
return this.stringQuery(
|
|
329
|
+
async multipleQuery(e, t) {
|
|
330
|
+
const s = a.buildMultipleQuery(e, t);
|
|
331
|
+
return this.stringQuery(a.makeFullQuery(s, this.queryName));
|
|
302
332
|
}
|
|
303
333
|
}
|
|
304
334
|
export {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
335
|
+
$ as EthGraphQuery,
|
|
336
|
+
f as OptionKeys,
|
|
337
|
+
a as QueryBuilder
|
|
308
338
|
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eth-graph-query",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A lightweight and
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "A lightweight GraphQL query builder and client with first-class support for The Graph. Build queries using JSON, avoid string concatenation, and keep strong TypeScript types.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.cjs",
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
9
17
|
"files": [
|
|
10
18
|
"dist"
|
|
11
19
|
],
|
|
12
|
-
"sideEffects": false,
|
|
13
20
|
"scripts": {
|
|
14
21
|
"build": "bun run clear && tsc && vite build",
|
|
15
22
|
"preview": "vite preview",
|
|
@@ -34,19 +41,16 @@
|
|
|
34
41
|
"url": "https://github.com/phamhongphuc1999/eth-graph-query/issues"
|
|
35
42
|
},
|
|
36
43
|
"homepage": "https://github.com/phamhongphuc1999/eth-graph-query#readme",
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"axios": "^1.13.2"
|
|
39
|
-
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@commitlint/cli": "^19.4.0",
|
|
42
46
|
"@commitlint/config-conventional": "^19.2.2",
|
|
43
47
|
"@eslint/js": "^9.29.0",
|
|
44
48
|
"@types/node": "^20.12.2",
|
|
45
|
-
"axios": "^1.13.2",
|
|
46
49
|
"eslint": "^9.29.0",
|
|
47
50
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
48
51
|
"eslint-plugin-import": "^2.32.0",
|
|
49
52
|
"eslint-plugin-prettier": "^5.5.1",
|
|
53
|
+
"eslint-plugin-react": "^7.37.5",
|
|
50
54
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
51
55
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
52
56
|
"husky": "^9.1.6",
|