Skip to content

Commit

Permalink
Add failing test for changing variables with observableQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Feb 9, 2024
1 parent 65ab695 commit 02e6dc2
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/core/__tests__/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3355,3 +3355,81 @@ test("handles changing variables in rapid succession before other request is com
networkStatus: NetworkStatus.ready,
});
});

test("does not return partial cache data when `returnPartialData` is false and new variables are passed in", async () => {
const cache = new InMemoryCache();
const client = new ApolloClient({
cache,
link: ApolloLink.empty(),
});

const query = gql`
query MyCar($id: ID) {
car(id: $id) {
id
make
}
}
`;

const partialQuery = gql`
query MyCar($id: ID) {
car(id: $id) {
id
make
model
}
}
`;

cache.writeQuery({
query,
variables: { id: 1 },
data: {
car: {
__typename: "Car",
id: 1,
make: "Ford",
model: "Pinto",
},
},
});

cache.writeQuery({
query: partialQuery,
variables: { id: 2 },
data: {
car: {
__typename: "Car",
id: 2,
make: "Ford",
model: "Bronco",
},
},
});

const observable = client.watchQuery({
query: partialQuery,
variables: { id: 2 },
returnPartialData: false,
notifyOnNetworkStatusChange: true,
});

const stream = new ObservableStream(observable);

expect(await stream.takeNext()).toEqual({
loading: false,
networkStatus: NetworkStatus.ready,
data: {
car: { __typename: "Car", id: 2, make: "Ford", model: "Bronco" },
},
});

observable.reobserve({ variables: { id: 1 } });

expect(await stream.takeNext()).toEqual({
loading: true,
networkStatus: NetworkStatus.loading,
data: undefined,
});
});

0 comments on commit 02e6dc2

Please sign in to comment.