1.1.0 • Published 1 year ago

onium v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Onium

a lib you can make query to thegraph project hosted services and subgraphs.

Installation

Use the package manager npm to install Onium.

npm i onium

Usage

//! for hosted services.
import { host } from "onium";

// your hosted service endpoint:
const endpoint = "https://api.thegraph.com/subgraphs/name/[hosted-service-name]";

const query = `
{
    your graphQL query
}
`;

// make your query:
let data = await host(endpoint,query);

// get your data 😉🤞
console.log(data);






//! for subgraphs.
import { sub } from "onium";

// your subgraph endpoint:(dont change [api-key] just change [the-subgraph-id])
const endpoint = "https://gateway.thegraph.com/api/[api-key]/subgraphs/id/[the-subgraph-id]";


// your api key form : https://thegraph.com/
const apiKey = "here add your api key!";

const query = `
{
    your graphQL query
}
`;

// make your query:
let data = await sub(endpoint,query,apiKey);

// get your data 😉🤞
console.log(data);

makeQuery

This function is used when you want to reuse a query several times while changing the search parameter.

usage:

import {makeQuery} from "onium";

let myReuseableQuery = `
query {
  user(id: {ID}) {
    name
    address
  }
}
`;
const newQuery = makeQuery(myReuseableQuery,"{ID}",5);

// now you can use your query in sub or host funtion!
console.log(newQuery);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago