ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.22k stars 742 forks source link

Spatial Projections not resolving #3714

Closed PHILLIPS71 closed 3 years ago

PHILLIPS71 commented 3 years ago

Describe the bug I've been following the documentation found here (https://chillicream.com/docs/hotchocolate/integrations/), which seems to be outdated as the package HotChocolate.Spatial does not exist. I've installed HotChocolate.Types.Spatial instead which seems to work fine when creating spatial objects via GraphQL, I'm running into issues when I'm projecting a Polygon object.

Doing so returning the following error:

      "extensions": {
        "message": "Type 'NetTopologySuite.Geometries.Polygon' does not have a default constructor (Parameter 'type')",
        "stackTrace": "   at System.Linq.Expressions.Expression.New(Type type)\r\n   at HotChocolate.Data.Projections.Expressions.ProjectionExpressionBuilder.CreateMemberInit(Type type, IEnumerable`1 expressions)\r\n   at 
HotChocolate.Data.Projections.Expressions.Handlers.QueryableProjectionFieldHandler.TryHandleLeave(QueryableProjectionContext context, ISelection selection, ISelectionVisitorAction& action)\r\n   at 
HotChocolate.Data.Projections.ProjectionVisitor`1.Leave(ISelection selection, TContext context)\r\n   at 
HotChocolate.Data.Projections.SelectionVisitor`1.Visit(ISelection selection, TContext context)\r\n   at 
HotChocolate.Data.Projections.ProjectionVisitor`1.Visit(ISelection selection, TContext context)\r\n   at 
HotChocolate.Data.Projections.SelectionVisitor`1.VisitChildren(IOutputField field, TContext context)\r\n   at 
HotChocolate.Data.Projections.SelectionVisitor`1.Visit(IOutputField field, TContext context)\r\n   at 
HotChocolate.Data.Projections.ProjectionVisitor`1.Visit(IOutputField field, TContext context)\r\n   at 
HotChocolate.Data.Projections.ProjectionVisitor`1.Visit(TContext context)\r\n   at 
HotChocolate.Data.Projections.Expressions.QueryableProjectionProvider.<CreateExecutor>g__ExecuteAsync|2_1[TEntityType](FieldDelegate next, IMiddlewareContext context)\r\n   at 
HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)\r\n   at 
HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n   at 
HotChocolate.Data.ToListMiddleware`1.InvokeAsync(IMiddlewareContext context)\r\n   at 
HotChocolate.Types.EntityFrameworkObjectFieldDescriptorExtensions.<>c__DisplayClass2_1`1.<<UseDbContext>b__4>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at 
HotChocolate.Types.EntityFrameworkObjectFieldDescriptorExtensions.<>c__DisplayClass2_1`1.<<UseDbContext>b__4>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at 
FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n   at 
HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n   at 
HotChocolate.AspNetCore.Authorization.AuthorizeMiddleware.InvokeAsync(IDirectiveContext context)\r\n   at 
HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n   at 
HotChocolate.Execution.Processing.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n   at 
HotChocolate.Execution.Processing.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
      }

According to the documentation I need to add a special handler .AddSpatialProjections() but the definition does not exist

Versions HotChocolate.AspNetCore v11.2.2 HotChocolate.Types.Spatial v11.2.2 HotChocolate.Data.Spatial v11.2.2 Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite v5.0.6

Model

    public class MapAsset
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [ID(nameof(Map))]
        public int MapId{ get; set; }

        public Polygon Polygon { get; set; }
    }

Query

        [Authorize]
        [UseDbContext(typeof(PlatformContext))]
        [UsePaging]
        [UseProjection]
        [UseFiltering]
        [UseSorting]
        public IQueryable<MapAsset> MapAssets([ScopedService] PlatformContext database)
        {
            return database.MapAssets;
        }
PascalSenn commented 3 years ago

https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Spatial/src/Data/Projections/Extensions/SpatialProjectionsRequestExecutorBuilderExtensions.cs That should do:

using HotChocolate;
....
servcies
    .AddGraphQLServer()
   ...
   .AddProjections()
   .AddSpatialProjections()