Skip to content

Refs #BAC-530: Accept Date for DateTime and give GraphqlRails models the query context - #7

Merged
povilasjurcys merged 4 commits into
mainfrom
feature/BAC-530-date-scalars-and-graphql-context
Oct 20, 2026
Merged

povilasjurcys merged 4 commits into
mainfrom
feature/BAC-530-date-scalars-and-graphql-context

Conversation

@povilasjurcys

@povilasjurcys povilasjurcys commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What's the reason for this feature?

Currently, be_successful_graphql_request reports two false positives in controller specs:

  • A DateTime! field returning a Date fails, though GraphQL serializes it correctly.
  • A GraphqlRails model whose field reads graphql_context raises, because the matcher never sets it (e.g., in shift decorators).

This PR:

  • checks ISO8601DateTime and ISO8601Date through coerce_result. The other built-in scalars keep their class lists, since their coerce_result accepts almost anything.
  • passes the request's context (response.context) down to field calls. A field runs inside with_graphql_context when its type is one GraphqlRails built, matching GraphqlRails' resolver behavior. graphql-ruby calls stay on NullContext.

Reviewers should know:

  • Date fields now accept anything Date.parse(to_s) accepts, such as 20240101, as GraphQL does. This is documented in the CHANGELOG.
  • Still open: the test context only supports []/fetch/key?/to_h, so decorators that call graphql_context&.dig(...) will fail the matcher if the context doesn't support deep navigation. Other open items: the CHANGELOG needs the graphql_rails version once released, no spec pins the respond_to?(:with_graphql_context) guard yet, and the new graphql_context: keyword belongs under "Added".
  • With an older graphql_rails version (no response.context), fields run without a context, as before.

Testing done: gem suite, 122 examples, 0 failures. Validated with updated gem branches in an application test suite where date fields pass the matcher and decorators resolve graphql_context correctly with the request context (and fail without it).

povilasjurcys and others added 3 commits October 19, 2026 10:07
…ls the query context

DateTime and Date fields are checked through coerce_result, so a Date in a
DateTime field passes as it does at runtime. be_successful_graphql_request
calls GraphqlRails model fields inside with_graphql_context(request context),
so decorators reading graphql_context no longer fail only in the matcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd cover nested fields

graphql-ruby leaves graphql_context unset when a GraphqlRails model sits behind
a plain GraphQL type, so the matcher must too. Pins the context reaching list
items, records that aren't models, and the date scalars' edge values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as at runtime

GraphqlRails' resolvers set it for any object that responds to
with_graphql_context, so a subclass returned where its parent type is
declared gets it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@povilasjurcys
povilasjurcys force-pushed the feature/BAC-530-date-scalars-and-graphql-context branch from 3360a7a to c56e829 Compare October 19, 2026 07:07
@povilasjurcys
povilasjurcys requested a balanced review from Copilot October 19, 2026 07:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The limited request context introduces matcher failures for fields using graphql_context&.dig.

1 open issue
What changed in this PR

Aligns date validation with GraphQL serialization and passes request context to GraphqlRails model fields.

Changes:

  • Validates date scalars through coerce_result.
  • Propagates optional context through field validation.
  • Adds regression specs and changelog entries.
File Description
spec/​lib/​rspec_extra_matchers/​graphql_matchers/​type_matcher_spec.rb Covers date coercion and model context behavior.
spec/​lib/​rspec_extra_matchers/​graphql_matchers/​successful_graphql_controller_response_matcher_spec.rb Tests request-context forwarding.
lib/​rspec_extra_matchers/​graphql_matchers/​type_matcher.rb Accepts and forwards optional context.
lib/​rspec_extra_matchers/​graphql_matchers/​successful_graphql_controller_response_matcher.rb Retrieves context from supported responses.
lib/​rspec_extra_matchers/​graphql_matchers/​assert_type_and_value.rb Coerces date scalars and scopes model context.
CHANGELOG.md Documents validation and context changes.

Review effort: Balanced

…the query context

GraphQL resolves an interface to the record's object type before calling
its fields, so a GraphqlRails model behind an interface field reads
graphql_context at runtime. Check that type instead of the interface.
Also cover a non-model record under a GraphqlRails type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@povilasjurcys
povilasjurcys merged commit 9895af4 into main Oct 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants