diff --git a/schema.graphql b/schema.graphql index dbf194ca..0e8e9c7e 100644 --- a/schema.graphql +++ b/schema.graphql @@ -243,20 +243,8 @@ type GraphAccount @entity { "Default display name is the current default name. Used for filtered queries in the explorer" defaultDisplayName: String - # IPFS Metadata. Duplicated for backwards compatibility + # IPFS Metadata. metadata: GraphAccountMetadata - "True if it is an organization. False if it is an individual" - isOrganization: Boolean - "Main repository of code for the graph account" - codeRepository: String - "Description of the graph account" - description: String - "Image URL" - image: String - "Website URL" - website: String - "Display name. Not unique" - displayName: String # Operator info "Operator of other Graph Accounts" @@ -309,11 +297,11 @@ type GraphAccount @entity { tokenLockWallets: [TokenLockWallet!]! } -type GraphAccountMetadata @entity { +type GraphAccountMetadata @entity(immutable:true) { "IPFS hash with account metadata details" id: ID! "Original graph account that created it" - graphAccount: GraphAccount! + graphAccount: [GraphAccount!] @derivedFrom(field:"metadata") "True if it is an organization. False if it is an individual" isOrganization: Boolean "Main repository of code for the graph account" @@ -439,35 +427,21 @@ type Subgraph @entity { "Total amount of NameSignal entities" nameSignalCount: Int! - # Metadata from IPFS linked in GNS. For backwards compatibility we duplicate it + # Metadata from IPFS linked in GNS "Subgraph metadata" metadataHash: Bytes "Subgraph metadata ipfs hash and entity" metadata: SubgraphMetadata - "Short description of the subgraph" - description: String - "Image in string format" - image: String - "NFT Image representation" - nftImage: String - "Location of the code for this project" - codeRepository: String - "Projects website" - website: String - "Display name" - displayName: String - "Categories that the subgraph belongs to. Modelled with a relation to allow for many-to-many relationship querying" - categories: [SubgraphCategoryRelation!]! @derivedFrom(field: "subgraph") # Auxiliary fields currentVersionRelationEntity: CurrentSubgraphDeploymentRelation } -type SubgraphMetadata @entity { +type SubgraphMetadata @entity(immutable:true) { "Subgraph metadata ipfs hash" id: ID! "Subgraph entity" - subgraph: Subgraph! + subgraph: Subgraph @derivedFrom(field:"metadata") "Short description of the subgraph" description: String "Image in string format" @@ -480,7 +454,8 @@ type SubgraphMetadata @entity { website: String "Display name" displayName: String - #maybe add categories here too? + "Categories that the subgraph belongs to." + categories: [String!] } type CurrentSubgraphDeploymentRelation @entity { @@ -495,25 +470,6 @@ type CurrentSubgraphDeploymentRelation @entity { active: Boolean! } -type Network @entity { - id: ID! - - deployments: [SubgraphDeploymentManifest!]! @derivedFrom(field: "network") -} - -type SubgraphCategoryRelation @entity { - id: ID! - - subgraph: Subgraph! - - category: SubgraphCategory! -} - -type SubgraphCategory @entity { - id: ID! - - subgraphs: [SubgraphCategoryRelation!]! @derivedFrom(field: "category") -} """ The SubgraphVersion entity represents a version of the Subgraph. A new SubgraphVersion is created @@ -538,21 +494,17 @@ type SubgraphVersion @entity { metadataHash: Bytes # Metadata from IPFS linked in GNS metadata: SubgraphVersionMetadata - "Short description of the version" - description: String - "Semantic versioning label" - label: String entityVersion: Int! "[DEPRECATED] Used for duplicate entities to enable old IDs from before the subgraph NFT update" linkedEntity: SubgraphVersion } -type SubgraphVersionMetadata @entity { +type SubgraphVersionMetadata @entity(immutable:true) { "Subgraph version metadata ipfs hash" id: ID! "Subgraph version entity" - subgraphVersion: SubgraphVersion! + subgraphVersion: SubgraphVersion @derivedFrom(field:"metadata") "Short description of the version" description: String "Semantic versioning label" @@ -617,19 +569,11 @@ type SubgraphDeployment @entity { # From Subgraph Manifest # dataSources: [DataSource!] "Entity that represents the manifest of the deployment. Filled by File Data Sources" - manifestEntity: SubgraphDeploymentManifest - "Entity that represents the schema of the deployment. Filled by File Data Sources" - schemaEntity: SubgraphDeploymentSchema + manifest: SubgraphDeploymentManifest "Entity that represents the schema of the deployment. Filled by File Data Sources" + schema: SubgraphDeploymentSchema + "shcema ipfs hash string" schemaIpfsHash: String - "Contents of the Schema file" - schema: String - "Contents of the Manifest file" - manifest: String - "Network where the contracts that the subgraph indexes are located" - network: Network - "Whether the subgraph is a SpS/SbS. Null if we can't parse it" - poweredBySubstreams: Boolean # Counters for currentSignalledTokens tracking on Subgraph "Total amount of Subgraph entities that used this deployment at some point. subgraphCount >= activeSubgraphCount + deprecatedSubgraphCount" @@ -653,20 +597,24 @@ type SubgraphDeployment @entity { signalledTokensReceivedOnL2: BigInt! } -type SubgraphDeploymentSchema @entity { +type SubgraphDeploymentSchema @entity(immutable:true) { "IPFS Hash" id: ID! + "Link to SubgraphDeployment entity" + deployment: SubgraphDeployment @derivedFrom(field:"schema") "Contents of the Schema file" schema: String } -type SubgraphDeploymentManifest @entity { +type SubgraphDeploymentManifest @entity(immutable:true) { "IPFS Hash" id: ID! + "Link to SubgraphDeployment entity" + deployment: SubgraphDeployment @derivedFrom(field:"manifest") "Contents of the Manifest file" manifest: String "Network where the contracts that the subgraph indexes are located" - network: Network + network: String "Whether the subgraph is a SpS/SbS. Null if we can't parse it" poweredBySubstreams: Boolean } @@ -1489,10 +1437,10 @@ Full test search for displayName and description on the Subgraph Entity """ type _Schema_ @fulltext( - name: "subgraphSearch" + name: "subgraphMetadataSearch" language: en algorithm: rank - include: [{ entity: "Subgraph", fields: [{ name: "displayName" }, { name: "description" }] }] + include: [{ entity: "SubgraphMetadata", fields: [{ name: "displayName" }, { name: "description" }] }] ) @fulltext( name: "curatorSearch" diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index 3b54a4f0..b7536c06 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,7 +1,7 @@ import { Bytes } from '@graphprotocol/graph-ts' import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry' import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates' -import { GraphAccount, GraphAccountMetadata } from '../types/schema' +import { GraphAccount } from '../types/schema' import { addQm, createOrLoadGraphAccount } from './helpers/helpers' @@ -28,9 +28,6 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { tlw.save() } - let metadata = new GraphAccountMetadata(base58Hash) - metadata.graphAccount = graphAccount.id; - metadata.save() GraphAccountMetadataTemplate.create(base58Hash) } } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 6fdc0941..7f4dbdcb 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -40,7 +40,6 @@ import { GraphAccount, NameSignalSubgraphRelation, NameSignal, - SubgraphMetadata, } from '../types/schema' import { zeroBD } from './utils' @@ -185,9 +184,6 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let metadata = new SubgraphMetadata(base58Hash) - metadata.subgraph = subgraph.id; - metadata.save() SubgraphMetadataTemplate.create(base58Hash) } @@ -720,9 +716,6 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - let metadata = new SubgraphMetadata(base58Hash) - metadata.subgraph = subgraph.id; - metadata.save() SubgraphMetadataTemplate.create(base58Hash) } diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 16572d37..2ab443f9 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -22,9 +22,6 @@ import { NameSignal, Delegator, DelegatedStake, - Network, - SubgraphCategory, - SubgraphCategoryRelation, NameSignalSubgraphRelation, CurrentSubgraphDeploymentRelation, } from '../../types/schema' @@ -857,41 +854,41 @@ export function calculatePricePerShare(deployment: SubgraphDeployment): BigDecim return pricePerShare } -export function createOrLoadNetwork(id: string): Network { - let network = Network.load(id) - if (network == null) { - network = new Network(id) - - network.save() - } - return network as Network -} - -export function createOrLoadSubgraphCategory(id: string): SubgraphCategory { - let category = SubgraphCategory.load(id) - if (category == null) { - category = new SubgraphCategory(id) - - category.save() - } - return category as SubgraphCategory -} - -export function createOrLoadSubgraphCategoryRelation( - categoryId: string, - subgraphId: string, -): SubgraphCategoryRelation { - let id = joinID([categoryId, subgraphId]) - let relation = SubgraphCategoryRelation.load(id) - if (relation == null) { - relation = new SubgraphCategoryRelation(id) - relation.subgraph = subgraphId - relation.category = categoryId - - relation.save() - } - return relation as SubgraphCategoryRelation -} +// export function createOrLoadNetwork(id: string): Network { +// let network = Network.load(id) +// if (network == null) { +// network = new Network(id) + +// network.save() +// } +// return network as Network +// } + +// export function createOrLoadSubgraphCategory(id: string): SubgraphCategory { +// let category = SubgraphCategory.load(id) +// if (category == null) { +// category = new SubgraphCategory(id) + +// category.save() +// } +// return category as SubgraphCategory +// } + +// export function createOrLoadSubgraphCategoryRelation( +// categoryId: string, +// subgraphMetadataId: string, +// ): SubgraphCategoryRelation { +// let id = joinID([categoryId, subgraphMetadataId]) +// let relation = SubgraphCategoryRelation.load(id) +// if (relation == null) { +// relation = new SubgraphCategoryRelation(id) +// relation.metadata = subgraphMetadataId +// relation.category = categoryId + +// relation.save() +// } +// return relation as SubgraphCategoryRelation +// } export function updateCurrentDeploymentLinks( oldDeployment: SubgraphDeployment | null, @@ -952,7 +949,7 @@ export function convertBigIntSubgraphIDToBase58(bigIntRepresentation: BigInt): S // Although for the events where the uint256 is provided, we probably don't need to unpad. let hexString = bigIntRepresentation.toHexString() if (hexString.length % 2 != 0) { - log.error('Hex string not even, hex: {}, original: {}. Padding it to even length', [ + log.warning('Hex string not even, hex: {}, original: {}. Padding it to even length', [ hexString, bigIntRepresentation.toString(), ]) diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index d6460eae..b79fc315 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -5,55 +5,33 @@ import { GraphAccountMetadata, SubgraphDeploymentSchema, SubgraphDeploymentManifest, - Subgraph, - GraphAccount } from '../types/schema' import { jsonToString } from './utils' -import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation } from './helpers/helpers' export function handleSubgraphMetadata(content: Bytes): void { - let subgraphMetadata = SubgraphMetadata.load(dataSource.stringParam())! - let subgraph = Subgraph.load(subgraphMetadata.subgraph)! + let subgraphMetadata = new SubgraphMetadata(dataSource.stringParam()) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() - // Duplicating the fields for backwards compatibility subgraphMetadata.description = jsonToString(data.get('description')) subgraphMetadata.displayName = jsonToString(data.get('displayName')) subgraphMetadata.codeRepository = jsonToString(data.get('codeRepository')) subgraphMetadata.website = jsonToString(data.get('website')) - - subgraph.description = subgraphMetadata.description - subgraph.displayName = subgraphMetadata.displayName - subgraph.codeRepository = subgraphMetadata.codeRepository - subgraph.website = subgraphMetadata.website let categories = data.get('categories') if (categories != null && !categories.isNull()) { - let categoriesArray = categories.toArray() - - for (let i = 0; i < categoriesArray.length; i++) { - let categoryId = jsonToString(categoriesArray[i]) - createOrLoadSubgraphCategory(categoryId) - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.id) - if (subgraph.linkedEntity != null) { - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.linkedEntity!) - } - } + let categoriesArray = categories.toArray().map((element) => jsonToString(element)) + subgraphMetadata.categories = categoriesArray } let image = jsonToString(data.get('image')) let subgraphImage = data.get('subgraphImage') if (subgraphImage != null && subgraphImage.kind === JSONValueKind.STRING) { subgraphMetadata.nftImage = image subgraphMetadata.image = jsonToString(subgraphImage) - subgraph.nftImage = subgraphMetadata.nftImage - subgraph.image = subgraphMetadata.image } else { subgraphMetadata.image = image - subgraph.image = subgraphMetadata.image } subgraphMetadata.save() - subgraph.save() } } @@ -66,8 +44,7 @@ export function handleSubgraphVersionMetadata(content: Bytes): void { } export function handleGraphAccountMetadata(content: Bytes): void { - let graphAccountMetadata = GraphAccountMetadata.load(dataSource.stringParam())! - let graphAccount = GraphAccount.load(graphAccountMetadata.graphAccount)! + let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam()) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -75,20 +52,12 @@ export function handleGraphAccountMetadata(content: Bytes): void { graphAccountMetadata.description = jsonToString(data.get('description')) graphAccountMetadata.image = jsonToString(data.get('image')) graphAccountMetadata.displayName = jsonToString(data.get('displayName')) - graphAccount.codeRepository = graphAccountMetadata.codeRepository - graphAccount.description = graphAccountMetadata.description - graphAccount.image = graphAccountMetadata.image - graphAccount.displayName = graphAccountMetadata.displayName let isOrganization = data.get('isOrganization') if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) { graphAccountMetadata.isOrganization = isOrganization.toBool() - graphAccount.isOrganization = graphAccountMetadata.isOrganization } graphAccountMetadata.website = jsonToString(data.get('website')) - graphAccount.website = graphAccountMetadata.website - graphAccountMetadata.save() - graphAccount.save() } } diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 784c0137..cd87fa2f 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -704,7 +704,6 @@ templates: handler: handleSubgraphDeploymentManifest entities: - SubgraphDeploymentManifest - - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -717,7 +716,6 @@ templates: handler: handleSubgraphDeploymentSchema entities: - SubgraphDeploymentSchema - - SubgraphDeployment abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -730,7 +728,6 @@ templates: handler: handleSubgraphMetadata entities: - SubgraphMetadata - - Subgraph abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -743,7 +740,6 @@ templates: handler: handleSubgraphVersionMetadata entities: - SubgraphVersionMetadata - - SubgraphVersion abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json @@ -756,7 +752,6 @@ templates: handler: handleGraphAccountMetadata entities: - GraphAccountMetadata - - GraphAccount abis: - name: EpochManager file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json