https://github.com/phamhongphuc1999/eth-graph-query
Simple package for creating query to the GraphQL in ethereum
https://github.com/phamhongphuc1999/eth-graph-query
the-graph
Last synced: 7 months ago
JSON representation
Simple package for creating query to the GraphQL in ethereum
- Host: GitHub
- URL: https://github.com/phamhongphuc1999/eth-graph-query
- Owner: phamhongphuc1999
- Created: 2023-06-09T08:23:17.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-31T02:26:22.000Z (11 months ago)
- Last Synced: 2024-11-07T07:14:19.252Z (8 months ago)
- Topics: the-graph
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/eth-graph-query
- Size: 1.39 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
eth-graph-querySimple package for creating query to [the GraphQL](https://thegraph.com/).
---
### Installation
- Using `npm`
```shell
npm install eth-graph-query```
- Using `yarn`
```shell
yarn add eth-graph-query
```- Using `bun`
```shell
bun install eth-graph-query
```---
### Usage
- The first thing you have to do is to create a query instance
```js
const query = new EthGraphQuery(root);
```- This package has three query options. Simply, you can create a direct string query
```js
result = await query.stringQuery(`query query {
collection1(first: 10) {
element1
element2
}
}`);
```- More readable, you can create a single json query
```js
const result = await query.query({
collection: 'collection1',
params: {
elements: ['element1', 'element2'],
first: 10,
},
});
```- You can create a multiple json queries
```js
const result = await query.multipleQuery([
{
collection: 'collection1',
params: {
elements: ['element11', 'element12'],
},
},
{
collection: 'collection2',
params: {
elements: ['element21', 'element22'],
},
},
]);
```- You can create a complex query
```js
const result = await query.multipleQuery([
{
collection: 'collection1',
params: {
elements: ['element11', 'element12'],
where: { element11: 'abc' },
},
},
{
collection: 'collection2',
params: {
elements: [
'element21',
{
collection: 'collection3',
params: {
elements: ['element31'],
where: {
id: { $in: ['123'] },
token_: { setId: { $in: ['1', 2, true] } },
element31: 'element31',
},
first: 50,
},
},
],
where: {
element21: '123',
collection3: { element31: '123' },
},
inlineFragments: [
{
collection: 'BridgeDepositTransaction',
params: { elements: ['id', 'l1Token'] },
},
{
collection: 'NameSignalTransaction',
params: { elements: ['id', 'timestamp'] },
},
],
},
},
]);
```---
### API
Read the [API Docs](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/documents/api.md), you also read my [examples](https://github.com/phamhongphuc1999/eth-graph-query/blob/main/examples)
---
### For developer
- Run example
```shell
npm run example example/file-name
```- Run test
```shell
npm run test
```### Reference
- https://spec.graphql.org