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

Add new step for easier graphql query #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Http/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ class RequestContext implements Context
/** @var RequestFactoryInterface */
private $requestFactory;

public function __construct(PluginClientBuilder $builder, StreamFactoryInterface $streamFactory, RequestFactoryInterface $requestFactory)
/** @var string */
private $graphqlEndpoint;
Comment on lines +40 to +41
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than a propoerty, it would be better IMO to have a I create the following graphql request on :graphqlEndpoint:: or something like that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but as an graphql endpoint is something that is fixed the same for all graphql request, it is redundant to precise it again in each request in my opinion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping ?


public function __construct(PluginClientBuilder $builder, StreamFactoryInterface $streamFactory, RequestFactoryInterface $requestFactory, string $graphqlEndpoint = '')
{
$this->builder = $builder;
$this->streamFactory = $streamFactory;
$this->requestFactory = $requestFactory;
$this->graphqlEndpoint = $graphqlEndpoint;

$this->client = Psr18ClientDiscovery::find();
}
Expand Down Expand Up @@ -118,6 +122,24 @@ final public function set_the_body(string $body): void
$this->request = $request->withBody($stream);
}

/** @When I create the following graphql request: */
final public function set_the_graphql_body(string $body): void
{
if (empty($this->graphqlEndpoint)) {
throw new RuntimeException('No graphql endpoint specified');
}

$this->query = [];
$request = $this->requestFactory->createRequest('POST', $this->graphqlEndpoint);

// let's set a default content-type
$this->set_the_content_type($this->getDefaultContentType());

$stream = $this->streamFactory->createStream(json_encode(['query' => $body]));

$this->request = $request->withBody($stream);
}

/** @When I add/set the value :value to the header :header */
final public function add_header(string $header, string $value): void
{
Expand Down