async-graphql icon indicating copy to clipboard operation
async-graphql copied to clipboard

Additional control over resolver arguments

Open meh opened this issue 3 years ago • 5 comments

Description of the feature

I'd like to be able to tell if a resolver argument was passed or explicitly set to null.

Code example (if possible)

async fn update(&self, foo: Parameter<i32>, bar: Parameter<Input>)

Now this Parameter would be equivalent to Option, but for the sake of clarity it's a different enum.

This means that in the case of Parameter<Option<T>> I can discern between a parameter not being passed, a null, and a value.

This might be possible to handle by abusing default but I'm not entirely sure about the semantics in that case, and a Parameter type would make that clearer.

I need this to implement decent partial updates to objects.

meh avatar Dec 22 '21 15:12 meh

You should have a look at MaybeUndefined<T>. You can see more information about how it works here.

oscartbeaumont avatar Dec 22 '21 15:12 oscartbeaumont

That's exactly what I wanted :panda_face:

meh avatar Dec 22 '21 15:12 meh

It also took me a while to find when I ran into the same use case as you have.

@sunli829 Is MaybeUndefined<T> included in the async-graphql book website? Because if it is missing from the website I can do a PR to add a section about it so it is easier to find.

oscartbeaumont avatar Dec 22 '21 15:12 oscartbeaumont

@oscartbeaumont I am so happy that you can help me add this to the book. 🙂

sunli829 avatar Dec 23 '21 11:12 sunli829

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 11 '22 02:09 github-actions[bot]