Skip to content

Conversation

uroslates
Copy link
Contributor

Description

Fixes #5268 where the feature request for propagating default values when building operations for field has been elaborated.

Related # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • run all existing tests and made sure they are not breaking
  • should work with query with default value arguments
  • should work with mutation with default value arguments

Test Environment:

  • OS:
  • @graphql-tools/...:
  • NodeJS:

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests and linter rules pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@changeset-bot
Copy link

changeset-bot bot commented May 11, 2023

🦋 Changeset detected

Latest commit: 68b55a3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@graphql-tools/utils Minor
@graphql-tools/executor Patch
@graphql-tools/graphql-tag-pluck Patch
@graphql-tools/import Patch
@graphql-tools/links Patch
@graphql-tools/load Patch
@graphql-tools/merge Patch
@graphql-tools/mock Patch
@graphql-tools/node-require Patch
@graphql-tools/relay-operation-optimizer Patch
@graphql-tools/resolvers-composition Patch
@graphql-tools/schema Patch
@graphql-tools/apollo-engine-loader Patch
@graphql-tools/code-file-loader Patch
@graphql-tools/git-loader Patch
@graphql-tools/github-loader Patch
@graphql-tools/graphql-file-loader Patch
@graphql-tools/json-file-loader Patch
@graphql-tools/module-loader Patch
@graphql-tools/url-loader Patch
@graphql-tools/executor-apollo-link Patch
@graphql-tools/executor-envelop Patch
@graphql-tools/executor-legacy-ws Patch
@graphql-tools/executor-urql-exchange Patch
@graphql-tools/executor-yoga Patch
graphql-tools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ardatan ardatan force-pushed the feature/build-operation-for-fields-with-default-values branch from 18927cb to 9a4f0b6 Compare September 24, 2025 16:32
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Generated operations now include default values from schema arguments, providing sensible variable defaults in queries and mutations.
  • Documentation
    • Added guidance and examples explaining how default argument values are propagated into generated operations.
  • Tests
    • Added coverage for queries and mutations that use defaulted arguments to ensure correct variable defaults.
  • Chores
    • Added a changeset entry to release these updates as a minor version.

Walkthrough

Adds propagation of GraphQL argument default values into VariableDefinitionNode when building operations, updates imports and fallback handling for AST conversion, adds tests for query and mutation defaults, and includes a changeset documenting a minor package update.

Changes

Cohort / File(s) Summary
Feature: include argument defaults in variable definitions
packages/utils/src/build-operation-for-field.ts
Computes a VariableDefinitionNode.defaultValue from argument defaultValue using astFromValue(arg.defaultValue, arg.type) with a try/catch fallback to astFromValueUntyped; adds necessary imports and attaches defaultValue when available.
Tests: default value handling
packages/utils/tests/build-operation-node-for-field.spec.ts
Adds tests for query and mutation cases that assert generated operations include variable defaults (Int/String/enum) and correct variable wiring.
Release note / changeset
.changeset/gold-eggs-stick.md
Declares a minor version bump for @graphql-tools/utils and documents how default argument values propagate into generated operations with an example.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Schema
  participant Builder as buildOperationNodeForField
  participant ArgLoop as Arg Iterator
  participant Typed as astFromValue
  participant Untyped as astFromValueUntyped

  Caller->>Builder: buildOperationNodeForField({ schema, kind, field })
  Builder->>Schema: lookup field + arguments
  Builder->>ArgLoop: iterate arguments
  ArgLoop->>Typed: astFromValue(arg.defaultValue, arg.type)
  alt typed conversion succeeds
    Typed-->>ArgLoop: DefaultValue AST
  else typed conversion throws
    ArgLoop->>Untyped: astFromValueUntyped(arg.defaultValue)
    Untyped-->>ArgLoop: DefaultValue AST (untyped)
  end
  ArgLoop-->>Builder: VariableDefinitionNode (with defaultValue if present)
  Builder-->>Caller: DocumentNode (operation with variable defaults)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibbled the schema, a carrot of types,
Found defaults tucked warm in tiny pipes.
Now queries wake with values already sewn,
Variables sprout where seeds were sown.
Thump-thump—tests pass; I hop home, well known.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd105f4 and 68b55a3.

📒 Files selected for processing (3)
  • .changeset/gold-eggs-stick.md (1 hunks)
  • packages/utils/src/build-operation-for-field.ts (4 hunks)
  • packages/utils/tests/build-operation-node-for-field.spec.ts (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ardatan
Copy link
Owner

ardatan commented Sep 24, 2025

Thanks for the PR! Sorry for the late review!

@ardatan ardatan merged commit fded91e into ardatan:master Sep 24, 2025
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.

Enhance buildOperationNodeForField by taking default values into consideration
2 participants