Skip to content

Commit

Permalink
Merge pull request #49 from roiLeo/feature/collectionByIdIn
Browse files Browse the repository at this point in the history
✨ colleciton by Id in
  • Loading branch information
vikiival authored Oct 10, 2024
2 parents b0d5d28 + 3cd9b86 commit 32b36cb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/clients/SquidClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class SquidClient implements AbstractClient<SquidCollection, SquidNFT> {
})
}

collectionByIdIn(id: string | string[], fields?: ObjProp<SquidCollection>): GraphQuery {
const toQuery = getFields(fields)
const list = Array.isArray(id)
? JSON.stringify(id)
: JSON.stringify(id.split(','))
return build(
`collections: collectionEntities(where: {id_in: ${list}})`,
toQuery,
)
}

collectionCountByIssuer(issuer: string): GraphQuery {
const { operation, fields, variables } = genericCountQuery('collection', {
issuer_eq: issuer,
Expand Down
1 change: 1 addition & 0 deletions src/clients/abstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BaseEvent, GraphLike, GraphQuery, ObjProp, QueryProps } from '../types'
// Collection, Token
interface AbstractClient<C, T, E = BaseEvent> {
collectionById(id: string, fields?: ObjProp<C>): GraphQuery
collectionByIdIn(id: string | string[], fields?: ObjProp<C>): GraphQuery
// collectionListBy(id: string, field: KeyOf<C>, fields?: ObjProp<C>): GraphQuery
collectionCountByIssuer(issuer: string): GraphQuery
collectionCountByName(name: string): GraphQuery
Expand Down
1 change: 1 addition & 0 deletions src/rest/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ClientCall, GraphRequest, Prefix } from './types'

const pathMap: Record<string, ClientCall> = {
collection: 'collectionById',
collectionByIdIn: 'collectionByIdIn',
collectionByIssuer: 'collectionListByIssuer',
collectionByName: 'collectionListByName',
collectionByOwner: 'collectionListByOwner',
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('UNIQUERY UTILS', () => {

it('should return default kusama indexer', () => {
const url = getUrl('ksm')
expect(url).eq('https://ahk.gql.api.kodadot.xyz/')
expect(url).eq('https://ksm.gql.api.kodadot.xyz/')
})

it('should return default base indexer', () => {
Expand Down
29 changes: 28 additions & 1 deletion test/path.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, it, describe } from 'vitest'
import { parsePath, pathToRequest } from '../src/rest/path'
import { getClient } from '../src'

describe.only('Path utils', () => {
describe('parse path should', () => {
Expand All @@ -20,7 +21,33 @@ describe.only('Path utils', () => {
})
})

describe('path to request', () => {
describe('collecion id in', () => {
const id = [
'0xd9a2c93ba2e9fae10fe762a42ee807bbf95764cc',
'0x2f36072129aabb22bd4afffca0640a3e02695925'
]

it('should do something', () => {
const res = pathToRequest('/base/collectionByIdIn/' + id)
expect(res.query).not.toBeUndefined()
})

it('should return collection In result when passing string separeted by ,', async () => {
const client = getClient('base')
const query = client.collectionByIdIn(id.toString())
const result = await client.fetch(query)
expect(result).not.toBeUndefined()
})

it('should return collection Id In result when passing array', async () => {
const client = getClient('base')
const query = client.collectionByIdIn(id)
const result = await client.fetch(query)
expect(result).not.toBeUndefined()
})
})

describe('ahk path to request', () => {
const tests = [
{ input: 'collection/2305670031' },
{ input: 'collectionByIssuer/bXhUWXbffHMJk2FoTriLixXjQY36RPDkX5Tugy5WYSmafJsGi' },
Expand Down

0 comments on commit 32b36cb

Please sign in to comment.