如何防止合并来自apollo client3中不同apollo链接的相同字段?

我在不同的链接中有两个graphql结构,例如:一个在hasura中,另一个在ASP.NET Core Web API中使用。问题在于,对于具有不同用例用途的某种类型,它们具有相同的架构,这将导致覆盖缓存中的相同字段。让我显示代码:

// Cache implementation
export const cache = new InmemoryCache({
  typepolicies: {
    Query: {
      fields: {
        tickets: {
          merge(existing = [],incoming) {
            const mergedData = [...existing,...incoming];
            return existing ? mergedData : incoming;
          }
        },},});

export const hasuraLink =  createHttpLink({
  uri: "https://blabla/v1/graphql",});

export const link=  createHttpLink({
  uri: "https://blablaDifferent/v1/graphql",});

const client = new ApolloClient({
  cache,link: ApolloLink.split(
    (operation) => operation.getcontext().clientName === 'hasura',hasuraLink,link
  ),});

因此,在组件中,我可以为查询提供上下文,并确定使用此方法在运行时应使用哪个链接。但是它们具有相同的字段tickets

const TICKETS = gql`
query MyQuery {
  tickets {
    id
    body
  }
}
`;

const HASURA_TICKETS = gql`
query MyQuery {
  tickets {
    id
    body
  }
}
`;
const { data: hasuraTickets } = useQuery(HASURA_TICKETS,{
 context: {
    clientName: 'hasura',}
});
const { data: regularTickets} = useQuery(TICKETS);

票证将合并在缓存中,因为它们具有完全相同的字段名,而缓存无法区分它。我该如何克服这种情况?

iCMS 回答:如何防止合并来自apollo client3中不同apollo链接的相同字段?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1518629.html

大家都在问