From ec64c452d590fd0b9cdd2a831c49c3c8e8b41930 Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Wed, 12 Jun 2024 16:34:41 +0200 Subject: [PATCH] fix(graph): metadata queries --- sdk/migrationV1_V2.md | 7 + sdk/package.json | 2 +- sdk/src/__generated__/gql/gql.ts | 14 +- sdk/src/__generated__/gql/graphql.ts | 348 ++++++++++++++++++++-- sdk/src/indexer.ts | 22 ++ sdk/src/indexer/queries/fractions.graphql | 2 +- sdk/src/indexer/queries/metadata.graphql | 53 ++++ sdk/src/types/indexer.ts | 8 + 8 files changed, 434 insertions(+), 22 deletions(-) create mode 100644 sdk/src/indexer/queries/metadata.graphql diff --git a/sdk/migrationV1_V2.md b/sdk/migrationV1_V2.md index f4f83a19..233c2dbe 100644 --- a/sdk/migrationV1_V2.md +++ b/sdk/migrationV1_V2.md @@ -18,6 +18,8 @@ FractionsByOwner, RecentHypercerts, FractionById, + MetadataByUri, + MetadataForHypercert ``` - When using VSCode we recommend using [gql.tada](https://github.com/0no-co/gql.tada) for syntax highlighting and other @@ -27,3 +29,8 @@ - `getData` - `getMetadata` -> in favor of using the Graph + +# Nerd stuff + +- GraphQL client autogenerated from the graph schema. +- API client autogenerated from the graph schema. diff --git a/sdk/package.json b/sdk/package.json index db960379..7dd2bb49 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hypercerts-org/sdk", - "version": "2.0.0-alpha.16", + "version": "2.0.0-alpha.17", "description": "SDK for hypercerts protocol", "repository": "git@github.com:hypercerts-org/hypercerts.git", "author": "Hypercerts team", diff --git a/sdk/src/__generated__/gql/gql.ts b/sdk/src/__generated__/gql/gql.ts index c17034d9..009b9330 100644 --- a/sdk/src/__generated__/gql/gql.ts +++ b/sdk/src/__generated__/gql/gql.ts @@ -13,10 +13,12 @@ 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}\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}': + '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: String!) {\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: {block_number: $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, + 'query MetadataByUri($uri: String = "", $first: Int = 100, $offset: Int = 0) {\n metadata(where: {uri: {eq: $uri}}, first: $first, offset: $offset, count: COUNT) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}\n\nquery MetadataForHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n metadata(\n where: {hypercerts: {hypercert_id: {eq: $hypercertId}}}\n first: $first\n offset: $offset\n count: COUNT\n ) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}': + types.MetadataByUriDocument, }; /** @@ -37,14 +39,20 @@ 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}\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}']; + 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: String!) {\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: String!) {\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. */ export function graphql( source: '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: {block_number: $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}', ): (typeof documents)['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: {block_number: $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}']; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql( + source: 'query MetadataByUri($uri: String = "", $first: Int = 100, $offset: Int = 0) {\n metadata(where: {uri: {eq: $uri}}, first: $first, offset: $offset, count: COUNT) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}\n\nquery MetadataForHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n metadata(\n where: {hypercerts: {hypercert_id: {eq: $hypercertId}}}\n first: $first\n offset: $offset\n count: COUNT\n ) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}', +): (typeof documents)['query MetadataByUri($uri: String = "", $first: Int = 100, $offset: Int = 0) {\n metadata(where: {uri: {eq: $uri}}, first: $first, offset: $offset, count: COUNT) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}\n\nquery MetadataForHypercert($hypercertId: String!, $orderDirection: SortOrder = descending, $first: Int = 100, $offset: Int = 0) {\n metadata(\n where: {hypercerts: {hypercert_id: {eq: $hypercertId}}}\n first: $first\n offset: $offset\n count: COUNT\n ) {\n data {\n allow_list_uri\n contributors\n description\n external_url\n image\n impact_scope\n impact_timeframe_from\n impact_timeframe_to\n name\n properties\n rights\n uri\n work_scope\n work_timeframe_from\n work_timeframe_to\n }\n }\n}']; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/sdk/src/__generated__/gql/graphql.ts b/sdk/src/__generated__/gql/graphql.ts index a76dc323..60483f5d 100644 --- a/sdk/src/__generated__/gql/graphql.ts +++ b/sdk/src/__generated__/gql/graphql.ts @@ -20,6 +20,8 @@ export type Scalars = { EthBigInt: { input: any; output: any }; /** The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf). */ JSON: { input: any; output: any }; + /** A field whose value is a generic Universally Unique Identifier: https://en.wikipedia.org/wiki/Universally_unique_identifier. */ + UUID: { input: any; output: any }; }; export type Attestation = { @@ -43,12 +45,12 @@ export type AttestationFetchInput = { export type AttestationSchema = { __typename?: "AttestationSchema"; chain_id?: Maybe; - eas_schema_id?: Maybe; id: Scalars["ID"]["output"]; records?: Maybe>; resolver?: Maybe; revocable?: Maybe; schema?: Maybe; + uid?: Maybe; }; export type AttestationSchemaFetchInput = { @@ -65,11 +67,11 @@ export type AttestationSchemaSortOptions = { export type AttestationSchemaWhereInput = { attestations?: InputMaybe; chain_id?: InputMaybe; - eas_schema_id?: InputMaybe; id?: InputMaybe; resolver?: InputMaybe; revocable?: InputMaybe; schema?: InputMaybe; + uid?: InputMaybe; }; export type AttestationSortOptions = { @@ -100,11 +102,11 @@ export type AttestationWhereInput = { export type BasicAttestationSchemaWhereInput = { chain_id?: InputMaybe; - eas_schema_id?: InputMaybe; id?: InputMaybe; resolver?: InputMaybe; revocable?: InputMaybe; schema?: InputMaybe; + uid?: InputMaybe; }; export type BasicAttestationWhereInput = { @@ -130,7 +132,8 @@ export type BasicContractWhereInput = { export type BasicFractionWhereInput = { creation_block_timestamp?: InputMaybe; - hypercert_id?: InputMaybe; + hypercert_id?: InputMaybe; + id?: InputMaybe; last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; @@ -139,6 +142,7 @@ export type BasicFractionWhereInput = { export type BasicHypercertWhereInput = { block_number?: InputMaybe; + creator_address?: InputMaybe; hypercert_id?: InputMaybe; id?: InputMaybe; owner_address?: InputMaybe; @@ -150,6 +154,7 @@ export type BasicMetadataWhereInput = { contributors?: InputMaybe; creation_block_timestamp?: InputMaybe; description?: InputMaybe; + id?: InputMaybe; impact_scope?: InputMaybe; impact_timeframe_from?: InputMaybe; impact_timeframe_to?: InputMaybe; @@ -199,10 +204,12 @@ export enum CountKeys { export type Fraction = { __typename?: "Fraction"; + claims_id?: Maybe; creation_block_timestamp?: Maybe; hypercert_id?: Maybe; id: Scalars["ID"]["output"]; last_block_update_timestamp?: Maybe; + metadata?: Maybe; orders?: Maybe; owner_address?: Maybe; units?: Maybe; @@ -222,8 +229,9 @@ export type FractionSortOptions = { export type FractionWhereInput = { creation_block_timestamp?: InputMaybe; - hypercert_id?: InputMaybe; + hypercert_id?: InputMaybe; hypercerts?: InputMaybe; + id?: InputMaybe; last_block_update_timestamp?: InputMaybe; owner_address?: InputMaybe; token_id?: InputMaybe; @@ -260,6 +268,12 @@ export type GetHypercertsResponse = { data?: Maybe>; }; +export type GetMetadataResponse = { + __typename?: "GetMetadataResponse"; + count?: Maybe; + data?: Maybe>; +}; + export type GetOrdersResponse = { __typename?: "GetOrdersResponse"; count?: Maybe; @@ -272,6 +286,7 @@ export type Hypercert = { block_number?: Maybe; contract?: Maybe; contracts_id?: Maybe; + creator_address?: Maybe; fractions?: Maybe; hypercert_id?: Maybe; id: Scalars["ID"]["output"]; @@ -303,6 +318,7 @@ export type HypercertsWhereInput = { attestations?: InputMaybe; block_number?: InputMaybe; contract?: InputMaybe; + creator_address?: InputMaybe; fractions?: InputMaybe; hypercert_id?: InputMaybe; id?: InputMaybe; @@ -313,10 +329,7 @@ export type HypercertsWhereInput = { }; export type IdSearchOptions = { - contains?: InputMaybe; - endsWith?: InputMaybe; - eq?: InputMaybe; - startsWith?: InputMaybe; + eq?: InputMaybe; }; export type Metadata = { @@ -353,13 +366,21 @@ export type MetadataSortOptions = { }; export type MetadataWhereInput = { - block_number?: InputMaybe; - hypercert_id?: InputMaybe; + contributors?: InputMaybe; + creation_block_timestamp?: InputMaybe; + description?: InputMaybe; + hypercerts?: InputMaybe; id?: InputMaybe; - metadata?: InputMaybe; - owner_address?: InputMaybe; - token_id?: InputMaybe; + impact_scope?: InputMaybe; + impact_timeframe_from?: InputMaybe; + impact_timeframe_to?: InputMaybe; + last_block_update_timestamp?: InputMaybe; + name?: InputMaybe; + rights?: InputMaybe; uri?: InputMaybe; + work_scope?: InputMaybe; + work_timeframe_from?: InputMaybe; + work_timeframe_to?: InputMaybe; }; export type NumberSearchOptions = { @@ -404,7 +425,7 @@ export type Query = { contracts: GetContractsResponse; fractions: GetFractionsResponse; hypercerts: GetHypercertsResponse; - metadata: Array; + metadata: GetMetadataResponse; orders: GetOrdersResponse; }; @@ -539,7 +560,7 @@ export type FractionsByHypercertQuery = { }; export type FractionByIdQueryVariables = Exact<{ - fractionId: Scalars["ID"]["input"]; + fractionId: Scalars["String"]["input"]; }>; export type FractionByIdQuery = { @@ -622,6 +643,69 @@ export type HypercertByIdQuery = { }; }; +export type MetadataByUriQueryVariables = Exact<{ + uri?: InputMaybe; + first?: InputMaybe; + offset?: InputMaybe; +}>; + +export type MetadataByUriQuery = { + __typename?: "Query"; + metadata: { + __typename?: "GetMetadataResponse"; + data?: Array<{ + __typename?: "Metadata"; + allow_list_uri?: string | null; + contributors?: Array | null; + description?: string | null; + external_url?: string | null; + image?: string | null; + impact_scope?: Array | null; + impact_timeframe_from?: any | null; + impact_timeframe_to?: any | null; + name?: string | null; + properties?: any | null; + rights?: Array | null; + uri?: string | null; + work_scope?: Array | null; + work_timeframe_from?: any | null; + work_timeframe_to?: any | null; + }> | null; + }; +}; + +export type MetadataForHypercertQueryVariables = Exact<{ + hypercertId: Scalars["String"]["input"]; + orderDirection?: InputMaybe; + first?: InputMaybe; + offset?: InputMaybe; +}>; + +export type MetadataForHypercertQuery = { + __typename?: "Query"; + metadata: { + __typename?: "GetMetadataResponse"; + data?: Array<{ + __typename?: "Metadata"; + allow_list_uri?: string | null; + contributors?: Array | null; + description?: string | null; + external_url?: string | null; + image?: string | null; + impact_scope?: Array | null; + impact_timeframe_from?: any | null; + impact_timeframe_to?: any | null; + name?: string | null; + properties?: any | null; + rights?: Array | null; + uri?: string | null; + work_scope?: Array | null; + work_timeframe_from?: any | null; + work_timeframe_to?: any | null; + }> | null; + }; +}; + export const FractionsByOwnerDocument = { kind: "Document", definitions: [ @@ -881,7 +965,7 @@ export const FractionByIdDocument = { { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "fractionId" } }, - type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, + type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, }, ], selectionSet: { @@ -1264,3 +1348,233 @@ export const HypercertByIdDocument = { }, ], } as unknown as DocumentNode; +export const MetadataByUriDocument = { + kind: "Document", + definitions: [ + { + kind: "OperationDefinition", + operation: "query", + name: { kind: "Name", value: "MetadataByUri" }, + variableDefinitions: [ + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "uri" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "String" } }, + defaultValue: { kind: "StringValue", value: "", block: false }, + }, + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "first" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }, + defaultValue: { kind: "IntValue", value: "100" }, + }, + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "offset" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }, + defaultValue: { kind: "IntValue", value: "0" }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "metadata" }, + arguments: [ + { + kind: "Argument", + name: { kind: "Name", value: "where" }, + value: { + kind: "ObjectValue", + fields: [ + { + kind: "ObjectField", + name: { kind: "Name", value: "uri" }, + value: { + kind: "ObjectValue", + fields: [ + { + kind: "ObjectField", + name: { kind: "Name", value: "eq" }, + value: { kind: "Variable", name: { kind: "Name", value: "uri" } }, + }, + ], + }, + }, + ], + }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "first" }, + value: { kind: "Variable", name: { kind: "Name", value: "first" } }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "offset" }, + value: { kind: "Variable", name: { kind: "Name", value: "offset" } }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "count" }, + value: { kind: "EnumValue", value: "COUNT" }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "data" }, + selectionSet: { + kind: "SelectionSet", + selections: [ + { kind: "Field", name: { kind: "Name", value: "allow_list_uri" } }, + { kind: "Field", name: { kind: "Name", value: "contributors" } }, + { kind: "Field", name: { kind: "Name", value: "description" } }, + { kind: "Field", name: { kind: "Name", value: "external_url" } }, + { kind: "Field", name: { kind: "Name", value: "image" } }, + { kind: "Field", name: { kind: "Name", value: "impact_scope" } }, + { kind: "Field", name: { kind: "Name", value: "impact_timeframe_from" } }, + { kind: "Field", name: { kind: "Name", value: "impact_timeframe_to" } }, + { kind: "Field", name: { kind: "Name", value: "name" } }, + { kind: "Field", name: { kind: "Name", value: "properties" } }, + { kind: "Field", name: { kind: "Name", value: "rights" } }, + { kind: "Field", name: { kind: "Name", value: "uri" } }, + { kind: "Field", name: { kind: "Name", value: "work_scope" } }, + { kind: "Field", name: { kind: "Name", value: "work_timeframe_from" } }, + { kind: "Field", name: { kind: "Name", value: "work_timeframe_to" } }, + ], + }, + }, + ], + }, + }, + ], + }, + }, + ], +} as unknown as DocumentNode; +export const MetadataForHypercertDocument = { + kind: "Document", + definitions: [ + { + kind: "OperationDefinition", + operation: "query", + name: { kind: "Name", value: "MetadataForHypercert" }, + variableDefinitions: [ + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "hypercertId" } }, + type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, + }, + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "orderDirection" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "SortOrder" } }, + defaultValue: { kind: "EnumValue", value: "descending" }, + }, + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "first" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }, + defaultValue: { kind: "IntValue", value: "100" }, + }, + { + kind: "VariableDefinition", + variable: { kind: "Variable", name: { kind: "Name", value: "offset" } }, + type: { kind: "NamedType", name: { kind: "Name", value: "Int" } }, + defaultValue: { kind: "IntValue", value: "0" }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "metadata" }, + arguments: [ + { + kind: "Argument", + name: { kind: "Name", value: "where" }, + value: { + kind: "ObjectValue", + fields: [ + { + kind: "ObjectField", + name: { kind: "Name", value: "hypercerts" }, + 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: "hypercertId" } }, + }, + ], + }, + }, + ], + }, + }, + ], + }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "first" }, + value: { kind: "Variable", name: { kind: "Name", value: "first" } }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "offset" }, + value: { kind: "Variable", name: { kind: "Name", value: "offset" } }, + }, + { + kind: "Argument", + name: { kind: "Name", value: "count" }, + value: { kind: "EnumValue", value: "COUNT" }, + }, + ], + selectionSet: { + kind: "SelectionSet", + selections: [ + { + kind: "Field", + name: { kind: "Name", value: "data" }, + selectionSet: { + kind: "SelectionSet", + selections: [ + { kind: "Field", name: { kind: "Name", value: "allow_list_uri" } }, + { kind: "Field", name: { kind: "Name", value: "contributors" } }, + { kind: "Field", name: { kind: "Name", value: "description" } }, + { kind: "Field", name: { kind: "Name", value: "external_url" } }, + { kind: "Field", name: { kind: "Name", value: "image" } }, + { kind: "Field", name: { kind: "Name", value: "impact_scope" } }, + { kind: "Field", name: { kind: "Name", value: "impact_timeframe_from" } }, + { kind: "Field", name: { kind: "Name", value: "impact_timeframe_to" } }, + { kind: "Field", name: { kind: "Name", value: "name" } }, + { kind: "Field", name: { kind: "Name", value: "properties" } }, + { kind: "Field", name: { kind: "Name", value: "rights" } }, + { kind: "Field", name: { kind: "Name", value: "uri" } }, + { kind: "Field", name: { kind: "Name", value: "work_scope" } }, + { kind: "Field", name: { kind: "Name", value: "work_timeframe_from" } }, + { kind: "Field", name: { kind: "Name", value: "work_timeframe_to" } }, + ], + }, + }, + ], + }, + }, + ], + }, + }, + ], +} as unknown as DocumentNode; diff --git a/sdk/src/indexer.ts b/sdk/src/indexer.ts index 4e157083..cb3aab41 100644 --- a/sdk/src/indexer.ts +++ b/sdk/src/indexer.ts @@ -15,6 +15,10 @@ import { RecentHypercertsQueryVariables, FractionByIdDocument, FractionByIdQueryVariables, + MetadataByUriDocument, + MetadataByUriQueryVariables, + MetadataForHypercertDocument, + MetadataForHypercertQueryVariables, } from "./__generated__/gql/graphql"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { DocumentNode } from "graphql"; @@ -126,6 +130,24 @@ export class HypercertIndexer implements HypercertIndexerInterface { return await this.performQuery(FractionByIdDocument, variables); }; + /** + * Gets the metadata for a given URI. + * @param uri The URI of the metadata. + * @returns A Promise that resolves to the metadata. + */ + metadataByUri = async (variables: MetadataByUriQueryVariables) => { + return await this.performQuery(MetadataByUriDocument, variables); + }; + + /** + * Gets the metadata for a given hypercert. + * @param hypercertId The ID of the hypercert. + * @returns A Promise that resolves to the metadata. + */ + metadataForHypercert = async (variables: MetadataForHypercertQueryVariables) => { + return await this.performQuery(MetadataForHypercertDocument, variables); + }; + /** * Gets the most recent claims. * @param params The query parameters. diff --git a/sdk/src/indexer/queries/fractions.graphql b/sdk/src/indexer/queries/fractions.graphql index 72bd746a..82cf70b9 100644 --- a/sdk/src/indexer/queries/fractions.graphql +++ b/sdk/src/indexer/queries/fractions.graphql @@ -43,7 +43,7 @@ query FractionsByHypercert( } } -query FractionById($fractionId: ID!) { +query FractionById($fractionId: String!) { fractions(where: { hypercert_id: { eq: $fractionId } }) { data { creation_block_timestamp diff --git a/sdk/src/indexer/queries/metadata.graphql b/sdk/src/indexer/queries/metadata.graphql new file mode 100644 index 00000000..3ec1ba63 --- /dev/null +++ b/sdk/src/indexer/queries/metadata.graphql @@ -0,0 +1,53 @@ +query MetadataByUri($uri: String = "", $first: Int = 100, $offset: Int = 0) { + metadata(where: {uri: {eq: $uri}}, first: $first, offset: $offset, count: COUNT) { + data { + allow_list_uri + contributors + description + external_url + image + impact_scope + impact_timeframe_from + impact_timeframe_to + name + properties + rights + uri + work_scope + work_timeframe_from + work_timeframe_to + } + } +} + +query MetadataForHypercert( + $hypercertId: String! + $orderDirection: SortOrder = descending + $first: Int = 100 + $offset: Int = 0 +) { + metadata( + where: {hypercerts: {hypercert_id: {eq: $hypercertId}}} + first: $first + offset: $offset + count: COUNT + ) { + data { + allow_list_uri + contributors + description + external_url + image + impact_scope + impact_timeframe_from + impact_timeframe_to + name + properties + rights + uri + work_scope + work_timeframe_from + work_timeframe_to + } + } +} diff --git a/sdk/src/types/indexer.ts b/sdk/src/types/indexer.ts index 3ba7a7c1..a5dfd424 100644 --- a/sdk/src/types/indexer.ts +++ b/sdk/src/types/indexer.ts @@ -12,6 +12,10 @@ import { FractionsByHypercertQueryVariables, FractionByIdQueryVariables, FractionByIdQuery, + MetadataByUriQuery, + MetadataByUriQueryVariables, + MetadataForHypercertQuery, + MetadataForHypercertQueryVariables, } from "../__generated__/gql/graphql"; export interface HypercertIndexerInterface { @@ -24,4 +28,8 @@ export interface HypercertIndexerInterface { fractionsByHypercert: ( variables: FractionsByHypercertQueryVariables, ) => Promise; + metadataByUri: (variables: MetadataByUriQueryVariables) => Promise; + metadataForHypercert: ( + variables: MetadataForHypercertQueryVariables, + ) => Promise; }