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

Equality operator shows incorrect values based on value of "__fulfilled" #2944

Closed
scottasoutherland opened this issue Apr 7, 2023 · 3 comments · Fixed by #2990
Closed

Equality operator shows incorrect values based on value of "__fulfilled" #2944

scottasoutherland opened this issue Apr 7, 2023 · 3 comments · Fixed by #2990
Assignees
Labels
bug Generally incorrect behavior planned-next Slated to be included in the next release
Milestone

Comments

@scottasoutherland
Copy link

scottasoutherland commented Apr 7, 2023

Summary

It is possible to create two objects, which are otherwise identical, but are not equal due to their "_fulfilled" property and the exact mechanism is which they are created.

Namely, if you have an object which has fragment fields, the value of that object.fragments.myFragment is not the same as the exact same fragment created directly.

Version

1.1.1

Steps to reproduce the behavior

  1. Have an object which uses a fragment.
  2. Create the object using .from(<mock>)
  3. Create the fragment type use .from(<mock>)
  4. Check object.fragments.fragementtype == fragment, notice they are not equal due to the value of "_fulfilled" beind different.

Example:

Suppose you have a query that looks something like:

fragment queryResponseFields  on QueryResponse {
   propertyOne
}

query MyQuery {
  myQueryResponse {
     ...queryResponseFields
  }
}
let mockData = Mock<QueryResponse>(propertyOne: "Some Value")
let realObject = MyQuery.MyQueryResponse.from(mockData)
let fragmentObject = QueryResponseFields.from(mockData)

XCTAssertTrue(realObject.fragments.queryResponseFields == fragmentObject) // returns false

Logs

No response

Anything else?

No response

Tasks

No tasks being tracked yet.
@scottasoutherland scottasoutherland added bug Generally incorrect behavior needs investigation labels Apr 7, 2023
@AnthonyMDev
Copy link
Contributor

Thanks for another awesome bug report @scottasoutherland! I'll dig into this one as well!

@AnthonyMDev AnthonyMDev self-assigned this Apr 13, 2023
@AnthonyMDev AnthonyMDev added this to the Patch Releases (1.1.x) milestone Apr 13, 2023
@scottasoutherland
Copy link
Author

I believe the equality operator just compares the underlying dictionary, which is why this is the case. But i'm unclear on why exactly the _fulfilled property is different...or even what it is for.

@AnthonyMDev
Copy link
Contributor

The _fulfilled property is computed during GraphQL execution to keep track of which fragments in the selection set were executed. This is used to determine which fragments the model can be converted to (for type cases and conditional fragments).

It should not be used as part of equality checks, which is an unintended side effect of the implementation. I'm going to work on a fix for this. :)

@AnthonyMDev AnthonyMDev added the planned-next Slated to be included in the next release label Apr 19, 2023
@calvincestari calvincestari added planned-next Slated to be included in the next release and removed planned-next Slated to be included in the next release labels May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants