From dad968a6a120034cd3033b4b2cdf396f52ddb457 Mon Sep 17 00:00:00 2001 From: jipstavenuiter Date: Mon, 3 Jun 2024 19:40:18 +0200 Subject: [PATCH] (feat): add query fraction by id helper --- sdk/package.json | 2 +- sdk/src/indexer.ts | 11 +++ sdk/src/indexer/gql/gql.ts | 6 +- sdk/src/indexer/gql/graphql.ts | 91 +++++++++++++++++++++++ sdk/src/indexer/queries/fractions.graphql | 31 +++++--- sdk/src/types/indexer.ts | 3 + 6 files changed, 130 insertions(+), 14 deletions(-) diff --git a/sdk/package.json b/sdk/package.json index f65b7f9f..7395ab19 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hypercerts-org/sdk", - "version": "2.0.0-alpha.10", + "version": "2.0.0-alpha.11", "description": "SDK for hypercerts protocol", "repository": "git@github.com:hypercerts-org/hypercerts.git", "author": "Hypercerts team", diff --git a/sdk/src/indexer.ts b/sdk/src/indexer.ts index 5afce31a..ea551834 100644 --- a/sdk/src/indexer.ts +++ b/sdk/src/indexer.ts @@ -13,6 +13,8 @@ import { FractionsByOwnerQueryVariables, RecentHypercertsDocument, RecentHypercertsQueryVariables, + FractionByIdDocument, + FractionByIdQueryVariables, } from "./indexer/gql/graphql"; import { DEPLOYMENTS, GRAPHS } from "./constants"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; @@ -140,6 +142,15 @@ export class HypercertIndexer implements HypercertIndexerInterface { return await this.performQuery(FractionsByHypercertDocument, variables); }; + /** + * Gets the fraction by its ID. + * @param $fractionId The ID of the fraction. + * @returns A Promise that resolves to the fraction. + */ + fractionById = async (variables: FractionByIdQueryVariables) => { + return await this.performQuery(FractionByIdDocument, variables); + }; + /** * Gets the most recent claims. * @param params The query parameters. diff --git a/sdk/src/indexer/gql/gql.ts b/sdk/src/indexer/gql/gql.ts index e37b7a25..8a8a626a 100644 --- a/sdk/src/indexer/gql/gql.ts +++ b/sdk/src/indexer/gql/gql.ts @@ -13,7 +13,7 @@ import { TypedDocumentNode as DocumentNode } from "@graphql-typed-document-node/ * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - 'query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}': + 'query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}\n\nquery FractionById($fractionId: ID!) {\n fractions(where: {hypercert_id: {eq: $fractionId}}) {\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}': types.FractionsByOwnerDocument, 'query HypercertsByOwner($owner: String = "", $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $owner}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery RecentHypercerts($orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n first: $first\n offset: $offset\n sort: {by: {creation_block_timestamp: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}\n\nquery HypercertById($id: String!) {\n hypercerts(count: COUNT, where: {hypercert_id: {eq: $id}}) {\n count\n data {\n hypercert_id\n owner_address\n units\n uri\n contract {\n chain_id\n }\n }\n }\n}': types.HypercertsByOwnerDocument, @@ -37,8 +37,8 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: 'query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}', -): (typeof documents)['query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}']; + source: 'query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}\n\nquery FractionById($fractionId: ID!) {\n fractions(where: {hypercert_id: {eq: $fractionId}}) {\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}', +): (typeof documents)['query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) {\n fractions(\n where: {owner_address: {eq: $owner}}\n count: COUNT\n first: $first\n offset: $offset\n ) {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}\n\nquery FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n hypercerts(\n count: COUNT\n where: {owner_address: {eq: $hypercertId}}\n first: $first\n offset: $offset\n sort: {by: {hypercert_id: $orderDirection}}\n ) {\n count\n data {\n hypercert_id\n units\n uri\n fractions {\n count\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n }\n }\n}\n\nquery FractionById($fractionId: ID!) {\n fractions(where: {hypercert_id: {eq: $fractionId}}) {\n data {\n creation_block_timestamp\n hypercert_id\n last_block_update_timestamp\n owner_address\n units\n }\n }\n}']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/sdk/src/indexer/gql/graphql.ts b/sdk/src/indexer/gql/graphql.ts index 5d1db926..53b323b6 100644 --- a/sdk/src/indexer/gql/graphql.ts +++ b/sdk/src/indexer/gql/graphql.ts @@ -130,6 +130,7 @@ export type BasicContractWhereInput = { export type BasicFractionWhereInput = { creation_block_timestamp?: InputMaybe; + hypercert_id?: InputMaybe; last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; @@ -216,6 +217,7 @@ export type FractionSortOptions = { export type FractionWhereInput = { creation_block_timestamp?: InputMaybe; + hypercert_id?: InputMaybe; hypercerts?: InputMaybe; last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; @@ -490,6 +492,25 @@ export type FractionsByHypercertQuery = { }; }; +export type FractionByIdQueryVariables = Exact<{ + fractionId: Scalars["ID"]["input"]; +}>; + +export type FractionByIdQuery = { + __typename?: "Query"; + fractions: { + __typename?: "GetFractionsResponse"; + data?: Array<{ + __typename?: "Fraction"; + creation_block_timestamp?: any | null; + hypercert_id?: string | null; + last_block_update_timestamp?: any | null; + owner_address?: string | null; + units?: any | null; + }> | null; + }; +}; + export type HypercertsByOwnerQueryVariables = Exact<{ owner?: InputMaybe; orderDirection?: InputMaybe; @@ -803,6 +824,76 @@ export const FractionsByHypercertDocument = { }, ], } as unknown as DocumentNode; +export const FractionByIdDocument = { + kind: "Document", + definitions: [ + { + kind: "OperationDefinition", + operation: "query", + name: { kind: "Name", value: "FractionById" }, + variableDefinitions: [ + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "fractionId" } }, + type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "fractions" }, + arguments: [ + { + kind: "Argument", + name: { kind: "Name", value: "where" }, + value: { + kind: "ObjectValue", + fields: [ + { + kind: "ObjectField", + name: { kind: "Name", value: "hypercert_id" }, + value: { + kind: "ObjectValue", + fields: [ + { + kind: "ObjectField", + name: { kind: "Name", value: "eq" }, + value: { kind: "Variable", name: { kind: "Name", value: "fractionId" } }, + }, + ], + }, + }, + ], + }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "data" }, + selectionSet: { + kind: "SelectionSet", + selections: [ + { kind: "Field", name: { kind: "Name", value: "creation_block_timestamp" } }, + { kind: "Field", name: { kind: "Name", value: "hypercert_id" } }, + { kind: "Field", name: { kind: "Name", value: "last_block_update_timestamp" } }, + { kind: "Field", name: { kind: "Name", value: "owner_address" } }, + { kind: "Field", name: { kind: "Name", value: "units" } }, + ], + }, + }, + ], + }, + }, + ], + }, + }, + ], +} as unknown as DocumentNode; export const HypercertsByOwnerDocument = { kind: "Document", definitions: [ diff --git a/sdk/src/indexer/queries/fractions.graphql b/sdk/src/indexer/queries/fractions.graphql index c3b8cb66..72bd746a 100644 --- a/sdk/src/indexer/queries/fractions.graphql +++ b/sdk/src/indexer/queries/fractions.graphql @@ -1,10 +1,5 @@ query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) { - fractions( - where: {owner_address: {eq: $owner}} - count: COUNT - first: $first - offset: $offset - ) { + fractions(where: { owner_address: { eq: $owner } }, count: COUNT, first: $first, offset: $offset) { count data { creation_block_timestamp @@ -16,13 +11,18 @@ query FractionsByOwner($owner: String = "", $first: Int = 100, $offset: Int = 0) } } -query FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) { - hypercerts( +query FractionsByHypercert( + $hypercertId: String! + $orderDirection: SortOrder = descending + $first: Int = 100 + $offset: Int = 0 +) { + hypercerts( count: COUNT - where: {owner_address: {eq: $hypercertId}} + where: { owner_address: { eq: $hypercertId } } first: $first offset: $offset - sort: {by: {hypercert_id: $orderDirection}} + sort: { by: { hypercert_id: $orderDirection } } ) { count data { @@ -43,3 +43,14 @@ query FractionsByHypercert($hypercertId: String!, $orderDirection: SortOrder = d } } +query FractionById($fractionId: ID!) { + fractions(where: { hypercert_id: { eq: $fractionId } }) { + data { + creation_block_timestamp + hypercert_id + last_block_update_timestamp + owner_address + units + } + } +} diff --git a/sdk/src/types/indexer.ts b/sdk/src/types/indexer.ts index 945da393..16d5fbcb 100644 --- a/sdk/src/types/indexer.ts +++ b/sdk/src/types/indexer.ts @@ -10,6 +10,8 @@ import { FractionsByOwnerQueryVariables, FractionsByHypercertQuery, FractionsByHypercertQueryVariables, + FractionByIdQueryVariables, + FractionByIdQuery, } from "../indexer/gql/graphql"; export interface HypercertIndexerInterface { @@ -18,6 +20,7 @@ export interface HypercertIndexerInterface { hypercertById: (variables: HypercertByIdQueryVariables) => Promise; recentHypercerts: (variables: RecentHypercertsQueryVariables) => Promise; fractionsByOwner: (variables: FractionsByOwnerQueryVariables) => Promise; + fractionById: (variables: FractionByIdQueryVariables) => Promise; fractionsByHypercert: ( variables: FractionsByHypercertQueryVariables, ) => Promise;