Skip to content
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

wip async implementation #106

Closed
wants to merge 3 commits into from
Closed

Conversation

nick-potts
Copy link

@nick-potts nick-potts commented Apr 22, 2024

  • Added automated tests
  • Documented for all relevant versions
  • Updated the changelog

resolves #32

Changes

Added an executeAsync that returns a PromiseInterface. The interface is an extension of the guzzle interface - it's a good standard but this does mean that every client needs to have an adapter. The upside is that the generated code just has a sailor provided interface, not guzzle.

The alternative is that you could specify an async interface you want to use when generating - this would make it easier to use both when making your own client, as well as using the responses. in the current implementation, you'll need to unwrap the promise using your own library's async.

I've also provided a default async guzzle and guzzle adapter.

I didn't update the tests that compare the output generation.

Breaking changes

N/A

@nick-potts nick-potts marked this pull request as draft April 22, 2024 10:47
@nick-potts
Copy link
Author

nick-potts commented Apr 22, 2024

turns out the adapter wasn't working as intended, and getting it typesafe was tricky. I think having an option in the config that allows you to set the async client response type would make the most sense.

@nick-potts
Copy link
Author

nick-potts commented Apr 23, 2024

After some thought, it actually makes more sense to just do the async inside of the client, requiring no modification to the library itself.

        $json = ['query' => $query];
        if (!is_null($variables)) {
            $json['variables'] = $variables;
        }

        $browser = new Browser();
        $promise = $browser->post($url, [
            'Content-Type' => 'application/json',
        ],
            json_encode($json)
        );
        $response = await($promise);
        return Response::fromResponseInterface($response);

@nick-potts nick-potts closed this Apr 23, 2024
@spawnia
Copy link
Owner

spawnia commented May 1, 2024

I am glad you figured something out, thanks for documenting your solution here.

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

Successfully merging this pull request may close these issues.

Async operations
2 participants