From 7a27ab4be8c62adfa350004713df9968b7b89202 Mon Sep 17 00:00:00 2001 From: maayan Date: Wed, 17 May 2023 10:43:38 -0700 Subject: [PATCH] token ownership fields fragment --- .../sdk/src/indexer/generated/operations.ts | 2 + .../sdk/src/indexer/generated/queries.ts | 115 +++++++----------- ...urrentTokenOwnershipFieldsFragment.graphql | 37 ++++++ .../indexer/queries/getOwnedTokens.graphql | 37 +----- .../getTokenOwnedFromCollection.graphql | 37 +----- .../sdk/src/tests/e2e/indexer.test.ts | 1 - 6 files changed, 86 insertions(+), 143 deletions(-) create mode 100644 ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql diff --git a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts index d0e1f16f88f41..63fa1aeb5585e 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/operations.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/operations.ts @@ -1,5 +1,7 @@ import * as Types from './types'; +export type CurrentTokenOwnershipFieldsFragment = { __typename?: 'current_token_ownerships_v2', token_standard: string, is_fungible_v2?: boolean | null, is_soulbound_v2?: boolean | null, property_version_v1: any, table_type_v1?: string | null, token_properties_mutated_v1?: any | null, amount: any, last_transaction_timestamp: any, last_transaction_version: any, storage_id: string, owner_address: string, current_token_data?: { __typename?: 'current_token_datas_v2', token_name: string, token_data_id: string, token_uri: string, token_properties: any, supply: any, maximum?: any | null, last_transaction_version: any, last_transaction_timestamp: any, largest_property_version_v1?: any | null, current_collection?: { __typename?: 'current_collections_v2', collection_name: string, creator_address: string, description: string, uri: string, collection_id: string, last_transaction_version: any, current_supply: any, mutable_description?: boolean | null, total_minted_v2?: any | null, table_handle_v1?: string | null, mutable_uri?: boolean | null } | null } | null }; + export type GetAccountCoinsDataQueryVariables = Types.Exact<{ owner_address?: Types.InputMaybe; offset?: Types.InputMaybe; diff --git a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts index 47a8ce608d5b2..33d71de4a5184 100644 --- a/ecosystem/typescript/sdk/src/indexer/generated/queries.ts +++ b/ecosystem/typescript/sdk/src/indexer/generated/queries.ts @@ -2,6 +2,45 @@ import * as Types from './operations'; import { GraphQLClient } from 'graphql-request'; import * as Dom from 'graphql-request/dist/types.dom'; +export const CurrentTokenOwnershipFieldsFragmentDoc = ` + fragment CurrentTokenOwnershipFields on current_token_ownerships_v2 { + token_standard + is_fungible_v2 + is_soulbound_v2 + property_version_v1 + table_type_v1 + token_properties_mutated_v1 + amount + last_transaction_timestamp + last_transaction_version + storage_id + owner_address + current_token_data { + token_name + token_data_id + token_uri + token_properties + supply + maximum + last_transaction_version + last_transaction_timestamp + largest_property_version_v1 + current_collection { + collection_name + creator_address + description + uri + collection_id + last_transaction_version + current_supply + mutable_description + total_minted_v2 + table_handle_v1 + mutable_uri + } + } +} + `; export const TokenDataFieldsFragmentDoc = ` fragment TokenDataFields on current_token_datas { creator_address @@ -149,44 +188,10 @@ export const GetOwnedTokens = ` offset: $offset limit: $limit ) { - token_standard - is_fungible_v2 - is_soulbound_v2 - property_version_v1 - table_type_v1 - token_properties_mutated_v1 - amount - last_transaction_timestamp - last_transaction_version - storage_id - owner_address - current_token_data { - token_name - token_data_id - token_uri - token_properties - supply - maximum - last_transaction_version - last_transaction_timestamp - largest_property_version_v1 - current_collection { - collection_name - creator_address - description - uri - collection_id - last_transaction_version - current_supply - mutable_description - total_minted_v2 - table_handle_v1 - mutable_uri - } - } + ...CurrentTokenOwnershipFields } } - `; + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenActivities = ` query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) { token_activities( @@ -245,44 +250,10 @@ export const GetTokenOwnedFromCollection = ` offset: $offset limit: $limit ) { - token_standard - is_fungible_v2 - is_soulbound_v2 - property_version_v1 - table_type_v1 - token_properties_mutated_v1 - amount - last_transaction_timestamp - last_transaction_version - storage_id - owner_address - current_token_data { - token_name - token_data_id - token_uri - token_properties - supply - maximum - last_transaction_version - last_transaction_timestamp - largest_property_version_v1 - current_collection { - collection_name - creator_address - description - uri - collection_id - last_transaction_version - current_supply - mutable_description - total_minted_v2 - table_handle_v1 - mutable_uri - } - } + ...CurrentTokenOwnershipFields } } - `; + ${CurrentTokenOwnershipFieldsFragmentDoc}`; export const GetTokenOwnersData = ` query getTokenOwnersData($token_id: String, $property_version: numeric) { current_token_ownerships( diff --git a/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql b/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql new file mode 100644 index 0000000000000..07f6651851250 --- /dev/null +++ b/ecosystem/typescript/sdk/src/indexer/queries/CurrentTokenOwnershipFieldsFragment.graphql @@ -0,0 +1,37 @@ +fragment CurrentTokenOwnershipFields on current_token_ownerships_v2 { + token_standard + is_fungible_v2 + is_soulbound_v2 + property_version_v1 + table_type_v1 + token_properties_mutated_v1 + amount + last_transaction_timestamp + last_transaction_version + storage_id + owner_address + current_token_data { + token_name + token_data_id + token_uri + token_properties + supply + maximum + last_transaction_version + last_transaction_timestamp + largest_property_version_v1 + current_collection { + collection_name + creator_address + description + uri + collection_id + last_transaction_version + current_supply + mutable_description + total_minted_v2 + table_handle_v1 + mutable_uri + } + } +} diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql index 7387ec09a44da..1920e431db6bc 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getOwnedTokens.graphql @@ -1,43 +1,10 @@ +#import "./CurrentTokenOwnershipFieldsFragment"; query getOwnedTokens($address: String!, $offset: Int, $limit: Int) { current_token_ownerships_v2( where: { owner_address: { _eq: $address }, amount: { _gt: 0 } } offset: $offset limit: $limit ) { - token_standard - is_fungible_v2 - is_soulbound_v2 - property_version_v1 - table_type_v1 - token_properties_mutated_v1 - amount - last_transaction_timestamp - last_transaction_version - storage_id - owner_address - current_token_data { - token_name - token_data_id - token_uri - token_properties - supply - maximum - last_transaction_version - last_transaction_timestamp - largest_property_version_v1 - current_collection { - collection_name - creator_address - description - uri - collection_id - last_transaction_version - current_supply - mutable_description - total_minted_v2 - table_handle_v1 - mutable_uri - } - } + ...CurrentTokenOwnershipFields } } diff --git a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql index 39974c95e8371..978fa420c16dd 100644 --- a/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql +++ b/ecosystem/typescript/sdk/src/indexer/queries/getTokenOwnedFromCollection.graphql @@ -1,3 +1,4 @@ +#import "./CurrentTokenOwnershipFieldsFragment"; query getTokenOwnedFromCollection($collection_id: String!, $owner_address: String!, $offset: Int, $limit: Int) { current_token_ownerships_v2( where: { @@ -8,40 +9,6 @@ query getTokenOwnedFromCollection($collection_id: String!, $owner_address: Strin offset: $offset limit: $limit ) { - token_standard - is_fungible_v2 - is_soulbound_v2 - property_version_v1 - table_type_v1 - token_properties_mutated_v1 - amount - last_transaction_timestamp - last_transaction_version - storage_id - owner_address - current_token_data { - token_name - token_data_id - token_uri - token_properties - supply - maximum - last_transaction_version - last_transaction_timestamp - largest_property_version_v1 - current_collection { - collection_name - creator_address - description - uri - collection_id - last_transaction_version - current_supply - mutable_description - total_minted_v2 - table_handle_v1 - mutable_uri - } - } + ...CurrentTokenOwnershipFields } } diff --git a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts index 5063130404b28..a448492f8f94a 100644 --- a/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts +++ b/ecosystem/typescript/sdk/src/tests/e2e/indexer.test.ts @@ -264,7 +264,6 @@ describe("Indexer", () => { it( "returns same result for getTokenOwnedFromCollectionNameAndCreatorAddress and getTokenOwnedFromCollectionAddress", async () => { - console.log(alice.address().hex()); const collectionAddress = await indexerClient.getCollectionAddress(alice.address().hex(), collectionNameV2); const tokensFromCollectionAddress = await indexerClient.getTokenOwnedFromCollectionAddress( alice.address().hex(),