Hi everyone!
I have the following type Query getAuditEvents:
extend type Query {
getAuditEvents(namespace: String!, first:Int, after:String, before:String, filter: AuditEventsFilter): Edges!
}
I need to use this query on 2 different pages, with separate cache objects, and using cursor-based pagination. For the first page, a table is shown with a number of items per page and Previous and Next buttons, and for the second page - Infinite scroll with relayStylePagination.
1.
const GET_AUDIT_EVENTS = gql`query getAuditEvents($namespace: String! $first: Int $after: String $before: String $filter: AuditEventsFilter){
auditEvents: getAuditEvents(namespace: $namespace first: $first after: $after before: $before filter: $filter) {
edges {
node {
... on AuditEvent {
id
events
userId
userName
targetId
targetType
}
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
totalEdges
}
}
}`;
const [getAuditEvents, {
data, fetchMore, networkStatus,
}] = useLazyQuery(GET_AUDIT_EVENTS, {
fetchPolicy: "network-only",
nextFetchPolicy: "cache-first",
notifyOnNetworkStatusChange: true,
});
//////////////////////////////////////////////////////////////////////////////////////
2.
const GET_RECENT_EVENTS = gql`query getRecentActivity($namespace: String! $first: Int $after: String $before: String $filter: AuditEventsFilter){
auditEvents: getAuditEvents(namespace: $namespace first: $first after: $after before: $before filter: $filter) {
edges {
node {
... on AuditEvent {
id
events
userName
eventDt
}
}
cursor
}
pageInfo {
hasNextPage
endCursor
totalEdges
}
}
}`;
const [getAuditEvents, {
data, networkStatus, fetchMore,
}] = useLazyQuery(GET_RECENT_ACTIVITY, {
fetchPolicy: "network-only",
nextFetchPolicy: "cache-first",
notifyOnNetworkStatusChange: true,
});
I’ve added both fields to typePolicies inMemoryCache obj:
export default new InMemoryCache({
typePolicies: {
Query: {
fields: {
getAuditEvents: {
keyArgs: false,
merge: (existing, incoming) => incoming,
},
getRecentActivity: relayStylePagination(),
},
},
},
});
First query getAuditEvents is returning the right edges as expected, but the second query getRecentActivity would not use relayStylePagination(), instead, it uses the same merge function that the first query uses.
I was wondering if there is any way to make the second query visible inside inMemoryCache config?
Thank you!!