Skip to content

Enforce input/output kind safety for ListOf/Nullable wrappers at compile time#569

Merged
xperiandri merged 7 commits into
devfrom
copilot/fix-listof-nullable-validation
May 17, 2026
Merged

Enforce input/output kind safety for ListOf/Nullable wrappers at compile time#569
xperiandri merged 7 commits into
devfrom
copilot/fix-listof-nullable-validation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

ListOf, Nullable, and StructNullable were previously kind-agnostic wrappers, so input types could be wrapped and consumed as output types (and vice versa), producing invalid schemas only detected at runtime. This change makes wrapper direction explicit in the type system and resolved at compile time.

Changes Made

  • Added directional markers (InputOutputDef / InputOutputDef<'Val>) for defs valid in both input and output contexts.
  • Reworked wrapper dispatch for Nullable, StructNullable, and ListOf to resolve by kind at compile time:
    • InputDef<'T> → input wrapper
    • OutputDef<'T> → output wrapper
    • InputOutputDef<'T> → dual-capable wrapper
  • Updated affected call sites where direction needed to be explicit to keep type inference stable.
  • Added focused tests (TypeWrappersKindSafetyTests) to verify wrapper direction is preserved for input-only/output-only types.
  • Applied review feedback in Relay Connections.fs by reverting helper-based wrapper indirection and keeping direct Nullable usage at call sites.

Validation

  • dotnet test tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj
  • dotnet test tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj --no-build

Comment thread src/FSharp.Data.GraphQL.Server.Relay/Connections.fs Outdated
Copilot AI changed the title [WIP] Fix validation of ListOf and Nullable types Enforce input/output kind safety for ListOf/Nullable wrappers at compile time May 17, 2026
Copilot AI requested a review from xperiandri May 17, 2026 15:00
@xperiandri xperiandri force-pushed the copilot/fix-listof-nullable-validation branch from 1fb9e12 to ca08d98 Compare May 17, 2026 17:31
Comment thread src/FSharp.Data.GraphQL.Server.Relay/Connections.fs
@xperiandri xperiandri force-pushed the copilot/fix-listof-nullable-validation branch from ca08d98 to 39decb4 Compare May 17, 2026 17:32
@xperiandri xperiandri marked this pull request as ready for review May 17, 2026 17:32
Copilot AI requested a review from xperiandri May 17, 2026 17:40
@xperiandri xperiandri force-pushed the copilot/fix-listof-nullable-validation branch from 945c831 to e1fab18 Compare May 17, 2026 17:41
Copilot AI and others added 7 commits May 17, 2026 19:51
Introduce a new test suite to verify compile-time enforcement of input/output directionality for ListOf, Nullable, and StructNullable wrappers. Replace previous inline tests with F# script-based checks that are executed via dotnet fsi. Update the test project to include these scripts as content files and ensure References.fsx is managed and ignored appropriately.
@xperiandri xperiandri force-pushed the copilot/fix-listof-nullable-validation branch from 29517ee to 0e567bd Compare May 17, 2026 17:51
@xperiandri xperiandri merged commit 022d633 into dev May 17, 2026
3 checks passed
@xperiandri xperiandri deleted the copilot/fix-listof-nullable-validation branch May 17, 2026 18:02
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.

ListOf and Nullable must not allow putting input types where output types expected and vice versa

3 participants