Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HotChocolate v13 schema test failed

I received the following error after upgraded HotChocolate GraphQL from v12 to v13 for schema testing.

HotChocolate.SchemaException : For more details look at the Errors property.

Unable to infer or resolve a schema type from the type reference @AuthorizeDirective. It was working in HotChocolate v12, but failed after the upgraded to v13.

[ExtendObjectType(typeof(Query))]
    public class PackageQueries
    {
        [UseResponseHeader]
        [HotChocolate.Authorization.Authorize(Roles = new string[] { "User_Read" })]
        public async Task<List<Package>?> GetPackages(
            [Service] IMyService _MyService
            string packageID,
            CancellationToken cancellationToken)

And the schema test code

ISchema schema = await new ServiceCollection()
                .AddGraphQL()
                .AddQueryType<Query>()
                    .AddTypeExtension<PackageQueries>()
                    .AddTypeExtension<VersionQueries>()                
                .BuildSchemaAsync();

Any idea?

I have tried by AddType<HotChocolate.Authorization.Authorize>(), no success.

like image 804
user21353952 Avatar asked Sep 03 '25 02:09

user21353952


1 Answers

Looks like you need use.AddAuthorization() like this:

ISchema schema = await new ServiceCollection()
                .AddGraphQL()
                .AddQueryType<Query>()
                    .AddTypeExtension<PackageQueries>()
                    .AddTypeExtension<VersionQueries>()
                .AddAuthorization()   // This difference           
                .BuildSchemaAsync();
like image 129
Renat V Avatar answered Sep 05 '25 03:09

Renat V