Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fix proper typing lazy hook options #3789

Closed
wants to merge 2 commits into from

Conversation

maapteh
Copy link
Contributor

@maapteh maapteh commented Jan 8, 2020

The lazy types are incorrect, the base options are not being added.

closes #3787

(previous PR was borked because of misconfiguration on current machine)

@krvajal
Copy link

krvajal commented Jan 9, 2020

It seems, from this signature

export interface QueryLazyOptions<TVariables> {
    variables?: TVariables;
    context?: Context;
}

that you can't pass a onCompleted or onError option when calling the lazy query function.
Is this correct?

My use case:

const [lazyQuery] = useLazyQuery(query);
function getData(variables){
return new Promise((resolve,reject) => lazyQuery({variables, onComplete: resolve, onError: reject))
}

Is there any other way to implement this?

@maapteh
Copy link
Contributor Author

maapteh commented Jan 9, 2020

No that is not correct, and that's why this PR has been made. To solve the types. If you don't use TS like your example (and also in their tests) you will be able to do this since these are legit options. But if you do use TS and want these options it will not compile.

@krvajal
Copy link

krvajal commented Jan 9, 2020

since these are legit options.

I don't think they are. They are never called.

@maapteh
Copy link
Contributor Author

maapteh commented Jan 9, 2020

But then that's a bug and not belonging to this PR, see #3505, for example, it showed it's being called

@maapteh maapteh closed this Jan 12, 2020
@maapteh
Copy link
Contributor Author

maapteh commented Jan 14, 2020

@krvajal to help you and make this PR still usefull :)

const [execute, data, error] = useLazyQuery(query, { onCompleted: () => {},onError: () => {}, );
...
execute(variables)

You dont need a Promise and your execution function is only accepting context and variables, the other options just are the second argument in the lazy Query. I read it wrong, just as you :) But the code above works :) Fijne dag en hopelijk hielp deze PR je dan toch een beetje

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

types for lazy hook are incorrect (only two available)
2 participants