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

Http4s Adapter: use Circe to transform the result to Json #70

Closed
ghostdogpr opened this issue Nov 7, 2019 · 0 comments · Fixed by #71
Closed

Http4s Adapter: use Circe to transform the result to Json #70

ghostdogpr opened this issue Nov 7, 2019 · 0 comments · Fixed by #71
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ghostdogpr
Copy link
Owner

ghostdogpr commented Nov 7, 2019

The current code in Http4sAdapter converts the result to a string, then is parsed into Json. Instead, we could use Circe (which is already in scope in the Http4sAdapter) to convert the result to Json directly. This will take care of edge cases (breaklines, etc) and will be faster.

Here's the existing code:

result <- execute(interpreter, query)
                     .fold(
                       err => s"""{"errors":["${err.toString.replace("\"", "'")}"]}""",
                       result => s"""{"data":$result}"""
                     )
json     <- Task.fromEither(parse(result))

Instead, we can define an Encoder[ResponseValue] and Encoder[ErrorResponse] to convert to Json directly.

@ghostdogpr ghostdogpr added enhancement New feature or request help wanted labels Nov 7, 2019
@ghostdogpr ghostdogpr changed the title Htt4s Adapter: use Circe to transform result to Json Htt4s Adapter: use Circe to transform the result to Json Nov 7, 2019
@ghostdogpr ghostdogpr added the good first issue Good for newcomers label Nov 7, 2019
@ghostdogpr ghostdogpr changed the title Htt4s Adapter: use Circe to transform the result to Json Http4s Adapter: use Circe to transform the result to Json Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant