question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Directive types for validations attributes do not work anymore

See original GitHub issue

Is 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:closed
  • Created 7 months ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
erwan-jolycommented, Mar 2, 2023

Thanks @atykhyy seems to works fine 😃

1reaction
michaelstaibcommented, Mar 2, 2023

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 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Form validation issues when using form input directive - ...
I have been trying to build a form input directive which will generate a form input based on the model and the model...
Read more >
Angular 4 Forms: Validation and Nesting
In this article, you will learn how you can work with forms and perform form validation with ease in your Angular application. There...
Read more >
Angular Custom Form Validators: Complete Guide
All about custom form validators, including synchronous and asynchronous, field-level, form-level, for both template-driven and reactive forms.
Read more >
Validating form input
Angular uses directives to match these attributes with validator ... The same built-in validators that are available as attributes in template-driven forms, ...
Read more >
Directives - Hot Chocolate - ChilliCream GraphQL Platform
Directives provide a way to add metadata for client tools such as code generators and IDEs or alternate a GraphQL server's runtime execution ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found