Directive types for validations attributes do not work anymore
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
Hello there, since I updated to HotChocolate 13 I’m getting this error at startup. I’m aware there are changes around directives.
What I’m trying to achieve here is to get directives for my validation attributes so my frontend can generate yup(frontend validation) for those.
Not sure if that’s the best way to achieve such a thing but I’m relying on the method I explained there: https://medium.com/@erwanjoly_55953/hotchocolate-graphql-validation-with-validationattribute-yup-373e830dd547
only difference is that I had to replace
var typeref = completionContext.TypeInspector.GetTypeRef(attribute.GetType());
field.Directives.Add(new DirectiveDefinition(attribute, typeref));
by
field.AddDirective(attribute, completionContext.TypeInspector);
I’m pretty sure it’s irrelevant as I get the same error without the interceptor.
Now I upgraded to 13.0.2 I’m getting an error. Is there anyway way to solve this ?
Steps to reproduce
Declare a directive type from EmailAddressAttribute
public class EmailAddressDirective : DirectiveType<EmailAddressAttribute>
{
protected override void Configure(IDirectiveTypeDescriptor<EmailAddressAttribute> descriptor)
{
descriptor.Name("emailAddress");
descriptor.Location(DirectiveLocation.InputFieldDefinition | DirectiveLocation.ArgumentDefinition | DirectiveLocation.FieldDefinition);
descriptor.Ignore(dt => dt.RequiresValidationContext);
descriptor.Ignore(dt => dt.ErrorMessageResourceName);
descriptor.Ignore(dt => dt.CustomDataType);
}
};
Relevant log output
System.InvalidOperationException : No compatible constructor found for input type type `System.ComponentModel.DataAnnotations.EmailAddressAttribute`.
Either you have to provide a public constructor with settable properties or a public constructor that allows to pass in values for read-only properties. There was no way to set the following properties: dataType.
Additional Context?
No response
Version
13.0.2
Issue Analytics
- State:
- Created 7 months ago
- Comments:14 (14 by maintainers)
Top GitHub Comments
Thanks @atykhyy seems to works fine 😃
It really amazes me in all our interactions how deep you have drilled into Hot Chocolate @atykhyy! Especially since most of this is not documented 😄