第3节:语法学习
小白入门:https://github.com/dukedaily/solidity-expert ,欢迎star转发,文末加V入群。
职场进阶: https://dukeweb3.com
请求格式
{
useFlashloans(first: 5) {
id
user
token
tokenName
}
stakePoolClaimeds(first: 5) {
id
user
amount
token
}
}
查询blocks
{
simpleBlocks(first: 5) {
id
}
}
语法:
在查询的时候,如果是查询数组,则会默认加上复数s,用于查询
如果查询单个,则首字母变成小写。
shift + 空格:查看有哪些schema可以使用。
同步块的时候有两种状态:syncing和pending,勿忘切换查看。
stone这个老版本的graph-ts,apiVersion一定要是:0.0.4,新版本的必须是0.0.5以上
event的address字段就是当前的合约地址
require的字段在创建的时候,都需要显示初始化,例如BigInt的要初始化为BigInt.zero()
查询条件:
_not _gt _lt _gte _lte _in _not_in _contains _not_contains _starts_with _ends_with _not_starts_with _not_ends_with
举例:
{ //其中:deposit_gt 是deposit和 applications(where: { deposit_gt: "10000000000" }) { _gt的组合 id whitelisted deposit } }
测试:
query sb { simpleBlocks(where: { id_gt: "13712600"}){ id } }
查询闪电贷:
{flahloanBalances{id,fee,time,balance}}
打印log使用技巧,必须有{}
log.info('***MARKET*** : underlyingAddress {}', [market.underlyingAddress.toHexString()])
其他
- https://www.apollographql.com/blog/graphql/filtering/how-to-search-and-filter-results-with-graphql/
- https://www.apollographql.com/docs/studio/explorer/explorer/
- https://thegraph.com/docs/en/querying/querying-the-graph/
best practice
- https://thegraph.com/docs/en/querying/querying-best-practices/
- ==https://thegraph.com/docs/en/querying/graphql-api/==(实用)
specification
- https://spec.graphql.org/October2021/
- https://www.bilibili.com/video/BV1RS4y1F7zw?spm_id_from=333.337.search-card.all.click&vd_source=42fe91bf6d16ec8841b22ea520184d76
schema.graphql
type UseFlashloan @entity {
id: ID!
user: String!
token: String!
tokenName: String!
amount: BigInt!
fee: BigInt!
block: BigInt!
time: BigInt!
}
type StakePoolClaimed @entity {
id: ID!
user: String!
token: String!
block: BigInt!
time: BigInt!
}
type FlashTotalClaimed @entity {
id: ID!
amount: BigInt!
lashHash: String!
lastTime: BigInt!
}
type MerkleDistributor @entity {
id: ID!
index: BigInt!
amount: BigInt!
settleBlocNumber: BigInt!
}
type SimpleBlock @entity {
id: ID!
height: BigInt!
time: BigInt!
}
type NoHandlerUseFlashloan @entity {
id: ID!
list: [UseFlashloan!]!
}
type UserFlashloan @entity {
id: ID!
user: String!
reward: BigInt!
flashloan: BigInt!
claimed: Boolean!
}
type FlashloanReward @eneity {
id: ID!
index: BigInt!
amount: BigInt!
settleBlocNumber: BigInt!
totalAmount: BigInt!
flashloanTotalAmount: BigInt!
list: [UserFlashloan!]!
}
type FlashloanBalance @entity {
id: ID!
tokenName: String
fee: BigInt
balance: BigInt
time: BigInt
}