Skip to content

Commit

Permalink
Merge pull request #35 from kodadot/uni-v1-query
Browse files Browse the repository at this point in the history
💥 Uniquery v0.4
  • Loading branch information
vikiival authored Aug 16, 2023
2 parents d84569e + 8ae23f1 commit 64c9fa4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kodadot1/uniquery",
"version": "0.3.1-rc.0",
"version": "0.4.0",
"description": "Universal GraphQL query builder for KodaDot",
"repository": "kodadot/uniquery",
"license": "MIT",
Expand Down Expand Up @@ -28,7 +28,7 @@
"test": "vitest run --dir test"
},
"dependencies": {
"@kodadot1/static": "0.0.3-rc.5",
"@kodadot1/static": "0.0.3",
"gql-query-builder": "^3.8.0",
"ofetch": "^1.1.1",
"scule": "^1.0.0",
Expand Down
17 changes: 5 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/clients/SquidClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ class SquidClient implements AbstractClient<SquidCollection, SquidNFT> {
}

eventList(options?: QueryProps<BaseEvent>): GraphQuery {
const toQuery = getFields(options?.fields ?? defaultEventField)
const toQuery = getFields(options?.fields, defaultEventField, false)
const optionList = optionToQuery(options, true)
return build(`events(${optionList})`, toQuery)
}

eventListByAddress(address: string, options?: QueryProps<BaseEvent>): GraphQuery {
const toQuery = getFields(options?.fields ?? defaultEventField)
const toQuery = getFields(options?.fields, defaultEventField, false)
const optionList = optionToQuery(options, true)
return build(`events(where: {caller_eq: "${address}" } ${optionList})`, toQuery)
}

eventListByCollectionId(id: string, options?: QueryProps<BaseEvent>): GraphQuery {
const toQuery = getFields(options?.fields ?? defaultEventField)
const toQuery = getFields(options?.fields, defaultEventField, false)
const optionList = optionToQuery(options, true)
return build(`events(where: {nft: {id_eq: "${id}"}} ${optionList})`, toQuery)
// events(where: { nft: { collection: { id_eq: "" }}})
}

eventListByInteraction(interaction: string, options?: QueryProps<BaseEvent>): GraphQuery {
const toQuery = getFields(options?.fields ?? defaultEventField)
const toQuery = getFields(options?.fields, defaultEventField, false)
const optionList = optionToQuery(options, true)
return build(`events(where: {interaction_eq: ${interaction}} ${optionList})`, toQuery)
}

eventListByItemId(id: string, options?: QueryProps<BaseEvent>): GraphQuery {
const toQuery = getFields(options?.fields ?? defaultEventField)
const toQuery = getFields(options?.fields, defaultEventField, false)
const optionList = optionToQuery(options, true)
return build(`events(where: {nft: {id_eq: "${id}"}} ${optionList})`, toQuery)
}
Expand Down
11 changes: 6 additions & 5 deletions src/clients/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ export function extendFields<T extends AbstractBase>(fields: ObjProp<T>): ObjPro
return [...set]
}

export function getFields<T>(fields?: ObjProp<T>, defaultList: ObjProp<T> | string[] = defaultField): Fields<T> {
export function getFields<T>(fields?: ObjProp<T>, defaultList: ObjProp<T> | string[] = defaultField, replaceMetaField = true): Fields<T> {
const list = fields ?? defaultList

const metaIndex = list.findIndex(hasMetaField)
if (replaceMetaField) {
const metaIndex = list.findIndex(hasMetaField)

if (metaIndex !== -1) {
list.splice(metaIndex, 1, { meta: ['id', 'name', 'description', 'image', 'animationUrl', 'type'] } as any)
if (metaIndex !== -1) {
list.splice(metaIndex, 1, { meta: ['id', 'name', 'description', 'image', 'animationUrl', 'type'] } as any)
}
}

return list
}

Expand Down
13 changes: 3 additions & 10 deletions src/rest/indexers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { INDEXERS } from '@kodadot1/static'
import { Prefix } from './types'

export const indexers: Record<Prefix, string> = {
ksm: 'https://squid.subsquid.io/rubick/v/008',
bsx: 'https://squid.subsquid.io/snekk/v/005',
snek: 'https://squid.subsquid.io/snekk/v/004',
movr: 'https://squid.subsquid.io/antick/v/001-rc0',
glmr: 'https://squid.subsquid.io/click/v/002'
}
export const getUrl = (chain: Prefix | ''): string => INDEXERS[chain]

export const getUrl = (chain: Prefix | ''): string => indexers[chain]

export const getAvailableChains = (): Prefix[] => Object.keys(indexers) as Prefix[]
export const getAvailableChains = (): Prefix[] => Object.keys(INDEXERS) as Prefix[]
20 changes: 20 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ describe('UNIQUERY UTILS', () => {
const fn = () => getUrl('ksm', 'subquery')
expect(fn).toThrow(ReferenceError)
})

it('should return default kusama indexer', () => {
const url = getUrl('ksm')
expect(url).eq('https://squid.subsquid.io/marck/v/v2/graphql')
})

it('should return default basilisk indexer', () => {
const url = getUrl('bsx')
expect(url).eq('https://squid.subsquid.io/snekk/graphql')
})

it('should return default Kusama Asset Hub indexer', () => {
const url = getUrl('ahk')
expect(url).eq('https://squid.subsquid.io/stick/graphql')
})

it('should return default Polkadot Asset Hub indexer', () => {
const url = getUrl('ahp')
expect(url).eq('https://squid.subsquid.io/speck/graphql')
})
})

describe('getFields', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ describe.only('Path utils', () => {
for (const test of tests) {
it(test.input, () => {
const res = pathToRequest(`/bsx/${test.input}`)
expect(res.baseURL).toBe('https://squid.subsquid.io/snekk/v/005')
expect(res.baseURL).toBe('https://squid.subsquid.io/snekk/graphql')
expect(res).haveOwnProperty('query')
expect(res.query).not.toBeUndefined()
})
}
})

describe('faioled path to request', () => {
describe('failed path to request', () => {
const tests = [
{ input: 'sbx/collection/2305670031' },
{ input: 'rmrk/itemById/2305670031-1' },
Expand Down

0 comments on commit 64c9fa4

Please sign in to comment.