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

Refactor transformation #259

Merged
merged 7 commits into from
May 28, 2020
Merged

Conversation

ybroeker
Copy link
Contributor

@ybroeker ybroeker commented May 16, 2020

Comment on lines 74 to 84
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>


Copy link
Member

Choose a reason for hiding this comment

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

Do we have JUnit 5 yet ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is at least already used in the client-implementation.

Copy link
Member

@phillip-kruger phillip-kruger left a comment

Choose a reason for hiding this comment

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

Hi @ybroeker . Thanks for this. I am not sure "why?" though. eems like nothing have really changed i.t.o functionally ? Some decisions, that was made in the implementation has moved to the schema builder ? Why ?

@ybroeker
Copy link
Contributor Author

There are some errors, There were still a few errors, like @NumberFormat int[] or handling of char (see eclipse/microprofile-graphql#252). These require different types on graphql side and on "resolver side" (String[] <-> int[], String <-> char), which has not been considered yet.

To fix this, the corresponding type needs to be known, so it is stored in the schema model. For example for int it is Integer, for a formatted int a String, for LocalDate a String, for char a String.

Since both types are always known, shouldTransform can be simplified - just compare types instead keeping a list of types to transform.

Also the transformers can be simplified a bit.
e.g. now the NumberTransformer gets only numbers, before this was not clear, in some cases it was a String, so the input was formatted first and then immediately parsed. With FormattedNumberTransformer this leads to the behaviour, that a @NumberFormat BigDecimal-unput was first parsed from String to double (loosing some information), then converted back to String to be then parsed to BigDecimal, now it is parsed only once directly to BigDecimal.

And as a bonus, eclipse/microprofile-graphql#252 would be trivial to implement.

@phillip-kruger
Copy link
Member

phillip-kruger commented May 19, 2020

Hi @ybroeker . Thanks for the explanation. So we should still be able to fix those cases without changing the model. Might be a bit more code, but I think the decision on how the transform work should stay in the impl. We might have to also check if this is a collection and then apply accordingly. W.r.t JUnit, we are waiting on the smallrye parent to release before we should use it. Let me check on that in the mean time.

@ybroeker
Copy link
Contributor Author

ybroeker commented May 19, 2020

So we should still be able to fix those cases without changing the model. Might be a bit more code, but I think the decision on how the transform work should stay in the impl.

Do you see any disadvantages in keeping the information in the model as well?
The respective scalar type is already known there, this just adds the Java type for this scalar type.

The matching type could be searched for at runtime, but I'm not sure if that would make things easier?
Just asking out of interest, it would actually be a fairly simple change, just need to keep a Map of types for each scalar.

We might have to also check if this is a collection and then apply accordingly.

Collections worked correctly before, but there were errors with Array, which are fixed now..

W.r.t JUnit, we are waiting on the smallrye parent to release before we should use it. Let me check on that in the mean time.

JUnit 5 could also be easily reverted, this just makes some things easier.
All previously existing tests with JUnit 4 are not affected by Junit 5 either.

@phillip-kruger
Copy link
Member

Hi @ybroeker - Apologies for taking so long to reply, I am on PTO at the moment, I'll look at this next week.

@phillip-kruger
Copy link
Member

Hey @ybroeker . Can you revert to JUnit 4 and look at the Conflicting files? Once fixed we can merge.

ybroeker added 6 commits May 27, 2020 17:00
Signed-off-by: Yannick Bröker <[email protected]>
* Transform types when a transformation is required instead of keeping a list of types to transform
* Specify concrete types for transformations. Makes code simpler (eg, use
numbers directly instead of formatting->parsing->formatting->parsing) and
more explicit
* Handle chars correctly, char-inputs didn't work before
* Handle BigInteger/BigDecimal correctly, previously those didn't work correctly if formatted (truncated to double or simply failing)
* Handle arrays of formatted types correctly, didn't worked before

* Build a foundation for eclipse/microprofile-graphql#251

Signed-off-by: Yannick Bröker <[email protected]>
@ybroeker ybroeker force-pushed the feat/transformation branch from 6dc0803 to 6c806e1 Compare May 27, 2020 15:06
@phillip-kruger phillip-kruger merged commit 3ac5c98 into smallrye:master May 28, 2020
@phillip-kruger
Copy link
Member

Thanks @ybroeker !

@phillip-kruger phillip-kruger added this to the 1.0.4 milestone May 28, 2020
@ybroeker ybroeker deleted the feat/transformation branch April 6, 2021 13:29
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