1

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.

1 Answers1

1

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

ISchema schema = await new ServiceCollection()
                .AddGraphQL()
                .AddQueryType<Query>()
                    .AddTypeExtension<PackageQueries>()
                    .AddTypeExtension<VersionQueries>()
                .AddAuthorization()   // This difference           
                .BuildSchemaAsync();
Renat V
  • 39
  • 2
  • For others having the same issue, make sure authorization is added when configuring the graphQL and if added change the order of the line. – Indunil Withana Jul 18 '23 at 09:24