Skip to content

Can't compile crate with "the trait IntoResolvable<'_, _, _, _> is not implemented for Result<MyType, FieldError>" error #1097

Open
@Occhioverde

Description

@Occhioverde

Describe the bug

The compile-time the trait `IntoResolvable<'_, _, _, _>` is not implemented for `Result<GitRepo, FieldError>` error is thrown by the #[graphql_object] macro when trying to return a struct with complex fields wrapped in a FieldResul.

Example code

The following is a snippet from my project that throws the compile-time error I mentioned before. Just in case it can be meaningful, the Repo struct annotated as the type of the repo field in GitRepo is not a GraphQL Object.

The first line is marked as the one from which the error is originating:

#[graphql_object(context = GQContext)]
impl Query {
    async fn repo(path: String, context: &GQContext) -> FieldResult<GitRepo> {
        get_by_path(&path, &context.authdata, &context.db).await
    }
}

pub struct GitRepo {
    repo: Repo,
}

#[graphql_object(context = GQContext)]
impl GitRepo {
    pub fn id(&self) -> String {
        self.repo.id.to_string()
    }
}

pub async fn get_by_path(path: &String, authdata: &AuthData, db: &DbCon) -> FieldResult<GitRepo> {
    // -- snip --
}

Expected behavior

The code should compile just like the following does:

#[graphql_object(context = GQContext)]
impl Query {
    async fn repo(path: String, context: &GQContext) -> FieldResult<GitRepo> {
        get_by_path(&path, &context.authdata, &context.db).await
    }
}

#[derive(GraphQLObject)]
pub struct GitRepo {
    id: String,
}

pub async fn get_by_path(path: &String, authdata: &AuthData, db: &DbCon) -> FieldResult<GitRepo> {
    // -- snip --
}

Metadata

Metadata

Assignees

Labels

enhancementImprovement of existing features or bugfix

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions