An open API service indexing awesome lists of open source software.

https://github.com/jacobjmarks/typeextensionprojectiondemo


https://github.com/jacobjmarks/typeextensionprojectiondemo

Last synced: 11 months ago
JSON representation

Awesome Lists containing this project

README

          

# Stub application for [Issue 4183](https://github.com/ChilliCream/hotchocolate/issues/4183)

`/MyEntity.cs`
``` csharp
public class MyEntity
{
public int Id { get; set; }
}
```

`/MyEntityTypeExtension.cs`
``` csharp
[ExtendObjectType(typeof(MyEntity))]
public class MyEntityTypeExtension
{
public IEnumerable GetMyList() => new List { "foo", "bar" };
}
```

`/MyDbContext.cs`
``` csharp
public class MyDbContext : DbContext
{
public DbSet MyEntities { get; set; } = null!;

public MyDbContext(DbContextOptions options) : base(options) { }
}
```

`/Query.cs`
``` csharp
public class Query
{
[UseDbContext(typeof(MyDbContext))]
[UseProjection]
public IQueryable GetMyEntities([ScopedService] MyDbContext dbContext) => dbContext.MyEntities;
}
```

`/Program.cs`
``` csharp
var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureServices((webHost, services) =>
{
services.AddPooledDbContextFactory(builder =>
{
builder.UseInMemoryDatabase(databaseName: "MyDatabase");
});

services.AddGraphQLServer()
.AddQueryType()
.AddTypeExtension()
.AddProjections();
});

var app = builder.Build();

app.UseRouting();

app.UseEndpoints(e => e.MapGraphQL());

app.Run();
```