-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: make graphql queries compatible with new Squid #380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,18 @@ import { AssetType, PriceFilters } from '../../ports/prices/types' | |
|
||
const MAX_RESULTS = 1000 | ||
|
||
const PRICES_ITEMS_FILTERS_DICT: Record<string, string> = { | ||
wearableCategory: '$wearableCategory: String', | ||
emoteCategory: '$emoteCategory: String', | ||
isWearableHead: '$isWearableHead: Boolean', | ||
isWearableAccessory: '$isWearableAccessory: Boolean', | ||
} | ||
|
||
const PRICES_FILTERS_DICT: Record<string, string> = { | ||
expiresAt: '$expiresAt: BigInt', | ||
...PRICES_ITEMS_FILTERS_DICT, | ||
} | ||
|
||
export function collectionsShouldFetch(filters: PriceFilters) { | ||
const isCorrectNetworkFilter = | ||
!filters.network || !!(filters.network && filters.network === Network.MATIC) | ||
|
@@ -72,12 +84,17 @@ export function collectionsNFTsPricesQuery(filters: PriceFilters) { | |
}, | ||
AssetType.NFT | ||
) | ||
return `query NFTPrices( | ||
$expiresAt: String, | ||
$wearableCategory: String | ||
$emoteCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean) { | ||
|
||
const variablesBasedOnFilters = Object.entries(filters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the variables in the GraphQL query must be used somewhere in the query, so this new logic is to put them in dynamically just if they are being used after. |
||
.filter(([key, value]) => value !== undefined && key in PRICES_FILTERS_DICT) | ||
.map(([key]) => (PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '')) | ||
|
||
const variablesDefinition = variablesBasedOnFilters.length | ||
? `query NFTPrices(${variablesBasedOnFilters.join('\n')})` | ||
: `query NFTPrices` | ||
|
||
return ` | ||
${variablesDefinition} { | ||
prices: nfts ( | ||
first: ${MAX_RESULTS}, | ||
orderBy: id, | ||
|
@@ -103,12 +120,15 @@ export function collectionsNFTsPricesQueryById(filters: PriceFilters) { | |
AssetType.NFT | ||
) | ||
return `query NFTPrices( | ||
$lastId: ID, | ||
$expiresAt: String | ||
$wearableCategory: String | ||
$emoteCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean | ||
$lastId: String, | ||
${Object.entries(filters) | ||
.filter( | ||
([key, value]) => value !== undefined && key in PRICES_FILTERS_DICT | ||
) | ||
.map(([key]) => | ||
PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '' | ||
) | ||
.join('\n')} | ||
) { | ||
prices: nfts( | ||
first: ${MAX_RESULTS}, | ||
|
@@ -141,12 +161,18 @@ export function collectionsItemsPricesQuery(filters: PriceFilters) { | |
? '[wearable_v1, wearable_v2, smart_wearable_v1]' | ||
: '[emote_v1]' | ||
|
||
return `query ItemPrices( | ||
$wearableCategory: String | ||
$emoteCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean | ||
) { | ||
const variablesBasedOnFilters = Object.entries(filters) | ||
.filter( | ||
([key, value]) => value !== undefined && key in PRICES_ITEMS_FILTERS_DICT | ||
) | ||
.map(([key]) => (PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '')) | ||
|
||
const variablesDefinition = variablesBasedOnFilters.length | ||
? `query ItemPrices(${variablesBasedOnFilters.join('\n')})` | ||
: `query ItemPrices` | ||
|
||
return ` | ||
${variablesDefinition} { | ||
prices: items ( | ||
first: ${MAX_RESULTS}, | ||
orderBy: id, | ||
|
@@ -179,11 +205,15 @@ export function collectionsItemsPricesQueryById(filters: PriceFilters) { | |
: '[emote_v1]' | ||
|
||
return `query ItemPrices( | ||
$lastId: ID, | ||
$wearableCategory: String | ||
$emoteCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean | ||
$lastId: String, | ||
${Object.entries(filters) | ||
.filter( | ||
([key, value]) => value !== undefined && key in PRICES_FILTERS_DICT | ||
) | ||
.map(([key]) => | ||
PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '' | ||
) | ||
.join('\n')} | ||
) { | ||
prices: items ( | ||
first: ${MAX_RESULTS}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,14 @@ import { | |
|
||
const MAX_RESULTS = 1000 | ||
|
||
const PRICES_FILTERS_DICT: Record<string, string> = { | ||
expiresAt: '$expiresAt: BigInt', | ||
wearableCategory: '$wearableCategory: String', | ||
emoteCategory: '$emoteCategory: String', | ||
isWearableHead: '$isWearableHead: Boolean', | ||
isWearableAccessory: '$isWearableAccessory: Boolean', | ||
} | ||
|
||
export function marketplaceShouldFetch(filters: PriceFilters) { | ||
const isCorrectNetworkFilter = | ||
!filters.network || | ||
|
@@ -96,13 +104,18 @@ export function marketplacePricesQuery(filters: PriceFilters) { | |
searchEstateSize_gt: 0, | ||
${additionalWheres.join('\n')} | ||
` | ||
return `query NFTPrices( | ||
$expiresAt: String | ||
$expiresAtSec: String | ||
$wearableCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean | ||
) { | ||
|
||
const variablesBasedOnFilters = Object.entries(filters) | ||
.filter(([key, value]) => value !== undefined && key in PRICES_FILTERS_DICT) | ||
.map(([key]) => (PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '')) | ||
Comment on lines
+108
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about abstracting this mechanism so we can use it in all of these queries? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, great idea, let me prepare that in a following up PR so we can review that exclusively. |
||
|
||
const variablesDefinition = variablesBasedOnFilters.length | ||
? `query NFTPrices($expiresAtSec: BigInt, ${variablesBasedOnFilters.join( | ||
'\n' | ||
)})` | ||
: `query NFTPrices($expiresAtSec: BigInt, $expiresAt: BigInt)` | ||
|
||
return `${variablesDefinition} { | ||
prices: nfts( | ||
first: ${MAX_RESULTS}, | ||
orderBy: tokenId, | ||
|
@@ -130,13 +143,16 @@ export function marketplacePricesQueryById(filters: PriceFilters) { | |
const { category, ...rest } = filters | ||
const additionalWheres: string[] = getExtraWheres(rest) | ||
const categories = getNFTCategoryFromPriceCategory(category) | ||
return `query NFTPrices( | ||
$lastId: ID, | ||
$expiresAt: String | ||
$wearableCategory: String | ||
$isWearableHead: Boolean | ||
$isWearableAccessory: Boolean | ||
) { | ||
const variablesBasedOnFilters = Object.entries(filters) | ||
.filter(([key, value]) => value !== undefined && key in PRICES_FILTERS_DICT) | ||
.map(([key]) => (PRICES_FILTERS_DICT[key] ? PRICES_FILTERS_DICT[key] : '')) | ||
|
||
const variablesDefinition = variablesBasedOnFilters.length | ||
? `query NFTPrices($lastId: BigInt, ${variablesBasedOnFilters.join('\n')})` | ||
: `query NFTPrices($lastId: BigInt)` | ||
|
||
return ` | ||
${variablesDefinition} { | ||
prices: nfts( | ||
orderBy: tokenId, | ||
orderDirection: asc, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is needed to know if it needs to be applied in the query as parameter or not
https://github.com/decentraland/nft-server/pull/380/files#diff-d1debe4191e7ee45f023c53cecc0a2d6c05c4dba8f24d44c3a2c69261102a0bcR310