Add DSL-only mode: to_query_string + spread#115
Conversation
- Client#to_query_string(**kargs, &block): builds full query document from DSL block and returns a String without touching Faraday or HTTP. - Query#spread(fragment_name): emits ...FragmentName in the query string, replacing the deprecated ___Const graphql-client convention. - spec_helper.rb: rescue LoadError on byebug require (Windows Ruby 3.2). - CLAUDE.md: AI agent instructions for this fork.
static_client_query_spec: add schema_path: 'spec/support/fixtures/invoice_api.json'
The client was fetching the schema from the live URL at module load time
(before WebMock is active), causing 403 in CI. Using a local schema file
avoids the network call and matches the pattern in webmock_client_query_spec.
client_dsl_spec: nodes { } → nodes do end (Style/BlockDelimiters)
query.rb: add rubocop:disable Metrics/ClassLength
Class grew past 100 lines after DSL additions (spread, fragment resolution).
spec_helper.rb: add rubocop:disable Lint/HandleExceptions on rescue LoadError
The empty rescue is intentional — byebug unavailable on some platforms.
Note: faraday_adapter_spec.rb:147 fails locally on Windows (TCP error message
format differs from Linux) but passes in CI on ubuntu-latest. Pre-existing.
On Linux, Errno::ECONNREFUSED.new(msg).message prepends 'Connection refused - '. On Windows, the OS prepends a different string. Use a regex that matches the core error_message content rather than the exact platform-specific prefix.
AI agent instructions are local-only and not relevant to the upstream repo. CLAUDE.md is removed from git tracking but kept in the working directory. Added to .gitignore so future sessions don't accidentally commit it.
Root cause: on Ruby 3.1, WebMock's Faraday middleware intercepts requests before they reach Faraday::Adapter::Rack, returning 403 for any URL without a stub. This caused 25 CI failures on that Ruby version. spec/support/context/dummy_client.rb: Replace Faraday::Adapter::Rack with stub_request.to_rack(app). WebMock routes both schema introspection and query execution through the Sinatra dummy app at the WebMock level (before Faraday dispatch). Removed schema_path: so graphql-client gets the full live schema (including test fields: executionErrorInvoice, partialSuccess etc.). spec/graphlient/static_client_query_spec.rb: Same to_rack approach for execution tests (schema_path kept here since the module constants are created at file-load time, before any before block). Removed Faraday::Adapter::Rack from the static client constructor. spec/graphlient/client_schema_spec.rb: Use include instead of eq for error message — Faraday 2.x appends the URL to the message; include matches on both old and new formats. 73 examples, 0 failures
spec/support/context/dummy_client.rb: spec/graphlient/static_client_query_spec.rb: Replace em-dashes (--) with ASCII semicolons/colons in comments. Style/AsciiComments cop requires pure ASCII. Gemfile: Add mutex_m gem -- activesupport 5.x requires mutex_m which was removed from Ruby's standard library in Ruby 3.4. Adding it explicitly silences the warning and fixes the LoadError on Ruby 3.4. .github/workflows/ci.yml: Add Ruby 3.4 to the required CI matrix (was previously only in ruby-head which is allowed to fail). Ruby 3.4 is now released and should be tested.
New sections:
'Build Query Strings without Validation' -- explains the serialization-only
path (no schema load, no graphql-client validation, no HTTP), shows the
basic usage, clarifies when the string can be fed back to client.execute
(fragment-free queries only), explains why fragment spreads cannot go back
through the gem (graphql-client's constant-based fragment model), and
shows how to_query_string is the escape hatch for replacing graphql-client
with your own HTTP transport entirely.
'Fragment Spreads' -- documents Query#spread as the modern alternative to
the triple-underscore convention; covers basic usage and multiple spreads.
|
The Danger job is failing due to an expired token in the workflow — unrelated to this PR's changes. |
- All entries single-line matching file convention (no continuation lines) - ashkan18#115 entries restored to their original order and not modified - ashkan18#116 prefix added to all directives/fragments/scalars/CI entries
|
I fixed CI / Danger in #117, rebase? |
| @@ -1,5 +1,5 @@ | |||
| module Graphlient | |||
| class Query | |||
| class Query # rubocop:disable Metrics/ClassLength | |||
There was a problem hiding this comment.
run rubocop -a ; rubocop --auto-gen-config.
| * Your contribution here. | ||
| * [#113](https://github.com/ashkan18/graphlient/pull/113): Fix CI builds - [@yuki24](https://github.com/yuki24). | ||
| * [#112](https://github.com/ashkan18/graphlient/pull/112): Update graphql-client github repository links in README - [@th1988](https://github.com/th1988). | ||
| * [#115](https://github.com/ashkan18/graphlient/pull/115): `Client#to_query_string(**kargs, &block)`: builds the full GraphQL query document from the |
There was a problem hiding this comment.
Make it a 1-liner. Add to README if you need something longer.
There was a problem hiding this comment.
sure, will work on this asap
…cop to ~> 1.0 Removed two inline disable comments (Metrics/ClassLength on Query, Lint/HandleExceptions in spec_helper) in favour of the rubocop_todo.yml approach suggested by upstream maintainer. Bumped rubocop dev dependency from pinned 0.56.0 to ~> 1.0 (required for Ruby 3.2 compatibility — Psych.safe_load signature changed). TargetRubyVersion kept at 2.3 to reflect the gem's minimum supported Ruby. Ran rubocop -a (11 auto-corrections) then --auto-gen-config to regenerate .rubocop_todo.yml with current cop names (Metrics/LineLength renamed to Layout/LineLength, Style/MethodMissingSuper removed, etc.).
Danger ReportNo issues found. |
dblock
left a comment
There was a problem hiding this comment.
This looks great! Can we lock rubocop to a specific version in a future PR please, see my comment.
| module Graphlient::Client::Spec | ||
| # schema_path avoids an HTTP schema fetch at file-load time. | ||
| # No Rack adapter needed here; parsing is local and execution is handled | ||
| # by the stub_request below. |
| .rvmrc | ||
|
|
||
| # AI agent instructions — local only, not for the upstream repo | ||
| CLAUDE.md |
There was a problem hiding this comment.
We should commit an AGENTS.md!
| group :development do | ||
| gem 'byebug', platform: :ruby | ||
| gem 'rubocop', '0.56.0' | ||
| gem 'rubocop', '~> 1.0' |
There was a problem hiding this comment.
Since this is a gem and we don't check in Gemfile.lock, this should be locked to a specific version. Otherwise future CI runs will keep breaking without changes.
Add DSL-only mode:
to_query_string+spreadAddresses enhancement proposal: Decouple DSL from GraphQL::Client logic
What
Two new methods for building GraphQL query strings from the DSL without triggering
schema loading, HTTP, or graphql-client validation.
Client#to_query_string(&block)— serializes a DSL block to aStringandreturns it. The string can be fed back to
client.executefor fragment-free queries,or sent with your own HTTP client to replace graphql-client entirely.
Query#spread(fragment_name)— emits...FragmentNamein the query string.Cleaner alternative to the
___Consttriple-underscore convention.Why
Framework layers that need to inspect, log, or augment the query string before
sending (e.g. appending fragment definitions, custom connection pooling) need the
serialized string before graphql-client's validation runs. This also opens a fully
external HTTP path.
Changes
lib/graphlient/client.rb—to_query_stringlib/graphlient/query.rb—spreadspec/graphlient/client_dsl_spec.rb— new spec file (7 examples)README.md— Build Query Strings without Validation + Fragment Spreads sectionsCI fixes included
stub_request.to_rackreplacesFaraday::Adapter::Rackfor cross-Ruby-version reliabilitymutex_madded to Gemfile (removed from stdlib in 3.4).gitignoreupdated for.vscode/,.idea/Checklist