Skip to content

Commit

Permalink
fix: handle-file-datasource-duplicate-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed May 6, 2024
1 parent d733214 commit e4eaba3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ type LItem @entity {
}

type LItemMetadata @entity {
"ipfs cid"
"ipfs cid - Litem ID"
id: ID!
"The parsed data describing the item."
props: [ItemProp!]! @derivedFrom(field: "item")
Expand Down
16 changes: 13 additions & 3 deletions src/GeneralizedTCRMapping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable prefer-const */
import { Bytes, BigInt, Address, log } from '@graphprotocol/graph-ts';
import {
Bytes,
BigInt,
Address,
log,
DataSourceContext,
} from '@graphprotocol/graph-ts';
import {
Item,
Request,
Expand Down Expand Up @@ -614,8 +620,12 @@ export function handleEvidence(event: EvidenceEvent): void {
);

const ipfsHash = extractPath(event.params._evidence);
evidence.metadata = ipfsHash;
EvidenceMetadataTemplate.create(ipfsHash);
evidence.metadata = `${ipfsHash}-${evidence.id}`;

const context = new DataSourceContext();
context.setString('evidenceId', evidence.id);

EvidenceMetadataTemplate.createWithContext(ipfsHash, context);

evidenceGroup.save();
evidence.save();
Expand Down
11 changes: 8 additions & 3 deletions src/LightGeneralizedTCRMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ export function handleNewItem(event: NewItem): void {
item.latestRequestSubmissionTime = BigInt.fromI32(0);

const ipfsHash = extractPath(event.params._data);
item.metadata = ipfsHash;
item.metadata = `${ipfsHash}-${graphItemID}`;

log.debug('Creating datasource for ipfs hash : {}', [ipfsHash]);

const context = new DataSourceContext();
context.setString('graphItemID', graphItemID);
Expand Down Expand Up @@ -850,8 +852,11 @@ export function handleEvidence(event: EvidenceEvent): void {
);

const ipfsHash = extractPath(event.params._evidence);
evidence.metadata = ipfsHash;
EvidenceMetadataTemplate.create(ipfsHash);
evidence.metadata = `${ipfsHash}-${evidence.id}`;

const context = new DataSourceContext();
context.setString('evidenceId', evidence.id);
EvidenceMetadataTemplate.createWithContext(ipfsHash, context);

evidenceGroup.save();
evidence.save();
Expand Down
6 changes: 5 additions & 1 deletion src/fileHandlers/EvidenceMetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { EvidenceMetadata } from '../../generated/schema';

export function handleGTCREvidenceMetadata(content: Bytes): void {
const id = dataSource.stringParam();
const evidence = new EvidenceMetadata(id);

const context = dataSource.context();
const evidenceId = context.getString('evidenceId');

const evidence = new EvidenceMetadata(`${id}-${evidenceId}`);
const value = json.fromBytes(content).toObject();

log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]);
Expand Down
5 changes: 4 additions & 1 deletion src/fileHandlers/LEvidenceMetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { EvidenceMetadata } from '../../generated/schema';

export function handleLGTCREvidenceMetadata(content: Bytes): void {
const id = dataSource.stringParam();
const evidence = new EvidenceMetadata(id);
const context = dataSource.context();
const evidenceId = context.getString('evidenceId');

const evidence = new EvidenceMetadata(`${id}-${evidenceId}`);
const value = json.fromBytes(content).toObject();

log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]);
Expand Down
5 changes: 3 additions & 2 deletions src/fileHandlers/LItemMetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { JSONValueToBool, JSONValueToMaybeString } from '../utils';

export function handleLItemMetadata(content: Bytes): void {
const id = dataSource.stringParam();
const metadata = new LItemMetadata(id);

const value = json.fromBytes(content).toObject();
const context = dataSource.context();

const context = dataSource.context();
const graphItemID = context.getString('graphItemID');
const address = context.getString('address');

const metadata = new LItemMetadata(`${id}-${graphItemID}`);

metadata.keywords = address;

log.debug(`ipfs hash : {}, content : {}`, [id, content.toString()]);
Expand Down
2 changes: 1 addition & 1 deletion subgraph.template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
specVersion: 0.0.4
specVersion: 1.0.0
description: Generalized TCR
features:
- fullTextSearch
Expand Down

0 comments on commit e4eaba3

Please sign in to comment.