Skip to content

Commit

Permalink
improve indexer client to support tokenv2 sorting and new queries (#9395
Browse files Browse the repository at this point in the history
)
  • Loading branch information
0xmaayan authored Aug 2, 2023
1 parent 4afc2a2 commit f0de1b3
Show file tree
Hide file tree
Showing 21 changed files with 3,390 additions and 918 deletions.
7 changes: 7 additions & 0 deletions ecosystem/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
All notable changes to the Aptos Node SDK will be captured in this file. This changelog is written by hand for now. It adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Export all remaining types and functions in TS SDK
- Add improvements for `IndexerClient`
- Export indexer types - `export * from "/indexer/generated/types"`
- Support for token v2 activities - `getTokenActivities`, response structure has changed
- Aggregate query suports token v2 activities - `getTokenActivitiesCount`
- Support for sorting indexer queries - `orderBy` optional argument in `extraArgs` arguments
- Support for get owned tokens by token address or token data id - `getOwnedTokensByTokenData`

## 1.15.0 (2023-07-28)

Expand Down
1 change: 1 addition & 0 deletions ecosystem/typescript/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from "./utils/hex_string";
export * from "./utils/hd-key";
export * from "./utils/property_map_serde";
export { APTOS_COIN } from "./utils/misc";
export * from "./indexer/generated/types";
36 changes: 31 additions & 5 deletions ecosystem/typescript/sdk/src/indexer/generated/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ export type TokenDataFieldsFragment = { __typename?: 'current_token_datas', crea
export type CollectionDataFieldsFragment = { __typename?: 'current_collection_datas', metadata_uri: string, supply: any, description: string, collection_name: string, collection_data_id_hash: string, table_handle: string, creator_address: string };

export type GetAccountTokensCountQueryVariables = Types.Exact<{
owner_address?: Types.InputMaybe<Types.Scalars['String']>;
where_condition?: Types.InputMaybe<Types.Current_Token_Ownerships_V2_Bool_Exp>;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
}>;


export type GetAccountTokensCountQuery = { __typename?: 'query_root', current_token_ownerships_aggregate: { __typename?: 'current_token_ownerships_aggregate', aggregate?: { __typename?: 'current_token_ownerships_aggregate_fields', count: number } | null } };
export type GetAccountTokensCountQuery = { __typename?: 'query_root', current_token_ownerships_v2_aggregate: { __typename?: 'current_token_ownerships_v2_aggregate', aggregate?: { __typename?: 'current_token_ownerships_v2_aggregate_fields', count: number } | null } };

export type GetAccountTransactionsCountQueryVariables = Types.Exact<{
address?: Types.InputMaybe<Types.Scalars['String']>;
Expand All @@ -51,6 +53,7 @@ export type GetCollectionDataQueryVariables = Types.Exact<{
where_condition: Types.Current_Collections_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Collections_V2_Order_By> | Types.Current_Collections_V2_Order_By>;
}>;


Expand All @@ -60,6 +63,7 @@ export type GetCollectionsWithOwnedTokensQueryVariables = Types.Exact<{
where_condition: Types.Current_Collection_Ownership_V2_View_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Collection_Ownership_V2_View_Order_By> | Types.Current_Collection_Ownership_V2_View_Order_By>;
}>;


Expand Down Expand Up @@ -89,36 +93,54 @@ export type GetOwnedTokensQueryVariables = Types.Exact<{
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Ownerships_V2_Order_By> | Types.Current_Token_Ownerships_V2_Order_By>;
}>;


export type GetOwnedTokensQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __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 GetOwnedTokensByTokenDataQueryVariables = Types.Exact<{
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Ownerships_V2_Order_By> | Types.Current_Token_Ownerships_V2_Order_By>;
}>;


export type GetOwnedTokensByTokenDataQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __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 GetTokenActivitiesQueryVariables = Types.Exact<{
idHash: Types.Scalars['String'];
where_condition: Types.Token_Activities_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Token_Activities_V2_Order_By> | Types.Token_Activities_V2_Order_By>;
}>;


export type GetTokenActivitiesQuery = { __typename?: 'query_root', token_activities: Array<{ __typename?: 'token_activities', creator_address: string, collection_name: string, name: string, token_data_id_hash: string, collection_data_id_hash: string, from_address?: string | null, to_address?: string | null, transaction_version: any, transaction_timestamp: any, property_version: any, transfer_type: string, event_sequence_number: any, token_amount: any }> };
export type GetTokenActivitiesQuery = { __typename?: 'query_root', token_activities_v2: Array<{ __typename?: 'token_activities_v2', after_value?: string | null, before_value?: string | null, entry_function_id_str?: string | null, event_account_address: string, event_index: any, from_address?: string | null, is_fungible_v2?: boolean | null, property_version_v1: any, to_address?: string | null, token_amount: any, token_data_id: string, token_standard: string, transaction_timestamp: any, transaction_version: any, type: string }> };

export type GetTokenActivitiesCountQueryVariables = Types.Exact<{
token_id?: Types.InputMaybe<Types.Scalars['String']>;
}>;


export type GetTokenActivitiesCountQuery = { __typename?: 'query_root', token_activities_aggregate: { __typename?: 'token_activities_aggregate', aggregate?: { __typename?: 'token_activities_aggregate_fields', count: number } | null } };
export type GetTokenActivitiesCountQuery = { __typename?: 'query_root', token_activities_v2_aggregate: { __typename?: 'token_activities_v2_aggregate', aggregate?: { __typename?: 'token_activities_v2_aggregate_fields', count: number } | null } };

export type GetTokenCurrentOwnerDataQueryVariables = Types.Exact<{
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Ownerships_V2_Order_By> | Types.Current_Token_Ownerships_V2_Order_By>;
}>;


export type GetTokenCurrentOwnerDataQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __typename?: 'current_token_ownerships_v2', owner_address: string }> };

