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

feat: Support for Apollo Federation #359

Merged
merged 2 commits into from
Nov 26, 2019
Merged

feat: Support for Apollo Federation #359

merged 2 commits into from
Nov 26, 2019

Conversation

iviaks
Copy link
Contributor

@iviaks iviaks commented Aug 22, 2019

Closing #352

Description

Add support for Apollo Federation.

  1. Added a new key directive;
  2. Added support for extend type;
  3. Added 3 tests for checking:
    • @key directive
    • extend type Query
    • imports

Examples

index.js

const path = require('path');
const { ApolloServer, gql } = require('apollo-server');
const { buildFederatedSchema } = require('@apollo/federation');

const { importSchema } = require('graphql-import');
const resolvers = require('./graphql/resolvers');

const typeDefs = importSchema(path.join(__dirname, './graphql/schema.graphql'));

const server = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs: gql(typeDefs),
      resolvers,
    },
  ]),
});

server.listen({ port: 4001 }).then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`);
});

graphql/schema.graphql

# import Query.* from './user/schema.graphql'

graphql/resolvers.js

module.exports = {
  Query: {
    me() {
      return users[0];
    },
  },
  User: {
    __resolveReference(object) {
      return users.find(user => user.id === object.id);
    },
  },
};

const users = [
  {
    id: '1',
    name: 'Ada Lovelace',
    birthDate: '1815-12-10',
    username: '@ada',
  },
  {
    id: '2',
    name: 'Alan Turing',
    birthDate: '1912-06-23',
    username: '@complete',
  },
];

graphql/user/schema.graphql

# import User from './types.graphql'

extend type Query {
  me: User
}

graphql/user/types.graphql

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

@drager
Copy link

drager commented Sep 11, 2019

@Urigo Could we get this merged?

@sponomarev
Copy link

That's a very valuable change

@sponomarev
Copy link

@iviaks Is it also necessary to add support for @requires @provides and @external directives as well as mentioned in the spec?

@iviaks
Copy link
Contributor Author

iviaks commented Sep 24, 2019

@sponomarev, Yes. I will add a few changes as soon as possible.

@iviaks
Copy link
Contributor Author

iviaks commented Sep 24, 2019

@sponomarev
I've added these directives and covered with tests according to Apollo Federation Docs

@shaneu
Copy link

shaneu commented Oct 8, 2019

What is the status on getting this branch merged?

@joarwilk
Copy link

@Urigo Any chance this can be merged? Would be very appreciated

@Globolobo
Copy link

@schickling Could we please get this merged?

@Alfarlost
Copy link

Alfarlost commented Nov 25, 2019

@Urigo, could we get this merged, please? Really a blocker for lots of people.

@ardatan ardatan merged commit 78d5336 into ardatan:master Nov 26, 2019
@marjorg
Copy link

marjorg commented Dec 3, 2019

@Urigo Any idea when this will be released?

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

Successfully merging this pull request may close these issues.

9 participants