possibleTypes doesn't work with subfields of typePolicies

39 Views Asked by At

For a bigger project I tried to use the InMemoryCache config of Apollo to write something like a default mergefunction. The possibleTypes inheritance looks like it could help, but it seems to not work with subfields. My queries are all saved below the ROOT_QUERY, so I have to use the subfields instead of the fields directly. Grateful for any help!

My current code looks like this, but doesn't work:

const cache = new InMemoryCache({
  possibleTypes: {
    queryName: ['apple', 'banana'],
  },
  typePolicies: {
    Query: {
      fields: {
        queryName: {
          merge: false,
        },
      },
    },
  },
})

Which should be the same as this code, that works:

const cache = new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        apple: {
          merge: false,
        },
        banana: {
          merge: false,
        },
      },
    },
  },
})
1

There are 1 best solutions below

2
phry On

possibleTypes is as the name implies for inheritance of type names - it doesn't work for fields, which are a competely different concept.

Is there anything in the documentation that indicates that this might work?