eth-graph-query 2.0.15 → 2.0.20
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/README.md +79 -90
- package/dist/api-query.d.ts +53 -0
- package/dist/eth-graph-query.d.ts +23 -16
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1338 -963
- package/dist/query-builder.d.ts +31 -26
- package/dist/type.d.ts +86 -3
- package/package.json +21 -26
package/dist/query-builder.d.ts
CHANGED
|
@@ -1,51 +1,56 @@
|
|
|
1
1
|
import { ElementType, GraphObject, InlineFragmentType, Metadata, QueryJson } from './type';
|
|
2
2
|
export declare class QueryBuilder {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
4
|
+
* Converts a JSON query object into a GraphQL-compatible string.
|
|
5
|
+
* Handles nested objects and operator mapping (e.g., $gt -> _gt).
|
|
6
|
+
* @param query - The JSON filter object to build.
|
|
7
|
+
* @returns A string representing the GraphQL 'where' or 'block' filter.
|
|
7
8
|
*/
|
|
8
9
|
static buildJsonQuery(query: QueryJson): string;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
11
|
+
* Builds the fields/elements part of a GraphQL query from an array of strings or objects.
|
|
12
|
+
* @param elements - An array of fields to query. Can include nested collections as GraphObject.
|
|
13
|
+
* @returns An array of strings representing the selected fields.
|
|
13
14
|
*/
|
|
14
15
|
static buildElements(elements: Array<ElementType>): Array<string>;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param
|
|
18
|
-
* @returns
|
|
17
|
+
* Builds the metadata (_meta) fragment of a GraphQL query.
|
|
18
|
+
* @param metadata - The metadata configuration.
|
|
19
|
+
* @returns A string representing the _meta query fragment.
|
|
19
20
|
*/
|
|
20
21
|
static buildMetadata(metadata: Metadata): string;
|
|
22
|
+
/**
|
|
23
|
+
* Builds an inline fragment (... on Collection { ... }) for a query.
|
|
24
|
+
* @param fragment - The inline fragment configuration.
|
|
25
|
+
* @returns A string representing the inline fragment.
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
21
28
|
private static _buildInlineFragment;
|
|
22
29
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
30
|
+
* Builds multiple inline fragments from an array of fragment configurations.
|
|
31
|
+
* @param fragments - An array of inline fragments.
|
|
32
|
+
* @returns A string containing all built inline fragments.
|
|
26
33
|
*/
|
|
27
34
|
static buildInlineFragments(fragments: Array<InlineFragmentType>): string;
|
|
28
35
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param {Metadata | undefined} metadata If it is defined, the query can get metadata that you defined
|
|
34
|
-
* @returns The string query
|
|
36
|
+
* Builds a complete GraphQL query for a single collection.
|
|
37
|
+
* @param data - The collection and parameters for the query.
|
|
38
|
+
* @param metadata - Optional metadata configuration.
|
|
39
|
+
* @returns A string containing the GraphQL query for the collection.
|
|
35
40
|
*/
|
|
36
41
|
static buildQuery(data: GraphObject, metadata?: Metadata): string;
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @returns
|
|
43
|
+
* Builds a query that targets multiple collections simultaneously.
|
|
44
|
+
* @param data - An array of collection queries and their parameters.
|
|
45
|
+
* @param metadata - Optional metadata configuration that applies to the entire query.
|
|
46
|
+
* @returns A string containing the merged GraphQL query for multiple collections.
|
|
42
47
|
*/
|
|
43
48
|
static buildMultipleQuery(data: Array<GraphObject>, metadata?: Metadata): string;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @returns The
|
|
50
|
+
* Wraps a query fragment into a full GraphQL 'query' block.
|
|
51
|
+
* @param query - The query fragment to wrap.
|
|
52
|
+
* @param queryName - An optional name for the GraphQL query (defaults to 'query').
|
|
53
|
+
* @returns The full GraphQL query string.
|
|
49
54
|
*/
|
|
50
55
|
static makeFullQuery(query: string, queryName?: string): string;
|
|
51
56
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,66 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Base types that can be used in query filters.
|
|
3
|
+
*/
|
|
4
|
+
export type BaseQueryType = string | number | boolean | Array<string | number | boolean> | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Valid operator suffixes for The Graph queries (e.g., _gt, _in, _contains).
|
|
7
|
+
*/
|
|
8
|
+
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"];
|
|
9
|
+
/**
|
|
10
|
+
* Type representing the valid operator keys.
|
|
11
|
+
*/
|
|
12
|
+
export type OptionKey = (typeof OptionKeys)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Filter options for text-based fields.
|
|
15
|
+
*/
|
|
3
16
|
export type TextWhereOptions = {
|
|
17
|
+
/** Matches values containing the substring. */
|
|
4
18
|
$contains?: BaseQueryType;
|
|
19
|
+
/** Case-insensitive contains. */
|
|
5
20
|
$contains_nocase?: BaseQueryType;
|
|
21
|
+
/** Matches values ending with the substring. */
|
|
6
22
|
$ends_with?: BaseQueryType;
|
|
23
|
+
/** Case-insensitive ends_with. */
|
|
7
24
|
$end_with_nocase?: BaseQueryType;
|
|
25
|
+
/** Matches values starting with the substring. */
|
|
8
26
|
$starts_with?: BaseQueryType;
|
|
27
|
+
/** Case-insensitive starts_with. */
|
|
9
28
|
$starts_with_nocase?: BaseQueryType;
|
|
29
|
+
/** Matches values NOT containing the substring. */
|
|
10
30
|
$not_contains?: BaseQueryType;
|
|
31
|
+
/** Case-insensitive not_contains. */
|
|
11
32
|
$not_contains_nocase?: BaseQueryType;
|
|
33
|
+
/** Matches values NOT ending with the substring. */
|
|
12
34
|
$not_ends_with?: BaseQueryType;
|
|
35
|
+
/** Case-insensitive not_ends_with. */
|
|
13
36
|
$not_ends_with_nocase?: BaseQueryType;
|
|
37
|
+
/** Matches values NOT starting with the substring. */
|
|
14
38
|
$not_starts_with?: BaseQueryType;
|
|
39
|
+
/** Case-insensitive not_starts_with. */
|
|
15
40
|
$not_starts_with_nocase?: BaseQueryType;
|
|
16
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Common filter options for all field types.
|
|
44
|
+
*/
|
|
17
45
|
export type CommonWhereOptions = {
|
|
46
|
+
/** Greater than. */
|
|
18
47
|
$gt?: BaseQueryType;
|
|
48
|
+
/** Greater than or equal to. */
|
|
19
49
|
$gte?: BaseQueryType;
|
|
50
|
+
/** Less than. */
|
|
20
51
|
$lt?: BaseQueryType;
|
|
52
|
+
/** Less than or equal to. */
|
|
21
53
|
$lte?: BaseQueryType;
|
|
54
|
+
/** Not equal to. */
|
|
22
55
|
$not?: BaseQueryType;
|
|
56
|
+
/** Included in the provided array. */
|
|
23
57
|
$in?: BaseQueryType;
|
|
58
|
+
/** Not included in the provided array. */
|
|
24
59
|
$not_in?: BaseQueryType;
|
|
25
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Combined filter options for a field.
|
|
63
|
+
*/
|
|
26
64
|
export type WhereOptions = TextWhereOptions & CommonWhereOptions;
|
|
65
|
+
/**
|
|
66
|
+
* JSON structure representing the 'where' filter in a query.
|
|
67
|
+
* Keys are field names, and values can be primitive values or WhereOptions.
|
|
68
|
+
*/
|
|
27
69
|
export type QueryJson = {
|
|
28
70
|
[key: string]: QueryJson | WhereOptions | BaseQueryType;
|
|
29
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Filter for querying data at a specific block.
|
|
74
|
+
*/
|
|
30
75
|
export type BlockQuery = {
|
|
76
|
+
/** Filter by block hash. */
|
|
31
77
|
hash?: string;
|
|
78
|
+
/** Filter by exact block number. */
|
|
32
79
|
number?: number;
|
|
80
|
+
/** Filter by blocks with number greater than or equal to. */
|
|
33
81
|
number_gte?: number;
|
|
34
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Metadata fields to query from the subgraph (_meta).
|
|
85
|
+
*/
|
|
35
86
|
export type Metadata = {
|
|
87
|
+
/** Specific metadata elements to fetch. */
|
|
36
88
|
elements?: Array<'deployment' | 'hasIndexingErrors' | 'hash' | 'number' | 'timestamp'>;
|
|
89
|
+
/** Query metadata for a specific block. */
|
|
37
90
|
blockQuery?: BlockQuery;
|
|
38
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Represents a field in a query. Can be a simple string (field name)
|
|
94
|
+
* or a GraphObject for nested collection queries.
|
|
95
|
+
*/
|
|
39
96
|
export type ElementType = string | GraphObject;
|
|
97
|
+
/**
|
|
98
|
+
* Represents an inline fragment for polymorphic types.
|
|
99
|
+
*/
|
|
40
100
|
export type InlineFragmentType = {
|
|
101
|
+
/** The collection name for the fragment (e.g., 'User'). */
|
|
41
102
|
collection: string;
|
|
103
|
+
/** Fields to select within the fragment. */
|
|
42
104
|
params?: Pick<GraphParams, 'elements'>;
|
|
43
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Parameters for a collection query.
|
|
108
|
+
*/
|
|
44
109
|
export interface GraphParams {
|
|
110
|
+
/** Fields to select from the collection. */
|
|
45
111
|
elements?: Array<ElementType>;
|
|
112
|
+
/** Inline fragments for selecting fields on specific types. */
|
|
46
113
|
inlineFragments?: Array<InlineFragmentType>;
|
|
114
|
+
/** Filter conditions for the query. */
|
|
47
115
|
where?: QueryJson;
|
|
116
|
+
/** Filter by specific entity ID (shortcut for where: { id: ... }). */
|
|
48
117
|
id?: string;
|
|
118
|
+
/** Number of items to return (max 1000). */
|
|
49
119
|
first?: number;
|
|
120
|
+
/** Field to sort the results by. */
|
|
50
121
|
orderBy?: string;
|
|
122
|
+
/** Direction of the sort (asc or desc). */
|
|
51
123
|
orderDirection?: 'asc' | 'desc';
|
|
124
|
+
/** Number of items to skip (max 5000). */
|
|
52
125
|
skip?: number;
|
|
126
|
+
/** Re-run the query even if the subgraph has indexing errors. */
|
|
53
127
|
subgraphError?: 'allow' | 'deny';
|
|
128
|
+
/** Query the collection state at a specific block. */
|
|
54
129
|
block?: BlockQuery;
|
|
55
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Configuration for a query against a specific collection.
|
|
133
|
+
*/
|
|
56
134
|
export interface GraphObject {
|
|
135
|
+
/** The name of the collection to query (e.g., 'users'). */
|
|
57
136
|
collection: string;
|
|
137
|
+
/** Optional parameters for filtering, sorting, and pagination. */
|
|
58
138
|
params?: GraphParams;
|
|
59
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Error structure returned by The Graph API.
|
|
142
|
+
*/
|
|
60
143
|
export type ErrorObject = {
|
|
144
|
+
/** List of errors encountered during query execution. */
|
|
61
145
|
errors: Array<{
|
|
62
146
|
message: string;
|
|
63
147
|
locations: Array<unknown>;
|
|
64
148
|
}>;
|
|
65
149
|
};
|
|
66
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eth-graph-query",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.20",
|
|
4
|
+
"description": "A lightweight and flexible library for building The Graph queries using simple JSON objects. Eliminate the need for complex string concatenation and maintain type-safe queries.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"clear": "rm -rf dist",
|
|
16
16
|
"test": "vitest run",
|
|
17
17
|
"prepare": "npm run build && husky install",
|
|
18
|
-
"eslint": "eslint . --
|
|
18
|
+
"eslint": "eslint --config ./eslint.config.js --cache",
|
|
19
|
+
"format": "prettier --write .",
|
|
19
20
|
"prepublishOnly": "npm run clear && npm run build && npm run test"
|
|
20
21
|
},
|
|
21
22
|
"repository": {
|
|
@@ -33,28 +34,28 @@
|
|
|
33
34
|
},
|
|
34
35
|
"homepage": "https://github.com/phamhongphuc1999/eth-graph-query#readme",
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"axios": "^1.
|
|
37
|
+
"axios": "^1.13.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@commitlint/cli": "^
|
|
40
|
-
"@commitlint/config-conventional": "^
|
|
40
|
+
"@commitlint/cli": "^19.4.0",
|
|
41
|
+
"@commitlint/config-conventional": "^19.2.2",
|
|
42
|
+
"@eslint/js": "^9.29.0",
|
|
41
43
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
42
44
|
"@types/node": "^20.12.2",
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-
|
|
46
|
-
"eslint-
|
|
47
|
-
"eslint-plugin-
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"husky": "^
|
|
50
|
-
"lint-staged": "^13.2.2",
|
|
45
|
+
"eslint": "^9.29.0",
|
|
46
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
47
|
+
"eslint-plugin-import": "^2.32.0",
|
|
48
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
49
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
50
|
+
"eslint-plugin-react-refresh": "^0.4.20",
|
|
51
|
+
"husky": "^9.1.6",
|
|
51
52
|
"path": "^0.12.7",
|
|
52
|
-
"prettier": "^2.8.8",
|
|
53
53
|
"rollup-plugin-typescript-paths": "^1.5.0",
|
|
54
54
|
"tslib": "^2.6.2",
|
|
55
|
-
"typescript": "
|
|
56
|
-
"
|
|
57
|
-
"
|
|
55
|
+
"typescript": "5.5.3",
|
|
56
|
+
"typescript-eslint": "^8.34.1",
|
|
57
|
+
"vite": "^7.2.7",
|
|
58
|
+
"vitest": "^4.0.15"
|
|
58
59
|
},
|
|
59
60
|
"contributors": [
|
|
60
61
|
{
|
|
@@ -64,18 +65,12 @@
|
|
|
64
65
|
}
|
|
65
66
|
],
|
|
66
67
|
"engines": {
|
|
67
|
-
"node": ">=
|
|
68
|
-
"npm": ">=
|
|
68
|
+
"node": ">=20",
|
|
69
|
+
"npm": ">=10"
|
|
69
70
|
},
|
|
70
71
|
"commitlint": {
|
|
71
72
|
"extends": [
|
|
72
73
|
"@commitlint/config-conventional"
|
|
73
74
|
]
|
|
74
|
-
},
|
|
75
|
-
"lint-staged": {
|
|
76
|
-
"*.{js,jsx,ts,tsx}": "eslint --config ./.eslintrc-staged.cjs --cache --fix",
|
|
77
|
-
"*.{json,yml,md}": [
|
|
78
|
-
"prettier --write"
|
|
79
|
-
]
|
|
80
75
|
}
|
|
81
76
|
}
|