VOOZH about

URL: https://www.nuget.org/packages/GraphQL.Relay/

⇱ NuGet Gallery | GraphQL.Relay 0.9.1




👁 Image
GraphQL.Relay 0.9.1

dotnet add package GraphQL.Relay --version 0.9.1
 
 
NuGet\Install-Package GraphQL.Relay -Version 0.9.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GraphQL.Relay" Version="0.9.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GraphQL.Relay" Version="0.9.1" />
 
Directory.Packages.props
<PackageReference Include="GraphQL.Relay" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GraphQL.Relay --version 0.9.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GraphQL.Relay, 0.9.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GraphQL.Relay@0.9.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GraphQL.Relay&version=0.9.1
 
Install as a Cake Addin
#tool nuget:?package=GraphQL.Relay&version=0.9.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

GraphQL.Relay

👁 License

👁 CodeQL analysis

👁 codecov

👁 Activity
👁 Activity
👁 Activity

👁 Size

A collection of classes, tools, and utilities for creating Relay.js compatible GraphQL servers in dotnet.

Provides the following packages:

Package Downloads NuGet Latest
GraphQL.Relay 👁 Nuget
👁 Nuget

Usage

Setup

Add the Nuget package:

$> dotnet add package GraphQL.Relay

Ensure your resolver for GraphQL can resolve:

  • ConnectionType<>
  • EdgeType<>
  • NodeInterface
  • PageInfoType

If you're using the resolver from MVC (IServiceProvider), that might look like this:

services.AddTransient(typeof(ConnectionType<>));
services.AddTransient(typeof(EdgeType<>));
services.AddTransient<NodeInterface>();
services.AddTransient<PageInfoType>();

GraphTypes

Included are a few GraphQL types and helpers for creating Connections, Mutations, and Nodes

QueryGraphType

A top level Schema query type, which defines the required node root query;

public class StarWarsQuery : QueryGraphType
{
 public StarWarsQuery() {
 Field<DroidType>(
 "hero",
 resolve: context => new Droid { DroidId = "1", Name = "R2-D2" }
 );
 }
}

public class StarWarsSchema : Schema
{
 public StarWarsSchema() {
 Query = new StarWarsQuery();
 }
}
NodeGraphType<TSource, TOut>, NodeGraphType<TSource>, NodeGraphType

NodeTypes, are ObjectGraphTypes that implement the NodeInterface and provide a GetById method, which allows Relay (via the node() Query) to refetch nodes when it needs to.

Nodes, also provide a convenient Id() method for defining global id fields, derived from the type Name and Id. If your underlying type has a name conflict on the field id, the "local" Id will be prefixed with the type name, e.g. Droid.Id -> droidId

public class Droid
{
 public string DroidId { get; set; }
 public string Name { get; set; }
}

public class DroidType : NodeGraphType<Droid>
{
 public DroidType()
 {
 Name = "Droid";

 Id(d => d.DroidId); // adds an id Field as well as the `Droid` id field

 Field<StringGraphType>("name", "The name of the droid.");
 }

 public override Droid GetById(string droidId) {
 return StarWarsData.GetDroidByIdAsync(droidId);
 }
}
Mutations

Relay mutations specify a few constraints on top of the general GraphQL mutations. To accommodate this, there are mutation specific GraphTypes provided.

MutationGraphType

The top level mutation type attached to the GraphQL Schema

public class StarWarsMutation : MutationGraphType
{
 public StarWarsMutation() {

 Mutation<CreateDroidInput, CreateDroidPayload>("createDroid");
 Mutation<DeleteDroidInput, DeleteDroidPayload>("deleteDroid");
 }
}

public class StarWarsSchema : Schema
{
 public StarWarsSchema() {
 Query = new StarWarsQuery();
 Mutation = new StarWarsMutation();
 }
}
MutationInputGraphType

An simple base class that defines a clientMutationId field. functionally identical to InputObjectGraphType otherwise

