subgraphs > Developing > FAQ

開発者 FAQ

Reading time: 7 min

This page summarizes some of the most common questions for developers building on The Graph.

1. サブグラフとは

このセクションへのリンク

A subgraph is a custom API built on blockchain data. Subgraphs are queried using the GraphQL query language and are deployed to a Graph Node using The Graph CLI. Once deployed and published to The Graph's decentralized network, Indexers process subgraphs and make them available for subgraph consumers to query.

2. What is the first step to create a subgraph?

このセクションへのリンク

To successfully create a subgraph, you will need to install The Graph CLI. Review the Quick Start to get started. For detailed information, see Creating a Subgraph.

3. Can I still create a subgraph if my smart contracts don't have events?

このセクションへのリンク

It is highly recommended that you structure your smart contracts to have events associated with data you are interested in querying. Event handlers in the subgraph are triggered by contract events and are the fastest way to retrieve useful data.

If the contracts you work with do not contain events, your subgraph can use call and block handlers to trigger indexing. However, this is not recommended, as performance will be significantly slower.

4. サブグラフに関連付けられている GitHub アカウントを変更できますか?

このセクションへのリンク

No. Once a subgraph is created, the associated GitHub account cannot be changed. Please make sure to carefully consider this before creating your subgraph.

5. How do I update a subgraph on mainnet?

このセクションへのリンク

You can deploy a new version of your subgraph to Subgraph Studio using the CLI. This action maintains your subgraph private, but once you’re happy with it, you can publish to Graph Explorer. This will create a new version of your subgraph that Curators can start signaling on.

6. Is it possible to duplicate a subgraph to another account or endpoint without redeploying?

このセクションへのリンク

サブグラフを再デプロイする必要がありますが、サブグラフの ID(IPFS ハッシュ)が変わらなければ、最初から同期する必要はありません。

7. How do I call a contract function or access a public state variable from my subgraph mappings?

このセクションへのリンク

Take a look at Access to smart contract state inside the section AssemblyScript API.

8. Can I import ethers.js or other JS libraries into my subgraph mappings?

このセクションへのリンク

Not currently, as mappings are written in AssemblyScript.

One possible alternative solution to this is to store raw data in entities and perform logic that requires JS libraries on the client.

9. When listening to multiple contracts, is it possible to select the contract order to listen to events?

このセクションへのリンク

サブグラフ内では、複数のコントラクトにまたがっているかどうかにかかわらず、イベントは常にブロックに表示される順序で処理されます。

10. How are templates different from data sources?

このセクションへのリンク

Templates allow you to create data sources quickly, while your subgraph is indexing. Your contract might spawn new contracts as people interact with it. Since you know the shape of those contracts (ABI, events, etc.) upfront, you can define how you want to index them in a template. When they are spawned, your subgraph will create a dynamic data source by supplying the contract address.

データソース・テンプレートのインスタンス化」のセクションをご覧ください: Data Source Templates

11. Is it possible to set up a subgraph using graph init from graph-cli with two contracts? Or should I manually add another dataSource in subgraph.yaml after running graph init?

このセクションへのリンク

Yes. On graph init command itself you can add multiple dataSources by entering contracts one after the other.

You can also use graph add command to add a new dataSource.

12. In what order are the event, block, and call handlers triggered for a data source?

このセクションへのリンク

Event and call handlers are first ordered by transaction index within the block. Event and call handlers within the same transaction are ordered using a convention: event handlers first then call handlers, each type respecting the order they are defined in the manifest. Block handlers are run after event and call handlers, in the order they are defined in the manifest. Also these ordering rules are subject to change.

When new dynamic data source are created, the handlers defined for dynamic data sources will only start processing after all existing data source handlers are processed, and will repeat in the same sequence whenever triggered.

13. How do I make sure I'm using the latest version of graph-node for my local deployments?

このセクションへのリンク

以下のコマンドを実行してください:

docker pull graphprotocol/graph-node:latest

Note: docker / docker-compose will always use whatever graph-node version was pulled the first time you ran it, so make sure you're up to date with the latest version of graph-node.

もし、イベント中に 1 つのエンティティしか作成されず、他に利用できるものがなければ、トランザクションハッシュ+ログインデックスがユニークになります。Bytes に変換してcrypto.keccak256に通すことで難読化することができますが、これでは一意性は高まりません。

15. Can I delete my subgraph?

このセクションへのリンク

Yes, you can delete and transfer your subgraph.

16. What networks are supported by The Graph?

このセクションへのリンク

対応ネットワークの一覧はこちらで確認できます。

17. Is it possible to differentiate between networks (mainnet, Sepolia, local) within event handlers?

このセクションへのリンク

はい、以下の例のようにgraph-tsをインポートすることで可能です。

import { dataSource } from '@graphprotocol/graph-ts'
dataSource.network()
dataSource.address()

18. Do you support block and call handlers on Sepolia?

このセクションへのリンク

Yes. Sepolia supports block handlers, call handlers and event handlers. It should be noted that event handlers are far more performant than the other two handlers, and they are supported on every EVM-compatible network.

19. Is it possible to specify what block to start indexing on?

このセクションへのリンク

Yes. dataSources.source.startBlock in the subgraph.yaml file specifies the number of the block that the dataSource starts indexing from. In most cases, we suggest using the block where the contract was created: Start blocks

20. What are some tips to increase the performance of indexing? My subgraph is taking a very long time to sync

このセクションへのリンク

Yes, you should take a look at the optional start block feature to start indexing from the block where the contract was deployed: Start blocks

21. Is there a way to query the subgraph directly to determine the latest block number it has indexed?

このセクションへのリンク

はい、あります。organization/subgraphName」を公開先の組織とサブグラフの名前に置き換えて、以下のコマンドを実行してみてください:

curl -X POST -d '{ "query": "{indexingStatusForCurrentVersion(subgraphName: \"organization/subgraphName\") { chains { latestBlock { hash number }}}}"}' https://api.thegraph.com/index-node/graphql

22. Is there a limit to how many objects The Graph can return per query?

このセクションへのリンク

By default, query responses are limited to 100 items per collection. If you want to receive more, you can go up to 1000 items per collection and beyond that, you can paginate with:

someCollection(first: 1000, skip: <number>) { ... }

23. If my dapp frontend uses The Graph for querying, do I need to write my API key into the frontend directly? What if we pay query fees for users – will malicious users cause our query fees to be very high?

このセクションへのリンク

Currently, the recommended approach for a dapp is to add the key to the frontend and expose it to end users. That said, you can limit that key to a hostname, like yourdapp.io and subgraph. The gateway is currently being run by Edge & Node. Part of the responsibility of a gateway is to monitor for abusive behavior and block traffic from malicious clients.

24. Is it possible to use Apollo Federation on top of graph-node?

このセクションへのリンク

Federation is not supported yet. At the moment, you can use schema stitching, either on the client or via a proxy service.

25. I want to contribute or add a GitHub issue. Where can I find the open source repositories?

このセクションへのリンク
  • graph-node
  • graph-tooling
  • graph-docs
  • graph-client
ページを編集

Delete a Subgraph
請求書
ページを編集