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: Initialize originalInput in OperationParams #1142

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tallesborges
Copy link

Summary

  • Added initialization of $originalInput property in the init method of OperationParams class.
  • This fix addresses the issue: "Typed property GraphQL\Server\OperationParams::$originalInput must not be accessed before initialization".
  • The change ensures that $originalInput is properly set from the BaseOperationParams object during initialization.
  • This prevents potential errors when accessing $originalInput and maintains consistency with other properties initialized in the init method.

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
  • Misc. change (internal, infrastructure, maintenance, etc.)

Checklist:

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • Update the README.md
  • Code style has been fixed via composer fix-style

@tallesborges tallesborges changed the title Fix/validate operation params Fix: Initialize originalInput in OperationParams Aug 9, 2024
@mfn mfn self-assigned this Aug 9, 2024
@mfn
Copy link
Collaborator

mfn commented Aug 9, 2024

@tallesborges test are failing, can you check?

Ensure that `originalInput` is initialized to an empty array if the value is null. This prevents potential null reference errors during operations.
@tallesborges
Copy link
Author

tallesborges commented Aug 9, 2024

@mfn, to be honest, I'm not sure if it's necessary to keep the baseOperationParams in that class. I've removed the it, and all tests passed.

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change still leaves a discrepancy with \Rebing\GraphQL\Support\OperationParams::getOriginalInput(), which accesses the parent one and not the shallow copy array of our class.

Can you better explain you use case which triggered all of this?

Removed redundant baseOperationParams property and replaced it with direct internal mappings. This reduces complexity and enhances code readability by accessing variables and read-only flag directly within OperationParams.
@tallesborges
Copy link
Author

It aims to fix the ValidateOperationParamsMiddleware; if an array is used as a variable, it crashes instead of returning the validation error message.

@tallesborges tallesborges requested a review from mfn August 10, 2024 14:11
@tallesborges
Copy link
Author

any comments @mfn ?

@mfn
Copy link
Collaborator

mfn commented Nov 17, 2024

No, sorry, I still don't understand the intention of the change :/

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.

3 participants