I am facing a problem with the following snippet:
const [execute] = useLazyQuery(gql`
query Example($id: String!) {
node(id: $id) {
... on Train {
id
passengers(first: 1) {
totalCount
}
}
}
}
`)
useEffect(() => {
execute({ onCompleted: () => console.log("Hello world") })
}, [])
interface Node {
id: ID!
}
type PassengerConnection {
totalCount: Int!
}
type Train {
id: ID!
passengers(first: Int): PassengerConnection!
}
type Query {
node(id: String!): Node
}
Observing the network tab tells that the server do return a response.
The execute function indeed returns a promise and this promise resolves that response.
But onCompleted
is not called at any circumstances
Expect
onCompleted
gets run
What I’ve been doing
result.data &&
previousResult?.networkStatus !== result.networkStatus &&
result.networkStatus === NetworkStatus.ready
The above snippet is used by Apollo to evaluate if it will run onCompleted
.
Using the debug tool, I’ve gotten to know that it will be called 3 times, the first time with { loading: true, networkStatus: 1 }
, the second time with { loading: false, networkStatus: 7 }
and the third time with { data: {...}, loading: false, networkStatus: 7 }
while theoretically it should’ve been called 2 times
Please be mindful that adding notifyOnNetworkStatusChange
does help 🙁
I’d like to ask what might be the cause to this
Thank you