In many cases, it might be desired to perform some aditional action before or after some field is resolved. Most common use-case could be authorization of user.
Hooks are special kind of functions added to field with @Before
or @After
decorator.
@Before
and @After
hooksLet's say we want to send informations about useage of some field of our graphql api to analitycs server. We could achieve that with:
Arguments passed to resolver are exactly the same, as ones passed to native graphql resolver funtion. Signature of a @Before hook function is
for @After, it is:
In case, we'd like to add id of removed user to logs, we'd change our code to: