diff --git a/src/bond.test.ts b/src/bond.test.ts index ce4524c..6bbeb7f 100644 --- a/src/bond.test.ts +++ b/src/bond.test.ts @@ -54,15 +54,20 @@ const bondTests = () => { test('Query bonds.', async () => { const bonds = await registry.queryBonds(); expect(bonds).toBeDefined(); - const bond = bonds.filter((bond: any) => bond.id === bond1.id); - expect(bond).toBeDefined(); + + const filteredBonds = bonds.filter((bond: any) => bond.id === bond1.id); + expect(filteredBonds).toHaveLength(1); + expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner }); }); test('Query bonds by owner.', async () => { - const bonds = await registry.queryBonds({ owner: bond1.owner }); - expect(bonds).toBeDefined(); - const bond = bonds.filter((bond: any) => bond.id === bond1.id); - expect(bond).toBeDefined(); + const [result] = await registry.queryBondsByOwner([bond1.owner]); + expect(result).toBeDefined(); + expect(result.bonds).toBeDefined(); + + const filteredBonds = result.bonds.filter((bond: any) => bond.id === bond1.id); + expect(filteredBonds).toHaveLength(1); + expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner }); }); test('Refill bond.', async () => { diff --git a/src/index.ts b/src/index.ts index 2ad56a1..09c5e1a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -186,10 +186,17 @@ export class Registry { } /** - * Query bonds by attributes. + * Query bonds. */ - async queryBonds (attributes = {}) { - return this._client.queryBonds(attributes); + async queryBonds () { + return this._client.queryBonds(); + } + + /** + * Query bonds by owner(s). + */ + async queryBondsByOwner (owners: string[]) { + return this._client.queryBondsByOwner(owners); } /** diff --git a/src/registry-client.ts b/src/registry-client.ts index 2b64bf1..08ebefa 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -427,11 +427,11 @@ export class RegistryClient { } /** - * Get bonds by attributes. + * Get bonds. */ - async queryBonds (attributes = {}) { - const query = `query ($attributes: [KeyValueInput!]) { - queryBonds(attributes: $attributes) { + async queryBonds () { + const query = `query { + queryBonds { id owner balance { @@ -441,11 +441,32 @@ export class RegistryClient { } }`; + return RegistryClient.getResult(this._graph(query)({}), 'queryBonds'); + } + + /** + * Get bonds by owner(s). + */ + async queryBondsByOwner (ownerAddresses: string[]) { + const query = `query ($ownerAddresses: [String!]) { + queryBondsByOwner(ownerAddresses: $ownerAddresses) { + owner + bonds { + id + owner + balance { + type + quantity + } + } + } + }`; + const variables = { - attributes: Util.toGQLAttributes(attributes) + ownerAddresses }; - return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds'); + return RegistryClient.getResult(this._graph(query)(variables), 'queryBondsByOwner'); } /**