diff --git a/schema.graphql b/schema.graphql index 6364809..56ceae8 100644 --- a/schema.graphql +++ b/schema.graphql @@ -155,8 +155,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" diff --git a/src/mappings/ethereumDIDRegistry.ts b/src/mappings/ethereumDIDRegistry.ts index 6696c7b..7a10303 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,9 +17,12 @@ 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() - GraphAccountMetadataTemplate.create(base58Hash) + let context = new DataSourceContext() + context.setString('id', metadataId) + GraphAccountMetadataTemplate.createWithContext(base58Hash, context) } } \ No newline at end of file diff --git a/src/mappings/ipfs.ts b/src/mappings/ipfs.ts index 92c4207..db5c86e 100644 --- a/src/mappings/ipfs.ts +++ b/src/mappings/ipfs.ts @@ -5,7 +5,8 @@ import { import { jsonToString } from './utils' 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() diff --git a/yarn.lock b/yarn.lock index 2b6a87e..dbf0a8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -425,10 +425,10 @@ graphql-import-node "^0.0.5" js-yaml "^4.1.0" -"@graphprotocol/contracts@5.3.0": - version "5.3.0" - resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-5.3.0.tgz#9c754cdba56bf84ef32c68617dc59a4ddf00ffd0" - integrity sha512-o1Dvk1h+Me+BEaeYoPr4M2dBT5PvLJAUlSuKjIOIy/hD5y1PAkBMZi2EnP5BWXP+1vn4y3q7d+qZjAmVKakL/Q== +"@graphprotocol/contracts@5.3.3": + version "5.3.3" + resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-5.3.3.tgz#89c383ce244d9ed6cf1146baafde379cbbdfdfe6" + integrity sha512-fmFSKr+VDinWWotj2q/Ztn92PppcRrYXeO/62gLgkLos/DcYa7bGWKbcOWyMUw0vsUvXxk6QAtr5o/LG3yQ1WQ== dependencies: console-table-printer "^2.11.1" ethers "^5.6.0"