Skip to content

fix: sparse fields set not applied to query #498

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

Merged
merged 1 commit into from
Apr 29, 2019
Merged

fix: sparse fields set not applied to query #498

merged 1 commit into from
Apr 29, 2019

Conversation

maurei
Copy link
Member

@maurei maurei commented Apr 25, 2019

continuation of #476

Indeed, @milosloub, there are still some issues; I was too hasty with replacing Get with the new GetQueryable.

Interestingly enough tests are not failing. Some investigation about this:

  • Fields_Query_Selects_Sparse_Field_Sets is not failing because, even though the sparse field set is not processed in the SQL query, the DocumentBuilder still removes the fields from the output JSON. This behaviour annoys me: (de)serialization should be decoupled from JsonApiContext, see Deserializer only links attributes and not included relationships #497. I don't think we can properly integration test the usage of the new GetQueryable without getting rid of this behaviour in the serialization layer, but that is beyond the scope of this PR.

  • I suspect the same goes for the other sparse field set tests.

I have changed a few things that should apply it to the queries again. All tests are passing, let me know if you have any more comments or an idea how we could more thoroughly test the new GetQueryable. (Note that the previous Get wasn't properly tested for sparse field selection neither)

@milosloub
Copy link
Contributor

milosloub commented Apr 25, 2019

Yeah, you are right. I totally forgot about that logic in DocumentBuilder. I remember, that there is a problem with this - for example you have integer property, so default value is 0 and you are not able to distinguish if it is standard value stored in DB, or if it is default value while new instance is created and you are not requesting this property (using fields without this property). Right now I don't have idea how to solve this other than this approach :/

@maurei
Copy link
Member Author

maurei commented Apr 26, 2019

... so default value is 0 and you are not able to distinguish if it is standard value stored in DB, ...

You're right, I don't think it's possible like this. Even if we only supported sparse fields selection for nullable fields to distinguish between 0 and default(int) (eg nullable int), it still wouldn't cover every scenario because there might be cases in which users actually want to use null as meaningful data. The same goes for strings and most/all other datatypes.

So yep, the (de)serialization layer, when sparse field selection is involved, can not completely (although still more than it is now) be decouple from JsonApiContext .

With respect to this I have the following thoughts:

  • We can still better organise the deserializers so that they become more reusable. Eg: if the deserializer would be used in a JsonApiClient, it will never have to worry about sparse fields. So I think that DocumentBuilder still should naively convert entities into documents without relying on JsonApiContext, and the actual IJsonApiDeserializer can perform additional logic, like

    • taking into account sparse fields when the serializer is used in a server (public class IJsonApiServerDeserializer : IJsonApiDeserializer`)
    • or removing metadata / links when used in a client (public class IJsonApiClientDeserializer : IJsonApiDeserializer`)
  • Sparse field selection on the level of the repositories should be tested using integration tests that involve only repositories, using an in-memory database. The current Fields_Query_Selects_Sparse_Field_Sets test is actually an e2e test.

Anyway, this is both ofc beyond the scope of this PR

Copy link
Contributor

@milosloub milosloub left a comment

Choose a reason for hiding this comment

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

This looks good to me. I think we can go like this with no problem.

@maurei maurei merged commit 0416df7 into master Apr 29, 2019
@maurei maurei deleted the fix/#475 branch April 29, 2019 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants