Coder Social home page Coder Social logo

micro.graphql.federation's Introduction

What

I'm using GraphQL package which is really good. While it does support schema first federation, it doesn't support code first federation.

How

Looking at the specs, all we need here is a few things that our graphql server does. We need to define some scalars and some queries. Schema first federation already includes a FederatedSchemaPrinter we can use that to print SDL

Why

I've multiple projects and I'm sure other people are also trying to do federation. Even though it's not a lot of code in this project, we'll always have to copy same code into all projects untill GraphQL project include federation.

Getting started:

First install Micro.GraphQL.Federation from nuget.

Create EntityType:

public class EntityType : Micro.GraphQL.Federation.Types.EntityType
{
    public EntityType()
    {
        // register all types which uses @key directive
        Type<ApplicationType>();
        Type<UserType>();
    }
}

Enable federation on Startup.ConfigureServices:

services.EnableFederation<EntityType>();

Extend your schema:

public class AppRegistrationSchema : Schema<EntityType>
{
    public AppRegistrationSchema(IServiceProvider services, Query query) : base(services)
    {
        Query = query;
    }
}

extend your query:

public class Query : Query<EntityType>
{
}

extend your types:

public sealed class UserType : ObjectGraphType<User>
{
  public UserType() {
      ExtendByKeys("id email username");
  }
}

will produce

extend type User @key(fields: "id email username") {

}

if it's core type and don't want to extend on gql schema

public sealed class UserType : ObjectGraphType<User>
{
  public UserType() {
      Key("id email username");
  }
}

will produce

type User @key(fields: "id email username") {}

for more info, open a issue

micro.graphql.federation's People

Contributors

cyberhck avatar

Stargazers

 avatar

Watchers

 avatar

micro.graphql.federation's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.