From ec02e7a1c9885997122b5fbbc4b0858822db457a Mon Sep 17 00:00:00 2001 From: "normad.eth" <norman.saade@gmail.com> Date: Sat, 4 Nov 2023 16:22:48 -1000 Subject: [PATCH 1/2] add a note on setting object references via context In my subgraph I needed a reference between the factory and template. I ended up passing the factoryID to the template with context. --- website/pages/en/developing/creating-a-subgraph.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/pages/en/developing/creating-a-subgraph.mdx b/website/pages/en/developing/creating-a-subgraph.mdx index bdbebefba35b..0411bafcd88a 100644 --- a/website/pages/en/developing/creating-a-subgraph.mdx +++ b/website/pages/en/developing/creating-a-subgraph.mdx @@ -683,6 +683,8 @@ let tradingPair = context.getString('tradingPair') There are setters and getters like `setString` and `getString` for all value types. +> **Note:** You can set object references in the context. Simply set the object id with `setBytes` and change the graphql schema accordingly. In the given ExchangeFactory example you might want to have a list of all NewExchange objects in the Factory. + ## Start Blocks The `startBlock` is an optional setting that allows you to define from which block in the chain the data source will start indexing. Setting the start block allows the data source to skip potentially millions of blocks that are irrelevant. Typically, a subgraph developer will set `startBlock` to the block in which the smart contract of the data source was created. From b569bfe89aa503aafb2f76add6320f60b8f1180f Mon Sep 17 00:00:00 2001 From: "normad.eth" <norman.saade@gmail.com> Date: Sun, 5 Nov 2023 13:46:16 -1000 Subject: [PATCH 2/2] Improved note under data source context. --- website/pages/en/developing/creating-a-subgraph.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/pages/en/developing/creating-a-subgraph.mdx b/website/pages/en/developing/creating-a-subgraph.mdx index 0411bafcd88a..5ce8e77415cb 100644 --- a/website/pages/en/developing/creating-a-subgraph.mdx +++ b/website/pages/en/developing/creating-a-subgraph.mdx @@ -683,7 +683,7 @@ let tradingPair = context.getString('tradingPair') There are setters and getters like `setString` and `getString` for all value types. -> **Note:** You can set object references in the context. Simply set the object id with `setBytes` and change the graphql schema accordingly. In the given ExchangeFactory example you might want to have a list of all NewExchange objects in the Factory. +> **Note:** Referecing an entity is done via ID in graphQL. That id can be passed into the instantiated data source by setting it in the context and then accessed within the mapping of the template. Example can be found in the [documenation of graph-ts](https://github.com/graphprotocol/graph-tooling/tree/main/packages/ts#api). ## Start Blocks