diff --git a/src/clients/SquidClient.ts b/src/clients/SquidClient.ts index 3928f54..4ae3810 100644 --- a/src/clients/SquidClient.ts +++ b/src/clients/SquidClient.ts @@ -20,6 +20,7 @@ import { genericCountQuery, getFields, includeBurned, + includeBurnedOption, optionToQuery, } from './defaults' @@ -362,10 +363,11 @@ class SquidClient implements AbstractClient { ): GraphQuery { const toQuery = getFields(options?.fields) const optionList = optionToQuery(options, true) + const burned = includeBurnedOption(options) return build( - `items: nftEntities(where: {collection: {id_eq: "${id}"}} ${optionList})`, - toQuery, - ) + `items: nftEntities(where: {collection: {id_eq: "${id}"} ${burned}} ${optionList})`, + toQuery + ); } itemListForSale(options?: QueryProps): GraphQuery { diff --git a/src/clients/defaults.ts b/src/clients/defaults.ts index ee7e70c..cadd337 100644 --- a/src/clients/defaults.ts +++ b/src/clients/defaults.ts @@ -104,7 +104,7 @@ export function ensureOrderBy(orderBy?: OrderBy | OrderBy[]): string { return Array.isArray(orderBy) ? stringFromArray(orderBy) : orderBy ?? '[]' // this is a trick to handle undefined } -type Burned = '' | `burned_eq: ${false}` +type Burned = '' | `burned_eq: ${false}` | `burned_eq: ${true}` export function includeBurned(options?: QueryProps): Burned { if (options && options.burned) { return '' @@ -113,6 +113,14 @@ export function includeBurned(options?: QueryProps): Burned { return 'burned_eq: false' } +export function includeBurnedOption(options?: QueryProps): Burned { + if (options && String(options.burned)) { + return `burned_eq: ${options.burned}` + } + + return '' +} + export function strOf(value: T): string { return `"${value}"` } diff --git a/test/path.test.ts b/test/path.test.ts index ca5fb6c..9b7f431 100644 --- a/test/path.test.ts +++ b/test/path.test.ts @@ -1,6 +1,6 @@ import { expect, it, describe } from 'vitest' import { parsePath, pathToRequest } from '../src/rest/path' -import { getClient } from '../src' +import { extendFields, getClient } from '../src' describe.only('Path utils', () => { describe('parse path should', () => { @@ -47,6 +47,37 @@ describe.only('Path utils', () => { }) }) + describe('ahp filter burned items', () => { + const collectionId = '244' + const client = getClient('ahp') + + it('should return only burned items from collection', async () => { + const query = client.itemListByCollectionId(collectionId, { burned: true, orderBy: 'blockNumber_ASC', fields: extendFields(['burned']) }) + const result = await client.fetch(query) + + expect(result).not.toBeUndefined() + + if (result.data) { + result.data.items.forEach(element => { + expect(element).toHaveProperty('burned', true) + }) + } + }) + + it('should return all non-burned items from collection', async () => { + const query = client.itemListByCollectionId(collectionId, { burned: false, orderBy: 'blockNumber_ASC', fields: extendFields(['burned']) }) + const result = await client.fetch(query) + + expect(result).not.toBeUndefined() + + if (result.data) { + result.data.items.forEach(element => { + expect(element).toHaveProperty('burned', false) + }) + } + }) + }) + describe('ahk path to request', () => { const tests = [ { input: 'collection/2305670031' },