See the condensed schema below for Uniswap and Exchange
# Uniswap global values across all exchanges
type Uniswap @entity {
id: ID!
exchanges: [Exchange!]!
.........
}
type Exchange @entity {
id: ID! # Uniswap Exchange address
...........
# Fields used to help derived relationship
factory: Uniswap! @derivedFrom(field: "exchanges")
}
This is a bad pattern because we are deriving factory from exchange, while factory -> exchange has a relationship of 1-n . Right now we are deriving the factory from the exchanges, even though we know factory will always have id 1 and that there is only one factory. We should do the following:
# Uniswap global values across all exchanges
type Uniswap @entity {
id: ID!
exchanges: [Exchange!]! @derivedFrom(field: "factory")
......
}
type Exchange @entity {
id: ID! # Uniswap Exchange address
...........
factory: Uniswap!
}
And set each Exchanges factory value to the string 1. This will allow for simpler sql queries within graph-node
See the condensed schema below for
UniswapandExchangeThis is a bad pattern because we are deriving factory from exchange, while factory -> exchange has a relationship of
1-n. Right now we are deriving the factory from the exchanges, even though we know factory will always have id1and that there is only one factory. We should do the following:And set each
Exchangesfactory value to the string1. This will allow for simpler sql queries within graph-node