https://github.com/jacobjmarks/typeextensionprojectiondemo
https://github.com/jacobjmarks/typeextensionprojectiondemo
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobjmarks/typeextensionprojectiondemo
- Owner: jacobjmarks
- Created: 2021-09-03T11:51:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-28T02:45:48.000Z (over 4 years ago)
- Last Synced: 2025-01-15T23:42:42.878Z (about 1 year ago)
- Language: C#
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
```