GraphQL.AutoUnions.OneOf
1.0.0-beta.1
See the version list below for details.
dotnet add package GraphQL.AutoUnions.OneOf --version 1.0.0-beta.1
NuGet\Install-Package GraphQL.AutoUnions.OneOf -Version 1.0.0-beta.1
<PackageReference Include="GraphQL.AutoUnions.OneOf" Version="1.0.0-beta.1" />
paket add GraphQL.AutoUnions.OneOf --version 1.0.0-beta.1
#r "nuget: GraphQL.AutoUnions.OneOf, 1.0.0-beta.1"
// Install GraphQL.AutoUnions.OneOf as a Cake Addin #addin nuget:?package=GraphQL.AutoUnions.OneOf&version=1.0.0-beta.1&prerelease // Install GraphQL.AutoUnions.OneOf as a Cake Tool #tool nuget:?package=GraphQL.AutoUnions.OneOf&version=1.0.0-beta.1&prerelease
[BETA] GraphQL.AutoUnions.OneOf
A library that adds support for auto schema with discriminated unions when using the OneOf library.
Problem
GraphQL is an awesome technology for building APIs, but it can be tricky to define complex types with unions and interfaces, especially when you're using .NET Core. It can be difficult to create a schema that's easy to understand, and it often requires a lot of boilerplate code.
Our library is here to help! We provide an easy way to define discriminated unions in your GraphQL schema using the popular OneOf library. This library is specifically designed to be used with AddAutoSchema
from the GraphQL package.
With our library, you can define your discriminated unions in C# using the OneOf library, and then automatically generate the corresponding GraphQL schema and resolvers using AddAutoSchema
from the GraphQL
package. Our goal is to make it easy for developers to work with discriminated unions in their GraphQL APIs, without having to worry about the details. Whether you're building a new project or adding features to an existing one, our library can help you save time and effort.
Usage
To use this library, you first need to install it using NuGet:
dotnet add package GraphQL.AutoUnions.OneOf
Once you have installed the package, you can use it in your .NET Core project. Here's an example of how to use this library:
using GraphQL;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGraphQL((gqlBuilder) =>
{
gqlBuilder.AddOneOfAutoUnions();
gqlBuilder.AddAutoSchema<ProductQuery>();
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseGraphQL();
}
}
public class ProductQuery
{
public static IEnumerable<ProductUnion> Products([FromServices] IProductService productService)
{
return productService.GetProducts();
}
}
[GenerateOneOf]
public partial class ProductUnion : OneOfBase<Book, Electronic>
{
}
public class Book
{
public int Id { get; set; }
public string Name { get; set; }
public string Author { get; set; }
public int PageCount { get; set; }
}
public class Electronic
{
public int Id { get; set; }
public string Name { get; set; }
public float Price { get; set; }
public string Description { get; set; }
}
public interface IProductService
{
IEnumerable<ProductUnion> GetProducts();
}
This code will generate the following schema:
type Book {
id: Int!
name: String!
author: String!
pageCount: Int!
}
type Electronic {
id: Int!
name: String!
price: Float!
description: String!
}
union ProductUnion = Book | Electronic
type Query {
products: [ProductUnion!]!
}
License
This library is released under the Apache 2 License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- GraphQL.AutoUnions (>= 1.0.0-beta.0)
- OneOf (>= 3.0.160)
- OneOf.SourceGenerator (>= 3.0.184)
-
.NETStandard 2.0
- GraphQL.AutoUnions (>= 1.0.0-beta.0)
- OneOf (>= 3.0.160)
- OneOf.SourceGenerator (>= 3.0.184)
-
.NETStandard 2.1
- GraphQL.AutoUnions (>= 1.0.0-beta.0)
- OneOf (>= 3.0.160)
- OneOf.SourceGenerator (>= 3.0.184)
-
net5.0
- GraphQL.AutoUnions (>= 1.0.0-beta.0)
- OneOf (>= 3.0.160)
- OneOf.SourceGenerator (>= 3.0.184)
-
net6.0
- GraphQL.AutoUnions (>= 1.0.0-beta.0)
- OneOf (>= 3.0.160)
- OneOf.SourceGenerator (>= 3.0.184)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta.3 | 138 | 3/20/2023 |
1.0.0-beta.2 | 94 | 3/18/2023 |
1.0.0-beta.1 | 86 | 3/13/2023 |