Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of federated graphs #299

Closed
marcus-sa opened this issue Jun 20, 2019 · 8 comments
Closed

Implementation of federated graphs #299

marcus-sa opened this issue Jun 20, 2019 · 8 comments

Comments

@marcus-sa
Copy link
Contributor

marcus-sa commented Jun 20, 2019

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

No support for federated graphs

Proposal

@apollo/federation uses a custom property in resolvers for referencing, just like when resolving a property.
Currently @nestjs/graphql have a @ResolveProperty() decorator, and what I propose is a @ResolveReference() decorator explicitly for when using @apollo/federation

Example of how they use __resolveReference:

const { ApolloServer, gql } = require('apollo-server');

const { buildFederatedSchema } = require('@apollo/federation');

const typeDefs = gql`
  type Query {
    me: User
  }


  type User @key(fields: "id") {
    id: ID!
    username: String
  }
`;

const resolvers = {
  Query: {
    me() {
      return { id: "1", username: "@ava" }
    }
  },

  User: {
    __resolveReference(user, { fetchUserById }){
      return fetchUserById(user.id)
    }
  }
};

const server = new ApolloServer({

  schema: buildFederatedSchema([{ typeDefs, resolvers }])
});

What is the motivation / use case for changing the behavior?

https://www.apollographql.com/docs/apollo-server/federation/introduction

Links

https://www.apollographql.com/docs/apollo-server/api/apollo-federation/

@marcus-sa
Copy link
Contributor Author

RFC: Should this be a part of the current @nestjs/graphql module, or should it be implemented as a community project?
Some people might not like the overheat that @apollo/federation provides if its useless for them.

@brianschardt
Copy link

brianschardt commented Jun 27, 2019

Any good or official implementation of federation for nestjs? Perhaps it could be a config option so people can specify federated: true, default false. If they want to use federated graph.

@marcus-sa
Copy link
Contributor Author

marcus-sa commented Jun 27, 2019

Haven't yet done any documentation, but essentially you'd be using GraphQLGatewayModule for your API gateway and GraphQLFederationModule for your microservices.

Check out my PR #301

And here's an example of how you'd be using it
https:/marcus-sa/nest-graphql-microservices-example/tree/dev?files=1

@brianschardt
Copy link

I see that makes sense. Anyone from nest looking into this. This is a super important feature!

@juicycleff
Copy link

Until a fix, you can use my library https:/juicycleff/nestjs-graphql-gateway. You keep using this library for everything else except the module initialization

@marcus-sa
Copy link
Contributor Author

@juicycleff where's the credits? You pretty much just copy-pasted my work.

@tuxmachine tuxmachine mentioned this issue Oct 29, 2019
3 tasks
@juicycleff
Copy link

juicycleff commented Nov 9, 2019

@marcus-sa oh sorry about I added credits to you. I basically used it in my project and decided to make it a lib so others can easily use it until there is support for federation here. Besides I was working on it, saw your project, wasn't much difference, took the part I needed and used it internally and decided to share it so others can use until support here (You copy-pasted from nestjs/graphql), I even added support for typegraphql, while true I copied some piece of your work which you made public to copy for free, it was not COPY PASTE. However again my bad for not adding credits to you, besides it was just a temporary fix. and not too different from what I made before only my approach was almost replacing the nest graphql library

@kamilmysliwiec
Copy link
Member

Just merged (published as 6.6.0). Let's track the docs update here nestjs/docs.nestjs.com#802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants