Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directive middleware not invoked for input objects #2217

Closed
willwolfram18 opened this issue Aug 11, 2020 · 1 comment
Closed

Directive middleware not invoked for input objects #2217

willwolfram18 opened this issue Aug 11, 2020 · 1 comment
Assignees
Milestone

Comments

@willwolfram18
Copy link
Contributor

Describe the bug
When creating a custom directive that is used on input objects types, the middleware registered for said custom directive is never invoked.

To Reproduce

  1. Define a custom directive.
public class OneFieldDirective : DirectiveType
{
    protected override void Configure(IDirectiveTypeDescriptor descriptor)
    {
        descriptor.Name("oneField");
        descriptor.Description("Indicates only one field is allowed.");
        descriptor.Location(DirectiveLocation.InputObject);

        descriptor.Use(next => context =>
        {
            Console.WriteLine("This is never executed");
            return next?.Invoke(context);
        });
    }
}
  1. Register the directive on an input object type
public class MyInputType : InputObjectType
{
    protected override void Configure(IInputObjectTypeDescriptor descriptor)
    {
        descriptor.Field("searchCriteria1").Type<StringType>();
        descriptor.Field("searchCriteria2").Type<StringType>();

        descriptor.Directive<OneFieldDirective>();
    }
}
  1. Use the input type on a query
  2. Register the types
  3. Run the app and submit a query that uses the input object type.

Expected behavior
The middleware for the custom directive is invoked.

Desktop (please complete the following information):

  • OS: MacOS Catalina 10.15.2, Windows 10

Additional context
My team is currently trying to evaluate ways we could implement a query that allows locating a single record by multiple lookup types e.g. record id, or various other Ids that might tie to the specific record. One idea we are trying to explore was implementing something similar to the @oneField/@oneOf suggestion for handling input unions as a GraphQL standard. Since the directive approach is one that is theoretically feasible to implement now, or team tried this out in our GraphQL app but found that the middleware for the directive is never invoked.

If there is any guidance that can be provided for another workaround that can be implemented with the current Hot Chocolate versions in the meantime that would be greatly appreciated! Thank you so much for your time and reviewing the issue!

@PascalSenn
Copy link
Member

This is not supported unfortunately
https://hotchocolate.io/docs/directives

A directive middleware is only added to a field middleware pipeline when the directive was annotated to the object definition, the field definition or the field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants