Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing fields #110

Merged
merged 32 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0defebc
proper count on token entity
daiagi Oct 4, 2023
2456fc3
remove exapnsive debug logs
daiagi Oct 4, 2023
3ec22b8
slim down - pass only collection id
daiagi Oct 4, 2023
0bcaafc
better debug logging
daiagi Oct 4, 2023
e470451
cheapest nft
daiagi Oct 4, 2023
3ae7031
improve performance
daiagi Oct 6, 2023
88a43f1
Merge branch 'tokenEnityt/fix-count-calc' of https://github.com/daiag…
daiagi Oct 6, 2023
0a93e90
resolver for tokenEntities of specific owner
daiagi Oct 6, 2023
0db457c
add metadata and meta to TokenEntity
daiagi Oct 6, 2023
2917612
add totalCount field to avoid bug when delting token
daiagi Oct 6, 2023
ef65343
Merge branch 'tokenEnityt/fix-count-calc' of https://github.com/daiag…
daiagi Oct 6, 2023
7e6e5dc
merge migration files
daiagi Oct 6, 2023
cd0de70
add meta and metadata to resolver
daiagi Oct 6, 2023
810718e
schema and migration
daiagi Oct 8, 2023
6559ba3
re orgenize
daiagi Oct 8, 2023
9a4aa70
schema name changes
daiagi Oct 8, 2023
4578868
name changes- resolver
daiagi Oct 8, 2023
96036d3
oops - undo comment out of unique handlers
daiagi Oct 8, 2023
3a97b0d
undo migration change
daiagi Oct 8, 2023
cbeda90
supply on resolver
daiagi Oct 8, 2023
8402c5e
use more utils
daiagi Oct 9, 2023
9eae7d8
fix orderBy, add denyList, owner can be null,
daiagi Oct 10, 2023
eb9a4dd
add collection floor price, fix typings
daiagi Oct 10, 2023
b5963dc
cheapest is already on tokenEntity
daiagi Oct 10, 2023
c684a66
total count resolver
daiagi Oct 10, 2023
7060884
drop collection floor price
daiagi Oct 10, 2023
789ff7b
syntax fix
daiagi Oct 10, 2023
6671e29
get 'cheapest' in resolver, drop it from schema
daiagi Oct 11, 2023
d858519
add current owner
daiagi Oct 11, 2023
40a43d4
`SELECT DISTINCT` to improve query performance
daiagi Oct 11, 2023
23ac70a
cheapest can have price:0
daiagi Oct 12, 2023
76692c8
😱 uncomment unique tranfer
daiagi Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/server-extension/model/tokenEntity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Collection {
}

@ObjectType()
export class TokenEntityByOwner {
export class TokenEntityModel {
@Field(() => String, { nullable: false })
id!: string;

Expand Down Expand Up @@ -95,13 +95,13 @@ export class TokenEntityByOwner {
collection!: Collection;


constructor(props: Partial<TokenEntityByOwner>) {
constructor(props: Partial<TokenEntityModel>) {
Object.assign(this, props);
}
}

@ObjectType()
export class TokenEntityByOwnerQueryResult {
export class TokenEntityQueryResult {
@Field(() => String, { nullable: false })
id!: string;

Expand Down Expand Up @@ -156,7 +156,7 @@ export class TokenEntityByOwnerQueryResult {



constructor(props: Partial<TokenEntityByOwner>) {
constructor(props: Partial<TokenEntityModel>) {
Object.assign(this, props);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const tokenEntityByOwner = `WITH cheapest_nft AS (
export const tokenEntities = `WITH cheapest_nft AS (
SELECT
ne.token_id,
ne.id AS nft_id,
Expand All @@ -7,17 +7,19 @@ export const tokenEntityByOwner = `WITH cheapest_nft AS (
FROM
nft_entity ne
WHERE
ne.current_owner = $1
($1::text IS NULL OR ne.current_owner = $1) AND
($7::text[] IS NULL OR ne.issuer NOT IN (SELECT unnest($7)))
vikiival marked this conversation as resolved.
Show resolved Hide resolved
),
nft_count AS (
SELECT
token_id,
COUNT(*) as count,
COUNT(CASE WHEN burned = false THEN 1 END) as supply
FROM
nft_entity
nft_entity ne
WHERE
current_owner = $1
($1::text IS NULL OR ne.current_owner = $1) AND
($7::text[] IS NULL OR ne.issuer NOT IN (SELECT unnest($7)))
GROUP BY
token_id
)
Expand Down Expand Up @@ -48,10 +50,7 @@ FROM
JOIN metadata_entity as me ON t.meta_id = me.id
JOIN nft_count ON t.id = nft_count.token_id
WHERE
($5::bigint IS NULL OR c.cheapest >= $5::bigint) AND
($6::bigint IS NULL OR c.cheapest > $6::bigint) AND
($7::bigint IS NULL OR c.cheapest <= $7::bigint)

ORDER BY $4 LIMIT $2 OFFSET $3;

($4::bigint IS NULL OR c.cheapest >= $4::bigint) AND
($5::bigint IS NULL OR c.cheapest > $5::bigint) AND
($6::bigint IS NULL OR c.cheapest <= $6::bigint)
`
2 changes: 1 addition & 1 deletion src/server-extension/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { WalletResolver } from './walletResolver'
export { EventResolver } from './event'
export { SeriesResolver } from './series'
export { SpotlightResolver } from './spotlight'
export { TokenResolver } from './tokenEntityByOwner'
export { TokenResolver } from './tokenEntities'
79 changes: 79 additions & 0 deletions src/server-extension/resolvers/tokenEntities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable camelcase */
import { Arg, Query, Resolver } from 'type-graphql'
import { EntityManager } from 'typeorm'
import { OrderBy, TokenEntityModel, TokenEntityQueryResult } from '../model/tokenEntity.model'
import { makeQuery } from '../utils'
import { tokenEntities } from '../query/tokenEntities'

@Resolver()
export class TokenResolver {
constructor(private tx: () => Promise<EntityManager>) {}

@Query(() => [TokenEntityModel])
async tokenEntityList(
@Arg('owner', { nullable: true }) owner?: string,
@Arg('limit', { nullable: true }) limit?: number,
@Arg('offset', { nullable: true, defaultValue: 0 }) offset?: number,
@Arg('orderBy', { nullable: true, defaultValue: OrderBy.blockNumber_DESC }) orderBy?: OrderBy,
@Arg('price_gte', { nullable: true }) price_gte?: number,
@Arg('price_gt', { nullable: true }) price_gt?: number,
@Arg('price_lte', { nullable: true }) price_lte?: number,
@Arg('denyList', () => [String], { nullable: true }) denyList?: string[]
): Promise<TokenEntityModel[]> {
const orderQuery = this.getOrderByQuery(orderBy)

const fullSQLQuery = `
${tokenEntities}
ORDER BY ${orderQuery} LIMIT $2 OFFSET $3;
`

const result: TokenEntityQueryResult[] = await makeQuery(this.tx, TokenEntityModel, fullSQLQuery, [
owner,
limit,
offset,
price_gte,
price_gt,
price_lte,
denyList,
])
return result.map(this.mapRowToTokenEntityByOwner)
}

private mapRowToTokenEntityByOwner(row: TokenEntityQueryResult): TokenEntityModel {
return {
...row,
blockNumber: row.block_number,
createdAt: row.created_at,
updatedAt: row.updated_at,
cheapest: {
id: row.cheapest_id,
price: row.cheapest_price,
},
collection: {
id: row.collection_id,
name: row.collection_name,
},
meta: {
id: row.meta_id,
description: row.meta_description,
animationUrl: row.meta_animation_url,
image: row.meta_image,
},
}
}

ORDER_BY_MAPPING: Record<OrderBy, string> = {
[OrderBy.blockNumber_ASC]: 'block_number ASC',
[OrderBy.blockNumber_DESC]: 'block_number DESC',
[OrderBy.createdAt_ASC]: 'created_at ASC',
[OrderBy.createdAt_DESC]: 'created_at DESC',
[OrderBy.updatedAt_ASC]: 'updated_at ASC',
[OrderBy.updatedAt_DESC]: 'updated_at DESC',
[OrderBy.price_ASC]: 'cheapest_price ASC',
[OrderBy.price_DESC]: 'cheapest_price DESC',
}

private getOrderByQuery(orderBy: OrderBy = OrderBy.blockNumber_DESC): string {
return this.ORDER_BY_MAPPING[orderBy] || 'block_number DESC' // default to "block_number DESC" if not found
}
}
82 changes: 0 additions & 82 deletions src/server-extension/resolvers/tokenEntityByOwner.ts
vikiival marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.