Comments (7)
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.
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.
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.
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.
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.
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)
- Support callback protocol for subscription HOT 2
- SDL only includes directives when `.federation()` is enabled. HOT 2
- Bug: Axum 0.7.2 integration trait implementation HOT 2
- [Question] I'm having an error requesting a lifetime on the macro [#Object] HOT 2
- `.sdl()` include anonymous lifetime on custom scalar and generate invalid GraphQL. HOT 1
- How can we use methods outside of graphql request context? HOT 3
- Stack overflow at `Schema::new()` when generic type's method returns self
- Consider disable the default features in Axum
- Better documentation HOT 3
- Async-graphql actix_web subscriptions don't work HOT 1
- Share data between guard and resolver HOT 2
- Add #[graphql(optional)] for fields (provde less boilerplate and more correctness) HOT 2
- async-graph-axum 7.0.0 only works with axum 0.7.0
- Cannot use string to publish to async channel HOT 3
- How to extract the query name in middleware HOT 3
- Disable introspection, returns null in __typename--Dynamic Schema
- How to view the graphql endpoint in Apollo studio explorer? HOT 2
- How do you create a model that doesn't have hardcoded values? HOT 1
- Adjust `#[allow(clippy::all)]` in macro expansions to not override `clippy::disallowed_macros` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.