export type GetTokenDataQueryVariables = Types.Exact<{
where_condition?: Types.InputMaybe<Types.Current_Token_Datas_V2_Bool_Exp>;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Datas_V2_Order_By> | Types.Current_Token_Datas_V2_Order_By>;
}>;


Expand All @@ -128,13 +150,17 @@ export type GetTokenOwnedFromCollectionQueryVariables = Types.Exact<{
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Ownerships_V2_Order_By> | Types.Current_Token_Ownerships_V2_Order_By>;
}>;


export type GetTokenOwnedFromCollectionQuery = { __typename?: 'query_root', current_token_ownerships_v2: Array<{ __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 GetTokenOwnersDataQueryVariables = Types.Exact<{
where_condition: Types.Current_Token_Ownerships_V2_Bool_Exp;
offset?: Types.InputMaybe<Types.Scalars['Int']>;
limit?: Types.InputMaybe<Types.Scalars['Int']>;
order_by?: Types.InputMaybe<Array<Types.Current_Token_Ownerships_V2_Order_By> | Types.Current_Token_Ownerships_V2_Order_By>;
}>;


Expand Down
101 changes: 71 additions & 30 deletions ecosystem/typescript/sdk/src/indexer/generated/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ export const GetAccountCurrentTokens = `
${TokenDataFieldsFragmentDoc}
${CollectionDataFieldsFragmentDoc}`;
export const GetAccountTokensCount = `
query getAccountTokensCount($owner_address: String) {
current_token_ownerships_aggregate(
where: {owner_address: {_eq: $owner_address}, amount: {_gt: "0"}}
query getAccountTokensCount($where_condition: current_token_ownerships_v2_bool_exp, $offset: Int, $limit: Int) {
current_token_ownerships_v2_aggregate(
where: $where_condition
offset: $offset
limit: $limit
) {
aggregate {
count
Expand Down Expand Up @@ -138,8 +140,13 @@ export const GetAccountTransactionsData = `
}
`;
export const GetCollectionData = `
query getCollectionData($where_condition: current_collections_v2_bool_exp!, $offset: Int, $limit: Int) {
current_collections_v2(where: $where_condition, offset: $offset, limit: $limit) {
query getCollectionData($where_condition: current_collections_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_collections_v2_order_by!]) {
current_collections_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
collection_id
token_standard
collection_name
Expand All @@ -151,12 +158,12 @@ export const GetCollectionData = `
}
`;
export const GetCollectionsWithOwnedTokens = `
query getCollectionsWithOwnedTokens($where_condition: current_collection_ownership_v2_view_bool_exp!, $offset: Int, $limit: Int) {
query getCollectionsWithOwnedTokens($where_condition: current_collection_ownership_v2_view_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_collection_ownership_v2_view_order_by!]) {
current_collection_ownership_v2_view(
where: $where_condition
order_by: {last_transaction_version: desc}
offset: $offset
limit: $limit
order_by: $order_by
) {
current_collection {
creator_address
Expand Down Expand Up @@ -206,59 +213,84 @@ export const GetNumberOfDelegators = `
}
`;
export const GetOwnedTokens = `
query getOwnedTokens($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int) {
query getOwnedTokens($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_token_ownerships_v2_order_by!]) {
current_token_ownerships_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
...CurrentTokenOwnershipFields
}
}
${CurrentTokenOwnershipFieldsFragmentDoc}`;
export const GetOwnedTokensByTokenData = `
query getOwnedTokensByTokenData($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_token_ownerships_v2_order_by!]) {
current_token_ownerships_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
...CurrentTokenOwnershipFields
}
}
${CurrentTokenOwnershipFieldsFragmentDoc}`;
export const GetTokenActivities = `
query getTokenActivities($idHash: String!, $offset: Int, $limit: Int) {
token_activities(
where: {token_data_id_hash: {_eq: $idHash}}
order_by: {transaction_version: desc}
query getTokenActivities($where_condition: token_activities_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [token_activities_v2_order_by!]) {
token_activities_v2(
where: $where_condition
order_by: $order_by
offset: $offset
limit: $limit
) {
creator_address
collection_name
name
token_data_id_hash
collection_data_id_hash
after_value
before_value
entry_function_id_str
event_account_address
event_index
from_address
is_fungible_v2
property_version_v1
to_address
transaction_version
transaction_timestamp
property_version
transfer_type
event_sequence_number
token_amount
token_data_id
token_standard
transaction_timestamp
transaction_version
type
}
}
`;
export const GetTokenActivitiesCount = `
query getTokenActivitiesCount($token_id: String) {
token_activities_aggregate(where: {token_data_id_hash: {_eq: $token_id}}) {
token_activities_v2_aggregate(where: {token_data_id: {_eq: $token_id}}) {
aggregate {
count
}
}
}
`;
export const GetTokenCurrentOwnerData = `
query getTokenCurrentOwnerData($where_condition: current_token_ownerships_v2_bool_exp!) {
current_token_ownerships_v2(where: $where_condition) {
query getTokenCurrentOwnerData($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_token_ownerships_v2_order_by!]) {
current_token_ownerships_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
owner_address
}
}
`;
export const GetTokenData = `
query getTokenData($where_condition: current_token_datas_v2_bool_exp) {
current_token_datas_v2(where: $where_condition) {
query getTokenData($where_condition: current_token_datas_v2_bool_exp, $offset: Int, $limit: Int, $order_by: [current_token_datas_v2_order_by!]) {
current_token_datas_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
token_data_id
token_name
token_uri
Expand All @@ -281,19 +313,25 @@ export const GetTokenData = `
}
`;
export const GetTokenOwnedFromCollection = `
query getTokenOwnedFromCollection($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int) {
query getTokenOwnedFromCollection($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_token_ownerships_v2_order_by!]) {
current_token_ownerships_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
...CurrentTokenOwnershipFields
}
}
${CurrentTokenOwnershipFieldsFragmentDoc}`;
export const GetTokenOwnersData = `
query getTokenOwnersData($where_condition: current_token_ownerships_v2_bool_exp!) {
current_token_ownerships_v2(where: $where_condition) {
query getTokenOwnersData($where_condition: current_token_ownerships_v2_bool_exp!, $offset: Int, $limit: Int, $order_by: [current_token_ownerships_v2_order_by!]) {
current_token_ownerships_v2(
where: $where_condition
offset: $offset
limit: $limit
order_by: $order_by
) {
owner_address
}
}
Expand Down Expand Up @@ -358,6 +396,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getOwnedTokens(variables: Types.GetOwnedTokensQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetOwnedTokensQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetOwnedTokensQuery>(GetOwnedTokens, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getOwnedTokens', 'query');
},
getOwnedTokensByTokenData(variables: Types.GetOwnedTokensByTokenDataQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetOwnedTokensByTokenDataQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetOwnedTokensByTokenDataQuery>(GetOwnedTokensByTokenData, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getOwnedTokensByTokenData', 'query');
},
getTokenActivities(variables: Types.GetTokenActivitiesQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<Types.GetTokenActivitiesQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<Types.GetTokenActivitiesQuery>(GetTokenActivities, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getTokenActivities', 'query');
},
Expand Down
Loading

0 comments on commit f0de1b3

Please sign in to comment.