diff --git a/schema.graphql b/schema.graphql index 3381a54..9059fba 100644 --- a/schema.graphql +++ b/schema.graphql @@ -300,8 +300,10 @@ type GraphAccount @entity { type GraphAccountMetadata @entity(immutable:true) { "IPFS hash with account metadata details" id: ID! - "Original graph account that created it" - graphAccount: [GraphAccount!] @derivedFrom(field:"metadata") + "Account that reference this metadata file. For compatibility purposes. For the full list use graphAccounts" + graphAccount: GraphAccount @derivedFrom(field:"metadata") + "Accounts that reference this metadata file" + graphAccounts: [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" @@ -440,8 +442,10 @@ type Subgraph @entity { type SubgraphMetadata @entity(immutable:true) { "Subgraph metadata ipfs hash" id: ID! - "Subgraph entity" + "Subgraph that reference this metadata. For compatibility purposes. For the full list use subgraphs" subgraph: Subgraph @derivedFrom(field:"metadata") + "Subgraphs that reference this metadata" + subgraphs: [Subgraph!]! @derivedFrom(field:"metadata") "Short description of the subgraph" description: String "Image in string format" @@ -503,8 +507,10 @@ type SubgraphVersion @entity { type SubgraphVersionMetadata @entity(immutable:true) { "Subgraph version metadata ipfs hash" id: ID! - "Subgraph version entity" + "SubgraphVersion entity that references this metadata. For compatibility purposes. For the full list use subgraphVersions" subgraphVersion: SubgraphVersion @derivedFrom(field:"metadata") + "SubgraphVersion entities that reference this metadata" + subgraphVersions: [SubgraphVersion!]! @derivedFrom(field:"metadata") "Short description of the version" description: String "Semantic versioning label" @@ -596,8 +602,10 @@ type SubgraphDeployment @entity { type SubgraphDeploymentSchema @entity(immutable:true) { "IPFS Hash" id: ID! - "Link to SubgraphDeployment entity" + "Link to a SubgraphDeploymentManifest entity that references this schema. For backwards compatibility purposes only, for the full list of manifests use manifests" manifest: SubgraphDeploymentManifest @derivedFrom(field:"schema") + "Links to SubgraphDeploymentManifest entities that reference this schema" + manifests: [SubgraphDeploymentManifest!]! @derivedFrom(field:"schema") "Contents of the Schema file" schema: String } @@ -607,7 +615,7 @@ type SubgraphDeploymentManifest @entity(immutable:true) { id: ID! "Link to SubgraphDeployment entity" deployment: SubgraphDeployment @derivedFrom(field:"manifest") - "Schema entity. Not yet working due to limitations with File Data Sources" + "Schema entity" schema: SubgraphDeploymentSchema "Schema ipfs hash" schemaIpfsHash: String diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index b7536c0..ba856e4 100644 --- a/src/mappings/ethereumDIDRegistry.ts +++ b/src/mappings/ethereumDIDRegistry.ts @@ -1,4 +1,4 @@ -import { Bytes } from '@graphprotocol/graph-ts' +import { Bytes, DataSourceContext } from '@graphprotocol/graph-ts' import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry' import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates' import { GraphAccount } from '../types/schema' @@ -17,17 +17,20 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void { // called it directly, it could crash the subgraph let hexHash = changetype(addQm(event.params.value)) let base58Hash = hexHash.toBase58() - graphAccount.metadata = base58Hash + let metadataId = graphAccount.id.concat('-').concat(base58Hash) + graphAccount.metadata = metadataId graphAccount.save() // Update all associated vesting contract addresses let tlws = graphAccount.tokenLockWallets for (let i = 0; i < tlws.length; i++) { let tlw = GraphAccount.load(tlws[i])! - tlw.metadata = base58Hash + tlw.metadata = metadataId tlw.save() } - GraphAccountMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + GraphAccountMetadataTemplate.createWithContext(base58Hash, context) } } diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index c91899e..a7b3226 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -1,4 +1,4 @@ -import { BigInt, BigDecimal, Bytes, log } from '@graphprotocol/graph-ts' +import { BigInt, BigDecimal, Bytes, log, DataSourceContext } from '@graphprotocol/graph-ts' import { SubgraphPublished, SubgraphPublished1, @@ -179,13 +179,15 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + let metadataId = subgraph.id.concat('-').concat(base58Hash) subgraph.metadataHash = event.params.subgraphMetadata - subgraph.metadata = base58Hash + subgraph.metadata = metadataId subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - SubgraphMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } /** @@ -235,11 +237,14 @@ export function handleSubgraphPublished(event: SubgraphPublished): void { subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -712,13 +717,15 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) let hexHash = changetype(addQm(event.params.subgraphMetadata)) let base58Hash = hexHash.toBase58() - + let metadataId = subgraph.id.concat('-').concat(base58Hash) subgraph.metadataHash = event.params.subgraphMetadata - subgraph.metadata = base58Hash; + subgraph.metadata = metadataId; subgraph.updatedAt = event.block.timestamp.toI32() subgraph.save() - SubgraphMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphMetadataTemplate.createWithContext(base58Hash, context) } // - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256) @@ -1076,11 +1083,14 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi let subgraphVersion = SubgraphVersion.load(versionID)! let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } else { let oldVersionID = subgraph.currentVersion @@ -1104,8 +1114,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi subgraphVersion.createdAt = event.block.timestamp.toI32() let hexHash = changetype(addQm(event.params.versionMetadata)) let base58Hash = hexHash.toBase58() + let metadataId = subgraphVersion.id.concat('-').concat(base58Hash) subgraphVersion.metadataHash = event.params.versionMetadata - subgraphVersion.metadata = base58Hash + subgraphVersion.metadata = metadataId let oldDeployment: SubgraphDeployment | null = null if (oldVersionID != null) { @@ -1116,7 +1127,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph) subgraphVersion.save() - SubgraphVersionMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context) } } diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index 378e5f4..e71b081 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -1,4 +1,4 @@ -import { json, Bytes, dataSource, JSONValueKind, log } from '@graphprotocol/graph-ts' +import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts' import { SubgraphMetadata, SubgraphVersionMetadata, @@ -12,7 +12,8 @@ import { import { jsonToString } from './utils' export function handleSubgraphMetadata(content: Bytes): void { - let subgraphMetadata = new SubgraphMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphMetadata = new SubgraphMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -39,7 +40,8 @@ export function handleSubgraphMetadata(content: Bytes): void { } export function handleSubgraphVersionMetadata(content: Bytes): void { - let subgraphVersionMetadata = new SubgraphVersionMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphVersionMetadata = new SubgraphVersionMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -50,7 +52,8 @@ export function handleSubgraphVersionMetadata(content: Bytes): void { } export function handleGraphAccountMetadata(content: Bytes): void { - let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let graphAccountMetadata = new GraphAccountMetadata(id) let tryData = json.try_fromBytes(content) if (tryData.isOk) { let data = tryData.value.toObject() @@ -69,7 +72,8 @@ export function handleGraphAccountMetadata(content: Bytes): void { export function handleSubgraphDeploymentSchema(content: Bytes): void { - let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam()) + let id = dataSource.context().getString("id") + let subgraphDeploymentSchema = new SubgraphDeploymentSchema(id) if (content !== null) { subgraphDeploymentSchema.schema = content.toString() } @@ -97,8 +101,9 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void { subgraphDeploymentManifest.schema = schemaIpfsHash subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash - // Can't create this template here yet (due to current implementation limitations on File Data Sources, but once that's sorted out, this should work.) - SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash) + let context = new DataSourceContext() + context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash)) + SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context) } else { log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()]) }