图表:我怎样才能在我的回复中包含这个“价格”?不同 GraphQL 类型中存在的值?
我正在与 thegraph.com 合作,并创建了一个子图来索引来自 NFT 市场智能合约的区块链数据我从头开始构建,只是为了我自己的教育目的。同时,我第一次使用 GraphQL 并在这里构建查询,所以我什至不确定这是否是正确的问题,但我将通过下面的屏幕截图来说明我的最终目标是什么。 这是我正在使用的子图端点,以防有人想要检查我在那里的模式并使用它: https://api.thegraph.com/subgraphs/name/parenthesislab/cubansea-mumbai-v9/graphql
我想要的结果:接收此价格
值存在于我在这个单一API响应中获得的相应ERC721tokens
对象内的MarketTokenMinted
类型中。
我当前的 GraphQL 查询(根据上面的屏幕截图生成响应 ^):
query FetchMarketTokens {
account(id: "0xae198b77c760c8d547f796f57c469c0294592ab8") {
id
ERC721tokens(orderBy: identifier, orderDirection: desc, first: 10) {
id
identifier
uri
}
}
marketTokenMinteds(orderBy: tokenId, orderDirection: desc) {
nftContract
price
tokenId
}
}
我当前的 GraphQL 架构部署到此 图表中的子图:
# schema.graphql
type MarketTokenMinted @entity {
id: ID!
itemId: BigInt! # uint256
nftContract: Bytes! # address
tokenId: BigInt! # uint256
seller: Bytes! # address
owner: Bytes! # address
price: BigInt! # uint256
sold: Boolean! # bool
}
type MarketTokenSold @entity {
id: ID!
itemId: BigInt! # uint256
nftContract: Bytes! # address
tokenId: BigInt! # uint256
seller: Bytes! # address
owner: Bytes! # address
price: BigInt! # uint256
sold: Boolean! # bool
}
type Account @entity {
id: ID!
asERC721: ERC721Contract
ERC721tokens: [ERC721Token!]! @derivedFrom(field: "owner")
ERC721operatorOwner: [ERC721Operator!]! @derivedFrom(field: "owner")
ERC721operatorOperator: [ERC721Operator!]! @derivedFrom(field: "operator")
ERC721transferFromEvent: [ERC721Transfer!]! @derivedFrom(field: "from")
ERC721transferToEvent: [ERC721Transfer!]! @derivedFrom(field: "to")
events: [Event!]! @derivedFrom(field: "emitter")
}
type ERC721Contract @entity {
id: ID!
asAccount: Account!
supportsMetadata: Boolean
name: String
symbol: String
tokens: [ERC721Token!]! @derivedFrom(field: "contract")
operators: [ERC721Operator!]! @derivedFrom(field: "contract")
transfers: [ERC721Transfer!]! @derivedFrom(field: "contract")
}
type ERC721Token @entity {
id: ID!
contract: ERC721Contract!
identifier: BigInt!
owner: Account!
approval: Account!
uri: String
transfers: [ERC721Transfer!]! @derivedFrom(field: "token")
}
type ERC721Operator @entity {
id: ID!
contract: ERC721Contract!
owner: Account!
operator: Account!
approved: Boolean!
}
type ERC721Transfer implements Event @entity {
id: ID!
emitter: Account!
transaction: Transaction!
timestamp: BigInt!
contract: ERC721Contract!
token: ERC721Token!
from: Account!
to: Account!
}
interface Event {
id: ID!
transaction: Transaction!
emitter: Account!
timestamp: BigInt!
}
type Transaction @entity {
id: ID!
timestamp: BigInt!
blockNumber: BigInt!
events: [Event!]! @derivedFrom(field: "transaction")
}
经过无数小时试图弄清楚这一点,我不确定我错过了什么,也不知道如何将其组合在一起以接收此 price
值以及每个上获得的其余数据收到的ERC721tokens
对象。任何帮助我走向正确方向的帮助都将受到高度赞赏。
I'm working with thegraph.com and created a subgraph to index blockchain data from a NFT marketplace smart contract I'm building from scratch, just for my own educational purposes. At the same time I'm using using GraphQL and building queries here for the first time, so I'm not even sure if this is the correct question, but I'll get to the point of what's my ultimate goal with the screenshot below.
Here is the subgraph endpoint I'm working with in case someone wants to inspect the schema I have there and play with it: https://api.thegraph.com/subgraphs/name/parenthesislab/cubansea-mumbai-v9/graphql
My desired outcome: Receive this price
value that exists in MarketTokenMinted
type inside the corresponding ERC721tokens
objects i'm getting on this single API response.
My current GraphQL query (produces the response from the screenshot above ^):
query FetchMarketTokens {
account(id: "0xae198b77c760c8d547f796f57c469c0294592ab8") {
id
ERC721tokens(orderBy: identifier, orderDirection: desc, first: 10) {
id
identifier
uri
}
}
marketTokenMinteds(orderBy: tokenId, orderDirection: desc) {
nftContract
price
tokenId
}
}
My current GraphQL schema deployed to this subgraph in The Graph:
# schema.graphql
type MarketTokenMinted @entity {
id: ID!
itemId: BigInt! # uint256
nftContract: Bytes! # address
tokenId: BigInt! # uint256
seller: Bytes! # address
owner: Bytes! # address
price: BigInt! # uint256
sold: Boolean! # bool
}
type MarketTokenSold @entity {
id: ID!
itemId: BigInt! # uint256
nftContract: Bytes! # address
tokenId: BigInt! # uint256
seller: Bytes! # address
owner: Bytes! # address
price: BigInt! # uint256
sold: Boolean! # bool
}
type Account @entity {
id: ID!
asERC721: ERC721Contract
ERC721tokens: [ERC721Token!]! @derivedFrom(field: "owner")
ERC721operatorOwner: [ERC721Operator!]! @derivedFrom(field: "owner")
ERC721operatorOperator: [ERC721Operator!]! @derivedFrom(field: "operator")
ERC721transferFromEvent: [ERC721Transfer!]! @derivedFrom(field: "from")
ERC721transferToEvent: [ERC721Transfer!]! @derivedFrom(field: "to")
events: [Event!]! @derivedFrom(field: "emitter")
}
type ERC721Contract @entity {
id: ID!
asAccount: Account!
supportsMetadata: Boolean
name: String
symbol: String
tokens: [ERC721Token!]! @derivedFrom(field: "contract")
operators: [ERC721Operator!]! @derivedFrom(field: "contract")
transfers: [ERC721Transfer!]! @derivedFrom(field: "contract")
}
type ERC721Token @entity {
id: ID!
contract: ERC721Contract!
identifier: BigInt!
owner: Account!
approval: Account!
uri: String
transfers: [ERC721Transfer!]! @derivedFrom(field: "token")
}
type ERC721Operator @entity {
id: ID!
contract: ERC721Contract!
owner: Account!
operator: Account!
approved: Boolean!
}
type ERC721Transfer implements Event @entity {
id: ID!
emitter: Account!
transaction: Transaction!
timestamp: BigInt!
contract: ERC721Contract!
token: ERC721Token!
from: Account!
to: Account!
}
interface Event {
id: ID!
transaction: Transaction!
emitter: Account!
timestamp: BigInt!
}
type Transaction @entity {
id: ID!
timestamp: BigInt!
blockNumber: BigInt!
events: [Event!]! @derivedFrom(field: "transaction")
}
After countless hours trying to figure this out I'm not sure anymore what I'm missing or how to put this together to receive this price
value along with the rest of the obtained data on each ERC721tokens
objects received. Any help that sets me in the right direction is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

最终找到了如何在此处回答我自己的问题以供将来参考。
这可以通过将
Price
字段添加到erc721token
我的架构的实体来完成。 。然后,我能够将映射逻辑添加到事件返回价格中,该价格将加载erc721token
实体并保存那里的价格信息。此事件是MarketTokenMinted
。将最终解决方案组合在一起如下:
erc721token
键入可选的价格字段:mapping.ts
带有添加的映射逻辑的文件,以通过获取令牌tokenid
参数(来自MarketTokenMintedEvent
),添加.price
属性>属性和值,并使用token.save()
:fetchmarkettokensbyowner
添加价格字段:我现在在每个令牌对象中包含
Price
值的结果:Finally found how, answering my own question here for future reference.
This could be done by adding a
price
field into theERC721Token
entity of my schema. Then I was able to add mapping logic into the event returning price which would load theERC721Token
entity and save the price information there. This event wasMarketTokenMinted
.The final solution was put together as follows:
The
ERC721Token
type with an optional price field added:The
mapping.ts
file with added mapping logic to fetch the token bytokenId
parameter (coming from theMarketTokenMintedEvent
), adds the.price
property and value and save withtoken.save()
:The
FetchMarketTokensByOwner
adding the price field:And the results I'm getting now with the
price
value included inside each token object: