Skip to content

Feature Request: Directive Visitors / Resolvers #299

Closed
@zimzat

Description

@zimzat

There's currently a lack of examples showing how to check for directives in resolvers for each location, whether the Schema or Query type. There doesn't seem to be any way to hook into schema directives, such as during the build step, and query directives seem to require manually implementing into each defaultResolver/fieldResolver/resolve function with no way to easily chain functionality or creating a global resolver to intercept every other resolver first, which seems a bit cumbersome. Am I missing something?

It would be nice to have a way to implement directives as visitors, promises, or other helpers. Implementing @skip, @include, and @deprecated in this way would be a good first step and provide a guide for implementing custom directives.

For reference the Apollo Server Directive implementation uses visitors and chaining resolver promises.

If a schema visitor during the build process and query resolve chain for the execution process sounds reasonable then I could put some time into implementing those (e.g. like Apollo), but if you have another idea on how to implement those or don't feel like it should be part of the library I'm open to alternates.

For my current usage I'm trying to implement a Query / Mutation directive to set the account context to be used for that execution. I've considered putting in the URL (which would have to be done for multiple graph endpoints, public/admin/employee for every account, but might be arguably easier for the client), adding an argument to every relevant field / object, putting it in filter parameters (which could get messy / disconnected for child/sibling filters), or a secondary request Header (this might be the way I end up going until I can get a better way to handle it with directives).

I'd also like to consider using schema directives for excluding/including specific objects definitions or fields based on the endpoint used (merging public/admin/employee type language files), but currently that's not an option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions