All Projects → Gusto → Apollo Federation Ruby

Gusto / Apollo Federation Ruby

Licence: mit
A Ruby implementation of Apollo Federation

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Apollo Federation Ruby

Apollo Angular
A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
Stars: ✭ 1,058 (+707.63%)
Mutual labels:  graphql, apollographql
Apollo Prophecy
🔮 GraphQL error management made Easy, generate custom machine-readable errors for Apollo Client/Server from the CLI
Stars: ✭ 83 (-36.64%)
Mutual labels:  graphql, apollographql
Data Source Base
Boilerplate for creating a GrAMPS-compatible data source.
Stars: ✭ 52 (-60.31%)
Mutual labels:  graphql, apollographql
Githunt React
[DEPRECATED] 🔃 An example app frontend built with Apollo Client and React
Stars: ✭ 1,036 (+690.84%)
Mutual labels:  graphql, apollographql
React Fullstack Graphql
Starter projects for fullstack applications based on React & GraphQL.
Stars: ✭ 1,352 (+932.06%)
Mutual labels:  graphql, apollographql
Umi Plugin Apollo
Apollo graphql plugin for umi
Stars: ✭ 48 (-63.36%)
Mutual labels:  graphql, apollographql
Apollo Mocked Provider
Automatically mock GraphQL data with a mocked ApolloProvider
Stars: ✭ 70 (-46.56%)
Mutual labels:  graphql, apollographql
Apollo Link Maxage
An Apollo Link to invalidate cached queries
Stars: ✭ 23 (-82.44%)
Mutual labels:  graphql, apollographql
Booben
Web app constructor based on React, with GraphQL bindings
Stars: ✭ 96 (-26.72%)
Mutual labels:  graphql, apollographql
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-28.24%)
Mutual labels:  graphql, apollographql
Howtographql
The Fullstack Tutorial for GraphQL
Stars: ✭ 7,999 (+6006.11%)
Mutual labels:  graphql, apollographql
React Graphql Github Apollo
🚀 A React + Apollo + GraphQL GitHub Client. Your opportunity to learn about these technologies in a real world application.
Stars: ✭ 1,563 (+1093.13%)
Mutual labels:  graphql, apollographql
Link state demo
🚀 Demonstrate how to support multiple stores in Apollo Link State
Stars: ✭ 30 (-77.1%)
Mutual labels:  graphql, apollographql
Graphql Query Test Mock
Easily mock GraphQL queries in your Relay Modern / Apollo / any-other-GraphQL-client tests.
Stars: ✭ 49 (-62.6%)
Mutual labels:  graphql, apollographql
Graphql React Apollo
A GraphQL implementation in React using Apollo.
Stars: ✭ 9 (-93.13%)
Mutual labels:  graphql, apollographql
Vue Apollo Todos
Vue Apollo GraphQL mutation examples
Stars: ✭ 69 (-47.33%)
Mutual labels:  graphql, apollographql
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (+429.77%)
Mutual labels:  graphql, apollographql
Graphql
GraphQL (TypeScript) module for Nest framework (node.js) 🍷
Stars: ✭ 697 (+432.06%)
Mutual labels:  graphql, apollographql
Angular Fullstack Graphql
🚀 Starter projects for fullstack applications based on Angular & GraphQL.
Stars: ✭ 92 (-29.77%)
Mutual labels:  graphql, apollographql
Graphql Codegen Hasura
code-generator plugins for hasura/apollo-gql/typescript development
Stars: ✭ 113 (-13.74%)
Mutual labels:  graphql, apollographql

apollo-federation

CircleCI

This gem extends the GraphQL Ruby gem to add support for creating an Apollo Federation schema.

DISCLAIMER

This gem is still in a beta stage and may have some bugs or incompatibilities. See the Known Issues and Limitations below. If you run into any problems, please file an issue.

Installation

Add this line to your application's Gemfile:

gem 'apollo-federation'

And then execute:

$ bundle

Or install it yourself as:

$ gem install apollo-federation

Getting Started

Include the ApolloFederation::Field module in your base field class:

require 'apollo-federation'

class BaseField < GraphQL::Schema::Field
  include ApolloFederation::Field
end

Include the ApolloFederation::Object module in your base object class:

class BaseObject < GraphQL::Schema::Object
  include ApolloFederation::Object

  field_class BaseField
end

Include the ApolloFederation::Interface module in your base interface module:

module BaseInterface
  include GraphQL::Schema::Interface
  include ApolloFederation::Interface

  field_class BaseField
end

Finally, include the ApolloFederation::Schema module in your schema:

class MySchema < GraphQL::Schema
  include ApolloFederation::Schema
end

Example

The example folder contains a Ruby implementation of Apollo's federation-demo. To run it locally, install the Ruby dependencies:

$ bundle

Install the Node dependencies:

$ yarn

Start all of the services:

$ yarn start-services

Start the gateway:

$ yarn start-gateway

This will start up the gateway and serve it at http://localhost:5000.

Usage

The API is designed to mimic the API of Apollo's federation library. It's best to read and understand the way federation works, in general, before attempting to use this library.

Extending a type

Apollo documentation

Call extend_type within your class definition:

class User < BaseObject
  extend_type
end

The @key directive

Apollo documentation

Call key within your class definition:

class User < BaseObject
  key fields: 'id'
end

The @external directive

Apollo documentation

Pass the external: true option to your field definition:

class User < BaseObject
  field :id, ID, null: false, external: true
end

The @requires directive

Apollo documentation

Pass the requires: option to your field definition:

class Product < BaseObject
  field :price, Int, null: true, external: true
  field :weight, Int, null: true, external: true
  field :shipping_estimate, Int, null: true, requires: { fields: "price weight"}
end

The @provides directive

Apollo documentation

Pass the provides: option to your field definition:

class Review < BaseObject
  field :author, 'User', null: true, provides: { fields: 'username' }
end

Reference resolvers

Apollo documentation

Define a resolve_reference class method on your object. The method will be passed the reference from another service and the context for the query.

class User < BaseObject
  def self.resolve_reference(reference, context)
    USERS.find { |user| user[:id] == reference[:id] }
  end
end

Tracing

To support federated tracing:

  1. Add use ApolloFederation::Tracing to your schema class.
  2. Change your controller to add tracing_enabled: true to the execution context based on the presence of the "include trace" header:
    def execute
      # ...
      context = {
        tracing_enabled: ApolloFederation::Tracing.should_add_traces(headers)
      }
      # ...
    end
    

Known Issues and Limitations

  • Only works with class-based schemas, the legacy .define API will not be supported
  • Does not add directives to the output of Schema.to_definition. Since graphql-ruby doesn't natively support schema directives, the directives will only be visible to the Apollo Gateway through the Query._service field (see the Apollo Federation specification)

Maintainers

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].