From c69d623a4d99f0f7b1ce15d8fc4f6f6ec30d1450 Mon Sep 17 00:00:00 2001 From: zer0 Date: Fri, 22 Nov 2024 11:45:09 +0100 Subject: [PATCH] w3sper: Add `query { ... }` to argument given to `network.query` - Remove unused private functions from network module --- w3sper.js/src/network/mod.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/w3sper.js/src/network/mod.js b/w3sper.js/src/network/mod.js index 2559422d5..eef9aa494 100644 --- a/w3sper.js/src/network/mod.js +++ b/w3sper.js/src/network/mod.js @@ -18,16 +18,6 @@ export { AddressSyncer } from "./syncer/address.js"; export { AccountSyncer } from "./syncer/account.js"; export { Bookmark } from "./bookmark.js"; -const abortable = (signal) => - new Promise((resolve, reject) => - signal?.aborted ? reject(signal.reason) : resolve(signal), - ); - -const once = (target, topic) => - new Promise((resolve) => - target.addEventListener(topic, resolve, { once: true }), - ); - export class Network { #rues; node; @@ -81,8 +71,8 @@ export class Network { // I suspect is a GraphQL limitation. In the meantime we convert the `Number` // to a `BigInt` for consistency and future proof of the API's consumers. get blockHeight() { - return this.query("query { block(height: -1) { header { height } }}").then( - (body) => BigInt(body?.block?.header?.height ?? 0), + return this.query("block(height: -1) { header { height } }").then((body) => + BigInt(body?.block?.header?.height ?? 0), ); } @@ -110,6 +100,8 @@ export class Network { } async query(gql, options = {}) { + gql = gql ? `query { ${gql} }` : ""; + const response = await this.#rues.scope("graphql").call.query(gql, options); switch (response.status) {