Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.6.0 (Next)
* Your contribution here.

* [#87](https://github.com/ashkan18/graphlient/pull/87): Raised `ExecutionError` with partial error response - [@QQism](https://github.com/QQism).
* [#90](https://github.com/ashkan18/graphlient/pull/90): Added support for Ruby 3.1 - [@QQism](https://github.com/QQism).
* [#90](https://github.com/ashkan18/graphlient/pull/90): Dropped support for Ruby 2.5 - [@QQism](https://github.com/QQism).
* [#91](https://github.com/ashkan18/graphlient/pull/91): Update GHA for `danger` with right permissions - [@QQism](https://github.com/QQism).
Expand Down
2 changes: 1 addition & 1 deletion lib/graphlient/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def client
end

def errors_in_result?(response)
response.data && response.data.errors && response.data.errors.any?
response.data && response.data.errors && response.data.errors.all.any?
end
end
end
20 changes: 20 additions & 0 deletions spec/graphlient/client_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@
GRAPHQL
end

let(:partial_success_query) do
<<-GRAPHQL
query {
someInvoices {
id
feeInCents
createdAt
}
}
GRAPHQL
end

it '#execute' do
response = client.execute(query, id: 42)
invoice = response.data.invoice
Expand Down Expand Up @@ -129,6 +141,14 @@
expect(e.response).to be_a GraphQL::Client::Response
end
end

it 'fails with a partial error response' do
expect do
client.execute(partial_success_query)
end.to raise_error Graphlient::Errors::ExecutionError do |e|
expect(e.response).to be_a GraphQL::Client::Response
end
end
end

context 'non-parameterized query' do
Expand Down
12 changes: 12 additions & 0 deletions spec/support/queries/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Query < GraphQL::Schema::Object
argument :id, Integer, required: false
end

field :some_invoices, [InvoiceType], null: true do
description 'List of invoices'
end

def invoice(id: nil)
return nil if id.nil?
OpenStruct.new(
Expand All @@ -32,4 +36,12 @@ def execution_error_invoice(id: nil, execution_errors:)

invoice(id: id)
end

def some_invoices
[
OpenStruct.new(id: 0, fee_in_cents: 20_000),
OpenStruct.new(id: 1, fee_in_cents: 20_000),
OpenStruct.new(id: 2, fee_in_cents: 20_000)
]
end
end
6 changes: 6 additions & 0 deletions spec/support/types/invoice_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ class InvoiceType < GraphQL::Schema::Object

field :id, ID, null: false
field :fee_in_cents, Integer, null: true
field :created_at, String, null: true, extras: [:execution_errors]

def created_at(execution_errors:)
execution_errors.add(GraphQL::ExecutionError.new('This is a partial error'))
Time.now.iso8601
end
end