Skip to content

Conversation

@XiNiHa
Copy link
Contributor

@XiNiHa XiNiHa commented Jul 7, 2025

🚨 IMPORTANT: Please do not create a Pull Request without creating an issue first.

Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of
the pull request.

Description

Remove unneeded toString call in MockStore.

While the stringified type representation was only used for error reporting, the toString function was always getting called, which is a bit inefficient; therefore, I moved it inside the branch.

Also, the toString call was redundant since the JS engine will call it anyway when we interpolate it inside template literals.

The typechecking function is also inverted, but it is mainly for making TS happy, not sure why it doesn't work in the inverted way.

Type of change

Please delete options that are not relevant.

  • 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

  • Ran the test suites
  • Verified the automatic toString behavior by running `${graphql.buildSchema('type Foo { name: Int! }')._typeMap.Foo}` in REPL and confirming Foo returned

Test Environment:

  • OS: macOS 15.5
  • @graphql-tools/...: mock 9.0.23
  • NodeJS: v22.14.0

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

Further comments

Haven't created an issue for this since it's a pretty minimal and chore-like change.

@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2025

🦋 Changeset detected

Latest commit: e63973d

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

This PR includes changesets to release 1 package
Name Type
@graphql-tools/mock 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for non-nullable fields in mock data, ensuring errors are thrown correctly when required values are missing.

Walkthrough

A patch was applied to the '@graphql-tools/mock' package, specifically to the MockStore module. The update refactors type checking logic by switching from isNullableType to isNonNullType and updates the associated error handling. An unnecessary toString call and an unused variable were also removed.

Changes

File(s) Change Summary
.changeset/six-seals-peel.md Added a changeset describing the patch and its effects on @graphql-tools/mock.
packages/mock/src/MockStore.ts Replaced isNullableType with isNonNullType, updated null handling logic, error messages, and removed unused code.

Poem

A patch for the mock, so tidy and neat,
Swapped types with a hop, made errors complete.
No more toString, no stray lines remain,
The MockStore now runs with less to explain.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/mock/src/MockStore.ts

Oops! Something went wrong! :(

ESLint: 9.30.1

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 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 4e85a0e and e63973d.

📒 Files selected for processing (2)
  • .changeset/six-seals-peel.md (1 hunks)
  • packages/mock/src/MockStore.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ardatan
PR: ardatan/graphql-tools#0
File: :0-0
Timestamp: 2025-01-29T19:58:05.749Z
Learning: The `isUrl` helper in @graphql-tools/utils should be tested with both URL.canParse and new URL() paths, covering various URL formats (http, https, file) and invalid cases. Tests should properly mock and restore URL.canParse to ensure consistent behavior across environments.
.changeset/six-seals-peel.md (1)
Learnt from: ardatan
PR: ardatan/graphql-tools#0
File: :0-0
Timestamp: 2025-01-29T19:58:05.749Z
Learning: The `isUrl` helper in @graphql-tools/utils should be tested with both URL.canParse and new URL() paths, covering various URL formats (http, https, file) and invalid cases. Tests should properly mock and restore URL.canParse to ensure consistent behavior across environments.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Unit Test on Node 18 (windows-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v16
  • GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v15
🔇 Additional comments (3)
packages/mock/src/MockStore.ts (2)

12-12: LGTM: Import change aligns with the logic update.

The import change from isNullableType to isNonNullType correctly supports the logic inversion in the normalizeValueToStore method.


339-341: Error message formatting is consistent and clear

Interpolating fieldType in the template literal will invoke its built-in toString(), yielding the expected GraphQL type name (including any non-null ! modifier). A search across the codebase shows no other divergent patterns, so this aligns with the PR’s goal to remove explicit .toString() calls. No further changes needed.

.changeset/six-seals-peel.md (1)

1-6: LGTM: Changeset properly documents the patch.

The changeset correctly identifies this as a patch-level change to the '@graphql-tools/mock' package and provides a clear, concise description that matches the PR objectives.

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

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@XiNiHa XiNiHa force-pushed the mock-unneeded-tostring branch from 0f6784f to e63973d Compare July 7, 2025 06:46
@ardatan ardatan merged commit 803288c into ardatan:master Jul 7, 2025
15 checks passed
@XiNiHa XiNiHa deleted the mock-unneeded-tostring branch July 7, 2025 14:53
@coderabbitai coderabbitai bot mentioned this pull request Jul 19, 2025
12 tasks
ardatan pushed a commit that referenced this pull request Sep 22, 2025
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