Skip to content
Open
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 lib/fbe/github_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,12 @@ def client
@client ||=
begin
http = HTTP.new(@token, @host)
schema = GraphQL::Client.load_schema(http)
dump = GraphQL::Client.dump_schema(http)
if dump['data'].nil?
errors = (dump['errors'] || []).map { |e| e['message'] }
raise(Fbe::Error, "Can't load the GraphQL schema from #{@host}: #{errors.empty? ? dump : errors.join('; ')}")
end
schema = GraphQL::Client.load_schema(dump)
c = GraphQL::Client.new(schema:, execute: http)
c.allow_dynamic_queries = true
c
Expand Down
12 changes: 12 additions & 0 deletions test/fbe/test_github_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,16 @@ def test_fake_total_releases_published_dont_count_after_till
h = graph.total_releases_published(owner, name, since, till: since + 60)
assert_equal(1, h['releases'], "the fake counts releases published after the till moment, seed: #{seed}")
end

def test_explains_failed_schema_load
WebMock.disallow_net_connect!
stub_request(:post, 'https://api.github.com/graphql').to_return(
{ status: 401, body: '{"message":"Bad credentials"}' },
{ status: 200, body: '{"errors":[{"message":"API rate limit exceeded"}]}' }
)
e = assert_raises(Fbe::Error) { Fbe::Graph.new(token: 'x').total_issues_and_pulls('a', 'b') }
assert_includes(e.message, '401', 'The HTTP status must be reported')
e = assert_raises(Fbe::Error) { Fbe::Graph.new(token: 'x').total_issues_and_pulls('a', 'b') }
assert_includes(e.message, 'API rate limit exceeded', 'The message from GitHub must be reported')
end
end
Loading