6 dakika
Developer FAQ
Bu sayfa, The Graph üzerinde geliştirme yapan geliştiricilerin sunduğu en yaygın soruların bazılarını özetlemektedir.
Subgraph ile İlgili Sorular
1. What is a Subgraph?
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. Can I change the GitHub account associated with my Subgraph?
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?
You have to redeploy the Subgraph, but if the Subgraph ID (IPFS hash) doesn’t change, it won’t have to sync from the beginning.
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?
Eşleyiciler AssemblyScript ile yazıldığından dolayı şu anda mümkün değil.
Bunun alternatif bir çözümü, verileri varlıklarda ham halde depolayıp, JS kütüphanelerine ihtiyaç duyan işlemleri istemci üzerinde gerçekleştirmektir.
9. Birden fazla sözleşmeyi dinlerken, olayları dinlenecek sözleşmelerin sırasını seçmek mümkün müdür?
Within a Subgraph, the events are always processed in the order they appear in the blocks, regardless of whether that is across multiple contracts or not.
10. Şablonlar veri kaynaklarından ne açıdan farklıdır?
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.
Check out the “Instantiating a data source template” section on: 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. Bir veri kaynağı için olay, blok ve çağrı işleyicileri hangi sırayla tetiklenir?
Olay ve çağrı işleyicileri, öncelikle blok içindeki işlem indisine göre sıralanır. Aynı işlem içindeki olay ve çağrı işleyicileri, şu sıralama kuralına düzenlenir: önce olay işleyicileri, ardından çağrı işleyicileri gelir; her tür kendi içinde manifestoda tanımlandığı sıraya uyar. Blok işleyicileri, olay ve çağrı işleyicilerinden sonra çalıştırılır ve manifestoda tanımlandıkları sıraya göre gerçekleştirilir. Ayrıca, bu sıralama kuralları değişime tabi olabilir.
Yeni dinamik veri kaynakları oluşturulduğunda, dinamik veri kaynakları için tanımlanan işleyiciler yalnızca mevcut tüm veri kaynağı işleyicileri işlendiğinde işlemeye başlar ve her tetiklendiğinde aynı sırada tekrar eder.
13. Yerel çalışma ortamımda graph-node’un en son sürümünü kullandığımdan nasıl emin olabilirim?
Aşağıdaki komutu çalıştırabilirsiniz:
1docker pull graphprotocol/graph-node:latest
Not: docker / docker-compose, ilk çalıştırdığınızda çekilen graph-node sürümünü kullanmaya devam edecektir. Bu yüzden en son graph-node sürümünü kullandığınızdan emin olun.
14. Olayları işlerken bir varlık için “otomatik oluşturulan” id’leri yaratmanın önerilen yolu nedir?
If only one entity is created during the event and if there’s nothing better available, then the transaction hash + log index would be unique. You can obfuscate these by converting that to Bytes and then piping it through crypto.keccak256
but this won’t make it more unique.
15. Can I delete my Subgraph?
Yes, you can delete and transfer your Subgraph.
Ağ ile İlgili Sorular
16. The Graph hangi ağları desteklemektedir?
You can find the list of the supported networks here.
17. Olay işleyicileri içerisinde ağlar (mainnet, Sepolia, yerel) arasında ayrım yapmak mümkün müdür?
Yes. You can do this by importing graph-ts
as per the example below:
1import { dataSource } from '@graphprotocol/graph-ts'23dataSource.network()4dataSource.address()
18. Sepolia ağında blok ve çağrı işleyicilerini destekliyor musunuz?
Evet. Sepolia, blok işleyicileri, çağrı işleyicileri ve olay işleyicilerini destekler. Olay işleyicilerinin diğer iki işleyiciye göre çok daha yüksek performansa sahip olduğu ve tüm EVM uyumlu ağlarda desteklendiği unutulmamalıdır.
Indexing & Querying Related
19. Endekslemeye hangi bloktan başlanacağını belirtmek mümkün müdür?
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?
Var! Aşağıdaki komutu, “organization/subgraphName” kısmına subgraph’inizi yayımladığınız organizasyon adını ve subgraph’inizin adını koyarak deneyin:
1curl -X POST -d '{ "query": "{indexingStatusForCurrentVersion(subgraphName: \"organization/subgraphName\") { chains { latestBlock { hash number }}}}"}' https://api.thegraph.com/index-node/graphql
22. The Graph’in sorgu başına kaç nesne döndürebileceğine dair bir sınır var mı?
Varsayılan olarak, sorgu yanıtları koleksiyon başına 100 ögeyle sınırlıdır. Daha fazlasını almak istiyorsanız koleksiyon başına 1000 ögeye kadar çıkabilirsiniz. Daha da fazlası için şu şekilde sayfalama yapabilirsiniz:
1someCollection(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.
Diğer
24. Apollo Federation’ı graph-node üzerinde kullanmak mümkün mü?
Federation henüz desteklenmiyor. Şu anda, şema birleştirme yöntemini ya istemci tarafında ya da bir proxy hizmeti aracılığıyla kullanabilirsiniz.