You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
Intended outcome:
I have a situation where I need to access passed parameters once I've ran useLazyQuery. Right now I can't await the result since the method returns void and I can't run the execute function with onCompleted as an option. This means I have to default to ApolloClient.query(). This issue is discussed here but I think one way to solve it that isn't discussed here is to be able to pass an onCompleted on the execute function instead, rather than having an onCompleted on the useLazyQuery or returning a Promise. I also know @FredyC originally intended for a Promise to be return but having an onComplete on the execute function would also work.
Actual outcome:
useLazyQuery returns a tuple with a function which, when used, returns void. Using onCompleted when defining the useLazyQuery means I can't access passed variables from a method when I need to.
How to reproduce the issue:
Something like the code below (not functioning code, just to give an idea of the usecase).
const [someQuery, {data, loading, error}] = useLazyQuery(SOME_QUERY, {variables: {foo: "bar"}});
const someMethod = (someVar) => {
// Doesn't work
let data = await someQuery();
anotherMethod(data, someVar)
// Doesn't work
someQuery({onCompleted: data => {
anotherMethod(data, someVar)
}})
}
const anotherMethod = (someData, passedVar) => {
// Do something
}
render() {
<button onClick={() => someMethod("quaz")}></button>
}
Honestly, I don't think it's a good idea to approach this through the callback. A promise is more of a standardized approach for that. Besides, I don't think it's any easier to implement such callback instead of a Promise, the complexity is pretty much the same.
Intended outcome:
I have a situation where I need to access passed parameters once I've ran useLazyQuery. Right now I can't await the result since the method returns void and I can't run the execute function with onCompleted as an option. This means I have to default to ApolloClient.query(). This issue is discussed here but I think one way to solve it that isn't discussed here is to be able to pass an onCompleted on the execute function instead, rather than having an onCompleted on the useLazyQuery or returning a Promise. I also know @FredyC originally intended for a Promise to be return but having an onComplete on the execute function would also work.
Actual outcome:
useLazyQuery returns a tuple with a function which, when used, returns void. Using onCompleted when defining the useLazyQuery means I can't access passed variables from a method when I need to.
How to reproduce the issue:
Something like the code below (not functioning code, just to give an idea of the usecase).
Version
System:
OS: macOS Sierra 10.12.6
Binaries:
Node: 10.0.0 - ~/.nvm/versions/node/v10.0.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v10.0.0/bin/npm
Browsers:
Chrome: 77.0.3865.120
Firefox: 68.0.2
Safari: 12.1.2
npmPackages:
@apollo/react-hooks: ^3.1.0 => 3.1.2
@apollo/react-ssr: ^3.1.0 => 3.1.2
@apollo/react-testing: ^3.1.0 => 3.1.2
apollo-cache-inmemory: ^1.5.1 => 1.6.3
apollo-client: ^2.5.1 => 2.6.4
apollo-link: ^1.2.12 => 1.2.13
apollo-link-error: ^1.1.12 => 1.1.12
apollo-link-http: ^1.5.14 => 1.5.16
apollo-utilities: ^1.3.2 => 1.3.2
The text was updated successfully, but these errors were encountered: