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

Implement path via PathValue instead of Either[String, Int] for paths #2048

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

kyri-petrou
Copy link
Collaborator

This is more of an experiment just to see what we think.

So, what's wrong with Either[String, Int]? There are 2 things that are kind of wrong with it:

  1. From a UX / dev perspective, It can be unclear on what it means unless you understand the structure of a graphql path
  2. From a performance perspective, it causes unnecessary object allocations and boxing of Ints in the Executor.

With this PR, we substitute the Either[String, Int] with PathValue, a sealed trait that is extended by StringValue and IntValue.IntNumber. In a world where we've all migrated to Scala 3, this could have easily been a type PathValue = StringValue | IntValue.IntNumber but unfortunately we have to make the code compatible with Scala 2 🥲.

I also made a few changes to some of the methods used to parse paths / IntValues from String to avoid wrapping them in Try (which causes boxing) and avoid throwing exceptions as a control flow mechanism

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

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

Love it!

@kyri-petrou kyri-petrou merged commit 2548822 into series/2.x Dec 18, 2023
10 checks passed
@kyri-petrou kyri-petrou deleted the path-value branch December 18, 2023 02:51
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