nuwave / nuwave/lighthouse

"Date" scalar serialization on subscription results in conversion to string, fails internal type validation test

Open
#1,606 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

Describe the bug

For queries and mutations, Lighthouse converts the Date scalar to the Carbon library for convenient back-end development. For a subscription, Dates are cast to string before being passed to the Subscription handler (ex. "authorize"method). "Date" scalars are converted to UTC format like so: 2020-11-02T00:00:00.000000Z. Subscriptions must store the attribute values in memory in order to be available for the "filter" and "resolve" methods.

When later recalled for the "filter" or "resolve" methods, they then fail the type validation test within webonyx\graphql-php which is expecting a Date. The long-form

Expected behavior/Solution

Type coercion to Carbon instance for use within the Subscription class, and proper storage in memory so that the validation test doesn't later fail.

Steps to reproduce

  1. Make a subscription with a "Date" argument.
  2. Join subscription - this can work if Date argument is handled as string type
  3. Broadcast on channel fails due to type validation error.

Lighthouse Version

4.17.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the subscription argument handling and the authorize, filter, and resolve entry points described in the report, then trace Date scalar values through subscription storage and broadcast. Reproduce the failure with a Date argument and verify that the subscription receives the expected Carbon value and that broadcast no longer triggers webonyx/graphql-php type validation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.