MutationPayloadGraphType<TSource, TOut>, MutationPayloadGraphType<TSource>, MutationPayloadGraphType

The output ObjectGraphType containing the mutation payload, functionally similar to an ObjectGraphType with the addition of requiring a MutateAndGetPayload() method used to resolve the payload from the inputs.

public class CreateDroidPayload : MutationPayloadGraphType<DroidPayload, Task<DroidPayload>>
{
 public CreateDroidPayload()
 {
 Name = "CreateDroidPayload";

 Field(
 name: "droid",
 type: typeof(Droid));
 }

 public override async Task<DroidPayload> MutateAndGetPayload(MutationInputs inputs)
 {
 string name = inputs.Get<string>("name");

 Droid newDroid = await StarWarsData.CreateDroidAsync(name)

 return new DroidPayload {
 Droid = newDroid
 };
 }
}

Connections

Luckily GraphQL-dotnet already provides helpful utilities for creating connection fields, on GraphTypes. In addition included here are a few more helpful methods for creating relay compatible Connections from IEnumerables.

Connection.ToConnection(IEnumerable items, ResolveConnectionContext context)

Creates a connection from an existing list of objects.

public class Droid
{
 public string DroidId { get; set; }
 public string Name { get; set; }
 public IEnumerable<Droid> Friends { get; set; }
}

public class DroidType : ObjectGraphType<Droid>
{
 public DroidType()
 {
 Name = "Droid";

 Field<StringGraphType>("name", "The name of the droid.");

 Connection<DroidType>()
 .Name("friends")
 .Resolve(context =>
 ConnectionUtils.ToConnection(c.Source.Friends, context));
 }
}
ConnectionUtils.ToConnection(IEnumerable items, ResolveConnectionContext context, int sliceStartIndex, int totalCount)

Similar to the above, but creates a connection with the correct cursors, when you only have a slice of the entire set of items. Windowing the items based on the arguments.

ConnectionUtils.CursorToOffset(string cursor)

Convert a connection item cursor to the int index of the item in the set.

ConnectionUtils.OffsetToCursor(int offset)

Convert an index offset to a connection cursor.

ResolveConnectionContextExtensions.ToConnection<TSource>(this IResolveConnectionContext context, IQueryable<TSource> items)

Creates a connection from an IQueryable.

public class Droid
{
 public string DroidId { get; set; }
 public string Name { get; set; }
 public IQueryable<Droid> Friends { get; set; }
}

public class DroidType : ObjectGraphType<Droid>
{
 public DroidType()
 {
 Name = "Droid";

 Field<StringGraphType>("name", "The name of the droid.");

 Connection<DroidType>()
 .Name("friends")
 .Resolve(context => context
 .ToConnection(c.Source.Friends));
 }
}
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

NuGet packages (4)

Showing the top 4 NuGet packages that depend on GraphQL.Relay:

Package Downloads
VirtoCommerce.ExperienceApiModule.Core

Experiene API functionality

VirtoCommerce.Exp.ExtensionSamples

Package Description

EPiGraphQL.Api

Plug and play EPiServer GraphQL service

Graphify.EPiServer.Api

Plug and play EPiServer GraphQL service

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.1 90,308 10/11/2022
0.9.0 1,936 10/7/2022
0.8.0 32,797 7/1/2022
0.7.0 1,041 6/27/2022
0.6.2 422,012 7/20/2021
0.5.0 463,369 11/13/2017
0.5.0-alpha.0 1,325 4/15/2018
0.4.1 11,553 1/10/2017
0.4.0 1,754 1/9/2017
0.3.0 1,704 1/9/2017
0.2.0 1,899 1/2/2017
0.1.0-beta4 1,305 12/20/2016
0.1.0-beta3 1,339 12/12/2016
0.1.0-beta2 1,269 12/12/2016
0.1.0-beta1 1,314 11/25/2016