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

Support PSR-18 clients #27

Closed
simPod opened this issue Aug 2, 2021 · 6 comments
Closed

Support PSR-18 clients #27

simPod opened this issue Aug 2, 2021 · 6 comments
Labels
enhancement A feature or improvement

Comments

@simPod
Copy link
Collaborator

simPod commented Aug 2, 2021

Is your feature request related to a problem? Please describe.

Dropping guzzle as a dependency in v0.8.0 is a nice step forward but two steps need to be done actually.

I have tons of PSR-18 client implementations available but in this lib I'm required to implement Spawnia\Sailor\Client instead which kind of reinvents the wheel.

Describe the solution you'd like

Accept PSR-compatible clients instead.

Doing this now which is a bit cumbersome

        return new class ($client) implements Client {
                public function __construct(private ClientInterface $client)
                {
                }

                public function request(string $query, \stdClass $variables = null) : Response
                {
                    $psr17Factory = new Psr17Factory();
                    $requestFactory = new GraphQLRequestFactory($psr17Factory, $psr17Factory);

                    /** @var array<string, mixed> $variablesArray */
                    $variablesArray = (array) $variables;

                    $request = $requestFactory->createRequest('', $query, $variablesArray);
                    $response = $this->client->sendRequest($request);

                    return Response::fromResponseInterface($response);
                }
            };
@spawnia spawnia added the enhancement A feature or improvement label Aug 2, 2021
@spawnia
Copy link
Owner

spawnia commented Aug 2, 2021

How about we implement something like your example snippet in Spawnia\Sailor\Client\Psr18?

@simPod
Copy link
Collaborator Author

simPod commented Aug 2, 2021

yup. that might work as well but what would be the reason to keep the Spawnia\Sailor\Client interface? It already returns PSR response 🤔

@spawnia
Copy link
Owner

spawnia commented Aug 2, 2021

It already returns PSR response 🤔

It returns GraphQL\Sailor\Response.

Here is an example of a client implementation that has nothing to do with PSR-18 or even HTTP: https://github.com/spawnia/sailor/blob/master/src/Client/Log.php
GraphQL itself is transport-agnostic.

@simPod
Copy link
Collaborator Author

simPod commented Aug 2, 2021

Ah right and I forgot I use this util Response::fromResponseInterface($response). Kk, this makes the most sense #27 (comment) I'll implement it I guess.

@simPod simPod closed this as completed Aug 2, 2021
@spawnia
Copy link
Owner

spawnia commented Aug 2, 2021

I am happy to accept a merge request for this and would like to keep this issue until something has landed.

@spawnia spawnia reopened this Aug 2, 2021
@simPod simPod mentioned this issue Aug 2, 2021
3 tasks
@spawnia
Copy link
Owner

spawnia commented Aug 3, 2021

@spawnia spawnia closed this as completed Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants