Skip to content

[4.0] preloadQuery variables don't update when they change #12885

@BrennenRocks

Description

@BrennenRocks

Issue Description

https://community.apollographql.com/t/preloadquery-without-topromise-in-v4/9409/4

  loader: async ({ params }) => {
    const queryRef = preloadQuery(Deal_Query, {
      fetchPolicy: 'cache-and-network',
      variables: { dealId: params.dealId }, // <--- When `params.dealId` changes the queryRef doesn't update
    });

    return preloadQuery.toPromise(queryRef);
  },

Workaround

  loader: async ({ params }) => {
    const queryRef = preloadQuery(Deal_Query, {
      fetchPolicy: 'cache-and-network',
      variables: { dealId: params.dealId },
    });

    const q = await preloadQuery.toPromise(queryRef);
    // @ts-expect-error
    q.dealId = params.dealId;
    return q;
  },

Link to Reproduction

none

Reproduction Steps

Image

@apollo/client version

4.0.2

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