Skip to content

IntoFieldResult for anyhow::Error #988

Closed
@samuela

Description

@samuela

Is your feature request related to a problem? Please describe.
anyhow is a dominant error handling library for rust. Currently, there is no convenient way to use anyhow Errs in juniper code. For example,

struct Mutation;

#[juniper::graphql_object]
impl Mutation {
  async fn Foo(line_number: i32) -> FieldResult<bool> {
    anyhow::ensure!(line_number >= 0);
    Ok(true)
  }
}

doesn't work.

IntoFieldResult offers a way of translating custom error types into FieldResults, but unfortunately implementing IntoFieldResult for anyhow::Error is not possible due to https://doc.rust-lang.org/error-index.html#E0117.

Side note: why is there IntoFieldResult instead of simply Into<FieldResult>?

Describe the solution you'd like
Not 100% clear what the exact solution ought to be, but I think just implementing IntoFieldResult for anyhow::Error would do the trick.

Describe alternatives you've considered
n/a

Additional context
n/a

Metadata

Metadata

Assignees

Labels

featureNew feature or requestk::apiRelated to API (application interface)k::integrationRelated to integration with third-party libraries or systemslib::anyhowRelated to `anyhow` crate integration

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions