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

[Confirm] Log GraphQL errors. #375

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion perllib/Integrations/Confirm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,18 @@ sub perform_request_graphql {
my $body = {
query => $query,
};
my $encoded_body = encode_json($body);

$request->content(encode_json($body));
$request->content($encoded_body);

my $response = $self->ua->request($request);

my $content = decode_json($response->content);

if ($content->{errors} && @{$content->{errors}}) {
$self->logger->warn("Got errors in response to GraphQL query $encoded_body: " . $response->content);
}

return $content;
}

Expand Down
43 changes: 43 additions & 0 deletions t/integrations/confirm.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package Integrations::Confirm::Dummy;
use Path::Tiny;
use Moo;
extends 'Integrations::Confirm';
sub _build_config_file { path(__FILE__)->sibling("confirm.yml")->stringify }

package main;

use strict;
use warnings;

use Test::More;
use Test::MockModule;
use Test::Output;
use HTTP::Response;
use JSON::MaybeXS;

BEGIN { $ENV{TEST_MODE} = 1; }

my $lwp = Test::MockModule->new('LWP::UserAgent');

$lwp->mock(request => sub {
return HTTP::Response->new(200, 'OK', [], encode_json({
data => {},
errors => [
{
message => "Uh-oh spaghettio!",
}
]
})
);
});

my $integration = Integrations::Confirm::Dummy->new;

subtest "GraphQL errors are logged " => sub {
local $ENV{TEST_LOGGER} = 'warn';
stderr_like {
$integration->perform_request_graphql(type => 'job_types');
} qr/.*Uh-oh spaghettio!.*/, 'Got expected warning log for errors.';
};

done_testing;
2 changes: 2 additions & 0 deletions t/integrations/confirm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
graphql_url: "http://example.org/graphql"
graphql_key: "key"
Loading