All Projects → autoguru-au → graphql-dotnet-relay

autoguru-au / graphql-dotnet-relay

Licence: MIT License
Relay support for graphql-dotnet

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to graphql-dotnet-relay

graphql-pynamodb
Graphene PynamoDB Integration
Stars: ✭ 63 (+384.62%)
Mutual labels:  relay, graphql-server
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+147323.08%)
Mutual labels:  relay, graphql-server
Hotchocolate
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.
Stars: ✭ 3,009 (+23046.15%)
Mutual labels:  graphql-server, graphql-dotnet
Create Graphql
Command-line utility to build production-ready servers with GraphQL.
Stars: ✭ 441 (+3292.31%)
Mutual labels:  relay, graphql-server
DotNetGraphQL
A sample demonstrating how to create a GraphQL Backend in .NET and consume it from a .NET mobile app created using Xamarin
Stars: ✭ 78 (+500%)
Mutual labels:  graphql-server, graphql-dotnet
Lighthouse Utils
An add-on to Lighthouse to auto-generate CRUD actions from types https://github.com/nuwave/lighthouse
Stars: ✭ 26 (+100%)
Mutual labels:  relay, graphql-server
Graphql Up
Get a ready-to-use GraphQL API for your schema
Stars: ✭ 415 (+3092.31%)
Mutual labels:  relay, graphql-server
koa-server
🗄️ GraphQL Back-end Server with Relay, Koa, MongoDB and Mongoose
Stars: ✭ 31 (+138.46%)
Mutual labels:  relay, graphql-server
relay-compiler-plus
Custom relay compiler which supports persisted queries
Stars: ✭ 68 (+423.08%)
Mutual labels:  relay, graphql-server
mimicsocks
just another TCP proxy
Stars: ✭ 14 (+7.69%)
Mutual labels:  relay
now-course
Proyecto para el curso de Now.sh en Platzi
Stars: ✭ 19 (+46.15%)
Mutual labels:  graphql-server
fullstack-graphql-angular
Simple Fullstack GraphQL Application with Angular CLI + Redux. API built with Typescript + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with Angular CLI + Redux + Async Middleware to access the API.
Stars: ✭ 67 (+415.38%)
Mutual labels:  graphql-server
react-relay-pokemon
Use React & Relay as your Pokedex!
Stars: ✭ 88 (+576.92%)
Mutual labels:  relay
web-haskell-graphql-postgres-boilerplate
Modern webserver in Haskell: Graphql + Postgresql + Authentication + DB migration + Dotenv and more
Stars: ✭ 114 (+776.92%)
Mutual labels:  graphql-server
subscription-graphql
Subscription POC with graphql and relay
Stars: ✭ 18 (+38.46%)
Mutual labels:  relay
AzuraRelay
A "relay in a box" containing a lightweight web application and Icecast servers that can connect to and relay an AzuraCast parent instance.
Stars: ✭ 20 (+53.85%)
Mutual labels:  relay
swifitch-software
Software for SWIFITCH HW
Stars: ✭ 12 (-7.69%)
Mutual labels:  relay
ngraphql
GraphQL .NET Server and Client
Stars: ✭ 26 (+100%)
Mutual labels:  graphql-server
esbuild-plugin-relay
An esbuild plugin to transform tagged GraphQL template literals for Relay.
Stars: ✭ 14 (+7.69%)
Mutual labels:  relay
vite-plugin-relay
A vite plugin for Relay
Stars: ✭ 44 (+238.46%)
Mutual labels:  relay

graphql-dotnet-relay

⚠️ Disclaimer

AutoGuru no longer use graphql-dotnet in our GraphQL stack.

As such we're no longer actively maintaining it ourselves.

This library provides useful bits for graphql-dotnet based servers to add relay support.

Features

Node support

Relay requires that:

  1. all queryable types in your graph implement a base type Node, and
  2. are queryable via query fields of form node(id: ID!) and nodes(ids: [ID!]!).

We offer two classes to make this easy for you.

QueryGraphType

Use this as the base for your root query field you attach to your schema and It'll add the node and nodes fields mentioned above.

NodeGraphType<TSourceType, TId>

Use this as the base for your own types, instead of ObjectGraphType<TSourceType> and it'll add two fields, id and dbId (where id is the Relay-spec compliant field required by all Node types, and dbId is your own internal id for that type, that you may need for displaying in your UI).

ID support

Translations

Although an ID is great for Relay, it's not great for humans or for use in our internal code. Furthermore, once you jump on the Relay train, you'll want to replace all your id-referencing field arguments with ID!

That causes a few issues:

  1. How can I query for data when dev'ing without first getting the global ID?
    1. Similarly, I want my website's URLs to contain my friendlier id, like /blog/1, how can I call graph with that without first translating that into a global ID?
  2. How can I migrate to Relay support gradually without all my clients breaking by passing 1 or "1"?
  3. How can I deserialize a global ID in my resolver to a value I understand internally to resolve my data?

To make this easier, we:

  1. Hookup wiring to support parsing string or TId into a ID, so you can safely pass "1" or 1 in place of a real global ID.
  2. Provide extension methods you can use in your resolver to read global IDs into the real id you know and love.

There's also a GlobalIdParser if you ever need to work with global IDs yourself.

Strongly-typed ID classes

We offer some built-in types for variations of global IDs (e.g. GuidGlobalId, IntGlobalId, LongGlobalId, StringGlobalId) so that you can read a complex field argument as a DTO class and use properties like IntGlobalId.

AutoMapper converters

If you're using AutoMapper to translate between say an InputDto and another type, you can have a DTO with a IntGlobalId property and map that to a type with an int property.

NewtonsoftJson converters

Similar to above but for NewtonsoftJson. Call JsonSerializerFactory.Create() to get a serializer that can read/write these ID-types into the equivalent BCL type to work with. Or use them like you would any other Newtonsoft.Json converter.

FluentValidation integration

If you're using FluentValidation, you can validate a strongly-typed global ID class's value like so:

RuleFor(x => x.Id).ValidGlobalId()

JSResource field

WIP

Usage

Note: Versions 1.x are for GraphQL 2.4.0. Versions 2.x are for GraphQL 3.0.0-preview-x

Install from NuGet:

> dotnet add package GraphQL.RelaySupport
> dotnet add package GraphQL.RelaySupport.AutoMapped
> dotnet add package GraphQL.RelaySupport.FluentValidation
> dotnet add package GraphQL.RelaySupport.NewtonsoftJson
> dotnet add package GraphQL.RelaySupport.Core

In your Startup.cs:

  1. Call services.AddRelaySupport();
  2. For AutoMapper support, include our profile when registering it, services.AddAutoMapper(..., typeof(GlobalIdsProfile))

Update your root Query type to inherit from QueryGraphType.

For each of your relevant graph types:

  1. Inherit from NodeGraphType<TSourceType, TId>, specifying TId as the type you use internally, e.g. int.
  2. Call base constructor, passing an idSelector func, e.g. myType => myType.Id.
  3. Implement the abstract GetByIdAsync method, which will receive the real database id of your type.

In your field resolvers:

  • If you want an id/s argument, use context.GetIntIdFromGlobalIdArgument("argName") or relevant overload.
  • If you want a complex argument, use standard context.GetArgument<T> from GraphQL project, but use the strongly-typed ID classes on your propeties where needed.

License

MIT © AutoGuru

AutoGuru

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].