Skip to content

feat(network-subgraphs): Add idAsString field #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/network-subgraphs/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type StreamPermission @entity {
type Stream @entity {
"stream ID = 'creator address'/'path' where path can be any string"
id: ID!
"This field has the same value as the ID field. It enables us to perform substring queries on the id field using the idAsString_contains where clause"
idAsString: String! @index
"Stream metadata JSON"
metadata: String!
"Permissions that each Ethereum address owns to this stream"
Expand Down
9 changes: 9 additions & 0 deletions packages/network-subgraphs/src/streamRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function handleStreamCreation(event: StreamCreated): void {
return
}
let stream = new Stream(event.params.id)
stream.idAsString = event.params.id
stream.metadata = event.params.metadata
stream.createdAt = event.block.timestamp
stream.updatedAt = event.block.timestamp
Expand All @@ -37,7 +38,15 @@ export function handleStreamUpdate(event: StreamUpdated): void {
[event.params.id, event.params.metadata, event.block.number.toString()])
let stream = Stream.load(event.params.id)
if (stream === null) {
// If the stream was initialized using the trustedSetStreamMetadata() method instead of the usual createStream(),
// the Stream entity does not yet exist. This pattern was used at least in the brubeck-migration-script
// (see https://github.com/streamr-dev/network-contracts/pull/1007), and possibly also in ENS stream creation
// (see https://github.com/streamr-dev/network-contracts/pull/109).
// The trustedSetStreamMetadata() method, which existed in StreamRegistry before version 5, only emitted
// the StreamUpdated event. Since no StreamCreated event was triggered during this process, the handleStreamCreation()
// function was not called, and therefore the Stream entity wasn't created. For this reason we need to create it here.
stream = new Stream(event.params.id)
stream.idAsString = event.params.id
stream.createdAt = event.block.timestamp
}
stream.metadata = event.params.metadata
Expand Down