Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support promise based queryFn function #54

Closed
nitedani opened this issue Nov 13, 2022 · 1 comment
Closed

Support promise based queryFn function #54

nitedani opened this issue Nov 13, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@nitedani
Copy link
Contributor

nitedani commented Nov 13, 2022

Which @ngneat/query-* package(s) are relevant/releated to the feature request?

query

Description

I would like to use a basic async function as the queryFn.

For example this one:

export const getPets = async () => {
  const response = await fetch('https://pokeapi.co/api/v2/pokemon');
  const json: {
    results: { name: string; url: string }[];
  } = await response.json();

  return json;
};

Proposed solution

Add the extra types for all of the exported functions, so they will accept basic async functions where they can, instead of only supporting observables. Check if the queryFn returns a promise or observable. If it returns a promise, then use that/wrap it with from.

Alternatives considered

Wrapping every promise in from, but I would like cleaner code.

Do you want to create a pull request?

No

@NetanelBasal
Copy link
Member

Most Angular developers work with the HTTP client, which returns an observable, so I think it's not more than "nice to have".

@NetanelBasal NetanelBasal changed the title Support basic async queryFn function Support promise based queryFn function Nov 13, 2022
@NetanelBasal NetanelBasal added the enhancement New feature or request label Nov 13, 2022
@ngneat ngneat locked and limited conversation to collaborators Nov 13, 2022
@NetanelBasal NetanelBasal converted this issue into discussion #55 Nov 13, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants