Skip to content

DataLoader generated source does not include fully qualified type of resultMap, causing build error #8264

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

Closed
svihpinc opened this issue Apr 26, 2025 · 1 comment · Fixed by #8265

Comments

@svihpinc
Copy link
Contributor

svihpinc commented Apr 26, 2025

Product

Hot Chocolate

Version

15.1.3

Link to minimal reproduction

https://github.com/svihpinc/-HotChocolateDataLoaderGenerationIssueRepro

Steps to reproduce

  1. In a solution, create project-1 which uses HotChocolate
  2. Create a project-2 with a name - lets say - Orders
  • Lets say this contains our Order Model under the Models/Order.cs file
  1. In project-1, create a dataloader in Schemas/Orders/OrderDataLoader.cs
  2. In project-1, create the ObjectType for Order model and a Query class that uses the dataloader from above

What is expected?

No errors during build

What is actually happening?

Error:

GreenDonutDataLoader.735550c.g.cs(49,88): Error CS0234 : The type or namespace name 'Models' does not exist in the namespace 'HotChocolateDataLoaderGenerationIssueRepro.Schema.Orders' (are you missing an assembly reference?)

Relevant log output

Additional context

Here's the generated OrdersByIdDataLoader class:

// <auto-generated/>

#nullable enable
#pragma warning disable

using System;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
using GreenDonut;

namespace HotChocolateDataLoaderGenerationIssueRepro.Schema.Orders
{
    public interface IOrdersByIdDataLoader
        : global::GreenDonut.IDataLoader<global::System.Guid, global::Orders.Models.Order>
    {
    }

    public sealed partial class OrdersByIdDataLoader
        : global::GreenDonut.DataLoaderBase<global::System.Guid, global::Orders.Models.Order>
        , IOrdersByIdDataLoader
    {
        private readonly global::System.IServiceProvider _services;

        public OrdersByIdDataLoader(
            global::System.IServiceProvider services,
            global::GreenDonut.IBatchScheduler batchScheduler,
            global::GreenDonut.DataLoaderOptions options)
            : base(batchScheduler, options)
        {
            _services = services ??
                throw new global::System.ArgumentNullException(nameof(services));
        }

        protected override async global::System.Threading.Tasks.ValueTask FetchAsync(
            global::System.Collections.Generic.IReadOnlyList<global::System.Guid> keys,
            global::System.Memory<GreenDonut.Result<global::Orders.Models.Order?>> results,
            global::GreenDonut.DataLoaderFetchContext<global::Orders.Models.Order> context,
            global::System.Threading.CancellationToken ct)
        {
            await using var scope = _services.CreateAsyncScope();
            var p1 = scope.ServiceProvider.GetRequiredService<global::Orders.Services.OrdersContext>();
            var temp = await global::HotChocolateDataLoaderGenerationIssueRepro.Schema.Orders.OrderDataLoader.GetOrdersById(keys, p1, ct).ConfigureAwait(false);
            CopyResults(keys, results.Span, temp);
        }

        private void CopyResults(
            global::System.Collections.Generic.IReadOnlyList<global::System.Guid> keys,
            global::System.Span<GreenDonut.Result<global::Orders.Models.Order?>> results,
            global::System.Collections.Generic.IReadOnlyDictionary<System.Guid, Orders.Models.Order> resultMap)
                                                                                 // ^ no global:: added here
        {
            for (var i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                if (resultMap.TryGetValue(key, out var value))
                {
                    results[i] = global::GreenDonut.Result<global::Orders.Models.Order?>.Resolve(value);
                }
                else
                {
                    results[i] = global::GreenDonut.Result<global::Orders.Models.Order?>.Resolve(default(global::Orders.Models.Order));
                }
            }
        }
    }
}
@svihpinc
Copy link
Contributor Author

I would like to work on this, please.

Thanks

svihpinc added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue Apr 26, 2025
svihpinc added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue Apr 26, 2025
svihpinc added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue May 3, 2025
svihpinc added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue May 3, 2025
@michaelstaib michaelstaib added this to the HC-15.1.4 milestone May 9, 2025
michaelstaib added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue May 15, 2025
michaelstaib added a commit to svihpinc/hotchocolate-graphql-platform that referenced this issue May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants