diff --git a/src/bond.test.ts b/src/bond.test.ts index f59550a..06df38b 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 f82cc49..07bc143 100644 --- a/src/index.ts +++ b/src/index.ts @@ -192,10 +192,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 23c7776..5dfd9f2 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -425,11 +425,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 { @@ -439,11 +439,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'); } /**