Skip to content

Commit

Permalink
Merge pull request #3044 from dusk-network/w3sper-network-query
Browse files Browse the repository at this point in the history
w3sper: Add `query { ... }` to argument given to `network.query`
  • Loading branch information
ZER0 authored Nov 22, 2024
2 parents 7f3d6c3 + c69d623 commit f4725e2
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions w3sper.js/src/network/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
);
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f4725e2

Please sign in to comment.