Skip to content

useLazyLoadQuery does not prevent sending empty requests to server when using store-and-network #5126

@casperstr

Description

@casperstr

Consider the following useLazyLoadQuery:

  const data = useLazyLoadQuery(
    graphql`
      query TodoQuery($id: ID!, $visible: Boolean!) {
        todo(id: $id) @include(if: $visible) {
          id
        }
      }
    `,
    {
      id: "",
      visible: false,
    },
    {
      fetchPolicy: "store-and-network",
    }
  );

When using fetchPolicy store-or-network no request is made due to the fact that the resulting selection is empty.

When we instead try to use store-and-network an empty unnecessary query is made to the server.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions