Skip to content

Commit 32bf62c

Browse files
committed
fix: duplicate entities FDS
1 parent 327c58b commit 32bf62c

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

schema.graphql

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ type GraphAccount @entity {
300300
type GraphAccountMetadata @entity(immutable:true) {
301301
"IPFS hash with account metadata details"
302302
id: ID!
303-
"Original graph account that created it"
304-
graphAccount: [GraphAccount!] @derivedFrom(field:"metadata")
303+
"Account that reference this metadata file. For compatibility purposes. For the full list use graphAccounts"
304+
graphAccount: GraphAccount @derivedFrom(field:"metadata")
305+
"Accounts that reference this metadata file"
306+
graphAccounts: [GraphAccount!]! @derivedFrom(field:"metadata")
305307
"True if it is an organization. False if it is an individual"
306308
isOrganization: Boolean
307309
"Main repository of code for the graph account"
@@ -440,8 +442,10 @@ type Subgraph @entity {
440442
type SubgraphMetadata @entity(immutable:true) {
441443
"Subgraph metadata ipfs hash"
442444
id: ID!
443-
"Subgraph entity"
445+
"Subgraph that reference this metadata. For compatibility purposes. For the full list use subgraphs"
444446
subgraph: Subgraph @derivedFrom(field:"metadata")
447+
"Subgraphs that reference this metadata"
448+
subgraphs: [Subgraph!]! @derivedFrom(field:"metadata")
445449
"Short description of the subgraph"
446450
description: String
447451
"Image in string format"
@@ -503,8 +507,10 @@ type SubgraphVersion @entity {
503507
type SubgraphVersionMetadata @entity(immutable:true) {
504508
"Subgraph version metadata ipfs hash"
505509
id: ID!
506-
"Subgraph version entity"
510+
"SubgraphVersion entity that references this metadata. For compatibility purposes. For the full list use subgraphVersions"
507511
subgraphVersion: SubgraphVersion @derivedFrom(field:"metadata")
512+
"SubgraphVersion entities that reference this metadata"
513+
subgraphVersions: [SubgraphVersion!]! @derivedFrom(field:"metadata")
508514
"Short description of the version"
509515
description: String
510516
"Semantic versioning label"
@@ -596,8 +602,10 @@ type SubgraphDeployment @entity {
596602
type SubgraphDeploymentSchema @entity(immutable:true) {
597603
"IPFS Hash"
598604
id: ID!
599-
"Link to SubgraphDeployment entity"
605+
"Link to a SubgraphDeploymentManifest entity that references this schema. For backwards compatibility purposes only, for the full list of manifests use manifests"
600606
manifest: SubgraphDeploymentManifest @derivedFrom(field:"schema")
607+
"Links to SubgraphDeploymentManifest entities that reference this schema"
608+
manifests: [SubgraphDeploymentManifest!]! @derivedFrom(field:"schema")
601609
"Contents of the Schema file"
602610
schema: String
603611
}
@@ -607,7 +615,7 @@ type SubgraphDeploymentManifest @entity(immutable:true) {
607615
id: ID!
608616
"Link to SubgraphDeployment entity"
609617
deployment: SubgraphDeployment @derivedFrom(field:"manifest")
610-
"Schema entity. Not yet working due to limitations with File Data Sources"
618+
"Schema entity"
611619
schema: SubgraphDeploymentSchema
612620
"Schema ipfs hash"
613621
schemaIpfsHash: String

src/mappings/ethereumDIDRegistry.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Bytes } from '@graphprotocol/graph-ts'
1+
import { Bytes, DataSourceContext } from '@graphprotocol/graph-ts'
22
import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry'
33
import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates'
44
import { GraphAccount } from '../types/schema'
@@ -17,17 +17,20 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void {
1717
// called it directly, it could crash the subgraph
1818
let hexHash = changetype<Bytes>(addQm(event.params.value))
1919
let base58Hash = hexHash.toBase58()
20-
graphAccount.metadata = base58Hash
20+
let metadataId = graphAccount.id.concat('-').concat(base58Hash)
21+
graphAccount.metadata = metadataId
2122
graphAccount.save()
2223

2324
// Update all associated vesting contract addresses
2425
let tlws = graphAccount.tokenLockWallets
2526
for (let i = 0; i < tlws.length; i++) {
2627
let tlw = GraphAccount.load(tlws[i])!
27-
tlw.metadata = base58Hash
28+
tlw.metadata = metadataId
2829
tlw.save()
2930
}
3031

31-
GraphAccountMetadataTemplate.create(base58Hash)
32+
let context = new DataSourceContext()
33+
context.setString('id', metadataId)
34+
GraphAccountMetadataTemplate.createWithContext(base58Hash, context)
3235
}
3336
}

src/mappings/gns.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigInt, BigDecimal, Bytes, log } from '@graphprotocol/graph-ts'
1+
import { BigInt, BigDecimal, Bytes, log, DataSourceContext } from '@graphprotocol/graph-ts'
22
import {
33
SubgraphPublished,
44
SubgraphPublished1,
@@ -179,13 +179,15 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
179179

180180
let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
181181
let base58Hash = hexHash.toBase58()
182-
182+
let metadataId = subgraph.id.concat('-').concat(base58Hash)
183183
subgraph.metadataHash = event.params.subgraphMetadata
184-
subgraph.metadata = base58Hash
184+
subgraph.metadata = metadataId
185185
subgraph.updatedAt = event.block.timestamp.toI32()
186186
subgraph.save()
187187

188-
SubgraphMetadataTemplate.create(base58Hash)
188+
let context = new DataSourceContext()
189+
context.setString('id', metadataId)
190+
SubgraphMetadataTemplate.createWithContext(base58Hash, context)
189191
}
190192

191193
/**
@@ -235,11 +237,14 @@ export function handleSubgraphPublished(event: SubgraphPublished): void {
235237
subgraphVersion.createdAt = event.block.timestamp.toI32()
236238
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
237239
let base58Hash = hexHash.toBase58()
240+
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
238241
subgraphVersion.metadataHash = event.params.versionMetadata
239-
subgraphVersion.metadata = base58Hash
242+
subgraphVersion.metadata = metadataId
240243
subgraphVersion.save()
241244

242-
SubgraphVersionMetadataTemplate.create(base58Hash)
245+
let context = new DataSourceContext()
246+
context.setString('id', metadataId)
247+
SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context)
243248

244249
let oldDeployment: SubgraphDeployment | null = null
245250
if (oldVersionID != null) {
@@ -712,13 +717,15 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)
712717

713718
let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
714719
let base58Hash = hexHash.toBase58()
715-
720+
let metadataId = subgraph.id.concat('-').concat(base58Hash)
716721
subgraph.metadataHash = event.params.subgraphMetadata
717-
subgraph.metadata = base58Hash;
722+
subgraph.metadata = metadataId;
718723
subgraph.updatedAt = event.block.timestamp.toI32()
719724
subgraph.save()
720725

721-
SubgraphMetadataTemplate.create(base58Hash)
726+
let context = new DataSourceContext()
727+
context.setString('id', metadataId)
728+
SubgraphMetadataTemplate.createWithContext(base58Hash, context)
722729
}
723730

724731
// - event: SignalMinted(indexed uint256,indexed address,uint256,uint256,uint256)
@@ -1076,11 +1083,14 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
10761083
let subgraphVersion = SubgraphVersion.load(versionID)!
10771084
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
10781085
let base58Hash = hexHash.toBase58()
1086+
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
10791087
subgraphVersion.metadataHash = event.params.versionMetadata
1080-
subgraphVersion.metadata = base58Hash
1088+
subgraphVersion.metadata = metadataId
10811089
subgraphVersion.save()
10821090

1083-
SubgraphVersionMetadataTemplate.create(base58Hash)
1091+
let context = new DataSourceContext()
1092+
context.setString('id', metadataId)
1093+
SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context)
10841094
} else {
10851095
let oldVersionID = subgraph.currentVersion
10861096

@@ -1104,8 +1114,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
11041114
subgraphVersion.createdAt = event.block.timestamp.toI32()
11051115
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
11061116
let base58Hash = hexHash.toBase58()
1117+
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
11071118
subgraphVersion.metadataHash = event.params.versionMetadata
1108-
subgraphVersion.metadata = base58Hash
1119+
subgraphVersion.metadata = metadataId
11091120

11101121
let oldDeployment: SubgraphDeployment | null = null
11111122
if (oldVersionID != null) {
@@ -1116,7 +1127,9 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
11161127
updateCurrentDeploymentLinks(oldDeployment, deployment, subgraph as Subgraph)
11171128
subgraphVersion.save()
11181129

1119-
SubgraphVersionMetadataTemplate.create(base58Hash)
1130+
let context = new DataSourceContext()
1131+
context.setString('id', metadataId)
1132+
SubgraphVersionMetadataTemplate.createWithContext(base58Hash, context)
11201133
}
11211134
}
11221135

src/mappings/ipfs.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { json, Bytes, dataSource, JSONValueKind, log } from '@graphprotocol/graph-ts'
1+
import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts'
22
import {
33
SubgraphMetadata,
44
SubgraphVersionMetadata,
@@ -12,7 +12,8 @@ import {
1212
import { jsonToString } from './utils'
1313

1414
export function handleSubgraphMetadata(content: Bytes): void {
15-
let subgraphMetadata = new SubgraphMetadata(dataSource.stringParam())
15+
let id = dataSource.context().getString("id")
16+
let subgraphMetadata = new SubgraphMetadata(id)
1617
let tryData = json.try_fromBytes(content)
1718
if (tryData.isOk) {
1819
let data = tryData.value.toObject()
@@ -39,7 +40,8 @@ export function handleSubgraphMetadata(content: Bytes): void {
3940
}
4041

4142
export function handleSubgraphVersionMetadata(content: Bytes): void {
42-
let subgraphVersionMetadata = new SubgraphVersionMetadata(dataSource.stringParam())
43+
let id = dataSource.context().getString("id")
44+
let subgraphVersionMetadata = new SubgraphVersionMetadata(id)
4345
let tryData = json.try_fromBytes(content)
4446
if (tryData.isOk) {
4547
let data = tryData.value.toObject()
@@ -50,7 +52,8 @@ export function handleSubgraphVersionMetadata(content: Bytes): void {
5052
}
5153

5254
export function handleGraphAccountMetadata(content: Bytes): void {
53-
let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam())
55+
let id = dataSource.context().getString("id")
56+
let graphAccountMetadata = new GraphAccountMetadata(id)
5457
let tryData = json.try_fromBytes(content)
5558
if (tryData.isOk) {
5659
let data = tryData.value.toObject()
@@ -69,7 +72,8 @@ export function handleGraphAccountMetadata(content: Bytes): void {
6972

7073

7174
export function handleSubgraphDeploymentSchema(content: Bytes): void {
72-
let subgraphDeploymentSchema = new SubgraphDeploymentSchema(dataSource.stringParam())
75+
let id = dataSource.context().getString("id")
76+
let subgraphDeploymentSchema = new SubgraphDeploymentSchema(id)
7377
if (content !== null) {
7478
subgraphDeploymentSchema.schema = content.toString()
7579
}
@@ -97,8 +101,9 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void {
97101
subgraphDeploymentManifest.schema = schemaIpfsHash
98102
subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash
99103

100-
// 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.)
101-
SubgraphDeploymentSchemaTemplate.create(schemaIpfsHash)
104+
let context = new DataSourceContext()
105+
context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash))
106+
SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context)
102107
} else {
103108
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()])
104109
}

0 commit comments

Comments
 (0)