Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 6560 nullable required fields #6561

Closed

Conversation

FGoessler
Copy link
Contributor

@FGoessler FGoessler commented Feb 9, 2024

🚨 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

This PR fixes an issue with JSOM schema based fields that are required and nullable at the same time. More details in issue.

Fixes #6560

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Screenshots/Sandbox (if appropriate/relevant):

Screenshot of failing test before fix:
Screenshot 2024-02-09 at 21 33 36

Screenshot of passing test after fix:
Screenshot 2024-02-09 at 21 34 13

How Has This Been Tested?

Test Environment:

  • OS: MacOS 13.2
  • NodeJS: v18.19.0
"@graphql-mesh/cli": "^0.88.6",
"@graphql-mesh/json-schema": "^0.98.0",
"graphql": "^16.8.1"

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • N.A. I have commented my code, particularly in hard-to-understand areas
  • N.A. 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, and I have added a
    changeset using yarn changeset that bumps the version
  • New and existing unit tests and linter rules pass locally with my changes
  • N.A. Any dependent changes have been merged and published in downstream modules

Copy link

codesandbox bot commented Feb 9, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@FGoessler FGoessler changed the title Fix/6560 nullable required fields fix: 6560 nullable required fields Feb 9, 2024
@FGoessler
Copy link
Contributor Author

These changes actually updated a bunch of snapshots tests. As far as I can see, these tests have been "false positives" before this fix. All those now optional fields should have been optional all the time.

The scope of this makes me wonder why this wasn't noticed earlier. 😅 😬

I also wonder whether this fix might be seen as a breaking change for consumers of GraphQL Mesh as a lot of types might now switch to optional. This not only changes the GraphQL schemas but also any generated TypeScript code based on it. That code then likely breaks compiling as additional non-null checks are required now. On the other hand, this might actually save some people from runtime issues as their Typescript compiler currently "falsely thinks" a field is always present but it actually can be missing. 🤔

@ardatan
Copy link
Owner

ardatan commented Feb 11, 2024

Thanks for the PR! But there were a few issues within this PR.
That code piece you removed is needed for complex cases with unions (allOf and anyOf). If we remove it, a JSON schema that has a prop required in parent but not in the child (anyOf or allOf) will be nonnullable which is not expected. Instead, I followed a different approach here;
#6563

@ardatan ardatan closed this Feb 11, 2024
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.

JSON-Schema issues with required + nullable=true fields
2 participants