I have problems getting local-only fields via typePolicies to work in my app. My setup is the following:
This is one of my queries:
export const GET_ALL_DEBT_TOKENS = gql`
query GetDebtTokens {
getDebtTokens {
totalSupplyUSD
totalReserve
totalReserve24hAgo
token {
address
symbol
priceUSD @client
priceUSD24hAgo
}
}
}
`;
And this is the config to resolve my local field:
export function CustomApolloProvider({ children }: PropsWithChildren<{}>) {
const client = new ApolloClient({
// TODO: replace with your own graphql server
uri: 'https://flyby-router-demo.herokuapp.com/',
cache: new InMemoryCache({
typePolicies: {
Token: {
fields: {
priceUSD: {
read() {
console.log('priceUSD read function is called');
return 100;
},
},
},
},
},
}),
});
return <ApolloProvider client={client}>{children}</ApolloProvider>;
}
This is the relevant schema:
type Token {
address: String! # contract address, used as id
symbol: String!
createdAt: String!
#
priceUSD24hAgo: Float!
#
isPoolToken: Boolean!
}
type DebtTokenMeta {
token: Token!
# borrower specific
walletAmount: Float
troveMintedAmount: Float
stabilityLostAmount: Float
stabilityCompoundAmount: Float
# global
stabilityDepositAPY: Float!
totalDepositedStability: Float!
totalReserve: Float!
totalReserve24hAgo: Float!
totalSupplyUSD: Float!
totalSupplyUSD24hAgo: Float!
}
My dev server returns everything except the “priceUSD” field. I also never see that log in the console. I am wondering how I can mess up this simple get-started guide.
The field marked with “@client” is not in the query to my Mock Service Worker. I wonder if it is the mock service worker that is causing the issue or a simple mistake by me.