Skip to content

Cache Redirect not causing query to run on partial data when using lists #9063

@amitozalvo

Description

@amitozalvo

Intended outcome:
Query should be sent to the server to receive the missing reference

Actual outcome:
Query not sent to server and I get no data

How to reproduce the issue:

  1. Create a query that fetches a list of items based on a condition:
items(where: { id: $id }) {
    ...CoreItemFields
  }

This will return [item]

  1. Create a cache redirect to the query
new InMemoryCache({
        typePolicies: {
            Query: {
                fields: {
                    items: {
                        read(_, { args, toReference }) {
                            if (!!args.where?.id) {
                                return [toReference({ __typename: "Item", id: args.where.id })];
                            }
                        }
                    }
                }
            }
        }
    }

If you run a query that queries items that do not exist in the cache, the read function will run, returning a list of 1 reference as expected.
But since the reference references to something that does not exist in cache, the query should run. But it doesn't.

Versions
System:
OS: macOS 12.0.1
Binaries:
Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
Browsers:
Chrome: 95.0.4638.69
Safari: 15.1
npmPackages:
apollo-server-express: ^3.3.0 => 3.4.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions