Skip to content

Commit

Permalink
fix: lots of minor fixes to make Subgraph/GraphAccount metadata work
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Sep 11, 2023
1 parent 76197ae commit fd59f64
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 164 deletions.
96 changes: 22 additions & 74 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/mappings/ethereumDIDRegistry.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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)
}
}
7 changes: 0 additions & 7 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import {
GraphAccount,
NameSignalSubgraphRelation,
NameSignal,
SubgraphMetadata,
} from '../types/schema'

import { zeroBD } from './utils'
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
75 changes: 36 additions & 39 deletions src/mappings/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import {
NameSignal,
Delegator,
DelegatedStake,
Network,
SubgraphCategory,
SubgraphCategoryRelation,
NameSignalSubgraphRelation,
CurrentSubgraphDeploymentRelation,
} from '../../types/schema'
Expand Down Expand Up @@ -854,41 +851,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,
Expand Down Expand Up @@ -949,7 +946,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(),
])
Expand Down
Loading

0 comments on commit fd59f64

Please sign in to comment.