Here in my code I have some value in state 'logTicketDetails' which is object and inside that object there are four arrays. I am getting that value now, in my code I am trying to store that inteir object 'logTicketDetails' in GraphQL object, I have written my code below. But I am getting error. Please help me how can I store full object in cache.
logTicketDetails value is below
{ticketTypes: Array(3), preferredLanguages: Array(4), responseMediums: Array(2),
troubleTicketPriority: Array(3)}
// below is logTicketDetails value which is there in state
{ticketTypes: Array(3), preferredLanguages: Array(4), responseMediums: Array(2), troubleTicketPriority: Array(3)}
preferredLanguages: (4) [{…}, {…}, {…}, {…}]
responseMediums: (2) [{…}, {…}]
ticketTypes: (3) [{…}, {…}, {…}]
troubleTicketPriority: (3) [{…}, {…}, {…}]
// this is my cache query
export const LOG_TICKET_DETAILS= gql`
query logTicketDetails {
logTicketDetails {
}
}
`
;
// Here I am writing to cache
await writeToCache(this,
LOG_TICKET_DETAILS,
{
logTicketDetails : this.state.logTicketDetails,
}
);
Each "depth level" [of data stored in apollo cache] requires type def (defined structure/sub field types, __typename
value[-s]) and unique key (usually id
/ _id
, can be customized per type).
You can store unknown (not to be normalized) structures using "custom json scalar" (read docs/tutorials for details). Top level still requires unique key (id, timestamp) - you can add it (decorate entry) after fetching, before cache write.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.