Code Monkey home page Code Monkey logo

Comments (7)

ashmarchington avatar ashmarchington commented on June 2, 2024 2

If you wrap your resolver response in Option I believe this works.

async fn bar(&self) -> Option<Result<String>> {
    Some(Err("Some error".into()))
}

At least it has been working for my project.

from async-graphql.

NfNitLoop avatar NfNitLoop commented on June 2, 2024

Well, today I learned that the "bug" behavior I'm seeing is actually defined in the GraphQL specification:

If an error was raised during the execution that prevented a valid response, the data entry in the response should be null.

And ascync_graphql is advertised as:

a high-performance graphql server library that's fully specification compliant

So, I suppose this is not a bug. It just differs than multiple GraphQL server implementations I've used before, so was surprising.

from async-graphql.

NfNitLoop avatar NfNitLoop commented on June 2, 2024

Oops, nevermind, the spec goes on to say:

If a field error is raised, execution attempts to continue and a partial result is produced (see Handling Field Errors). The data entry in the response must be present. The errors entry should include all raised field errors.

and:

If a field error is raised while resolving a field, it is handled as though the field returned null, and the error must be added to the "errors" list in the response.

So, async_graphql is, AFAICT, not currently "fully specification compliant".

from async-graphql.

NfNitLoop avatar NfNitLoop commented on June 2, 2024

I tried that as well, and got the same error. Maybe I'm on an older version. I'll update and try again.

from async-graphql.

Miaxos avatar Miaxos commented on June 2, 2024

As @ashmarchington said, if you want to have a null here it would means that the type of foo and the type of bar should be Nullable, but in async-graphql to have a Nullable type, you must return Option<T>.

When you return Result<String> it means that the inferred type should be a Non-Nullable<String> for GraphQL, but it may fail and if it fails, it'll bubble up the error.

So here, if you change it by Option<Result<String>> it will work.

from async-graphql.

NfNitLoop avatar NfNitLoop commented on June 2, 2024

Came back to test this. Created a repository where I can reproduce this issue:
NfNitLoop/async-graphql-bug-1449@5563f45

But then I re-read @Miaxos's comment, suggesting Option<Result<T>> and I tried that. Sure enough, it works:
NfNitLoop/async-graphql-bug-1449@e1531a5#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR20-R23

But -- why would that work and not Result<Option<T>>? That seems to be the more "correct" type in my mind. It also allows you to use ? for error handling, where Option<Result<T>> does not.

IMO it's a bug that these don't work the same way. Or at a minimum, a really big foot-gun.

from async-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.