All Projects → d12 → graphql-remote_loader

d12 / graphql-remote_loader

Licence: other
Performant remote GraphQL queries from within the resolvers of a Ruby GraphQL API.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to graphql-remote loader

kanji
A strongly typed GraphQL API framework
Stars: ✭ 12 (-76.92%)
Mutual labels:  graphql-server, graphql-ruby
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 (+5686.54%)
Mutual labels:  graphql-server, schema-stitching
total
Ruby Gem to get total memory size in the system
Stars: ✭ 15 (-71.15%)
Mutual labels:  ruby-gem
busser-serverspec
A Busser runner plugin for the serverspec testing library
Stars: ✭ 51 (-1.92%)
Mutual labels:  ruby-gem
waifu2x
Ruby wrapper and CLI for waifu2x
Stars: ✭ 15 (-71.15%)
Mutual labels:  ruby-gem
finch-graphql
Local GraphQL API in the background process of a web extension.
Stars: ✭ 48 (-7.69%)
Mutual labels:  graphql-server
showcase
A Full Stack Journey with Micro Services and Micro Front Ends. Using dapr, kubernetes, react module federation and web assembly,
Stars: ✭ 45 (-13.46%)
Mutual labels:  graphql-server
graphql-ufc-api
GraphQL server for UFC's public API
Stars: ✭ 26 (-50%)
Mutual labels:  graphql-server
kitchen-google
Google Compute Engine driver for Test-Kitchen
Stars: ✭ 47 (-9.62%)
Mutual labels:  ruby-gem
graphql-express-nodejs
A Simple GraphQL Server implementation using Express and Node. See post here: https://t.co/Cm6GitZaBL
Stars: ✭ 24 (-53.85%)
Mutual labels:  graphql-server
jekyll-gzip
Generate gzipped assets and files for your Jekyll site at build time
Stars: ✭ 34 (-34.62%)
Mutual labels:  ruby-gem
tty-editor
Opens a file or text in the user's preferred editor
Stars: ✭ 26 (-50%)
Mutual labels:  ruby-gem
whitespace-linter
A program that detects and formats trailing whitespace and extra empty lines in your code and config files.
Stars: ✭ 16 (-69.23%)
Mutual labels:  ruby-gem
apollo-graphql-full-stack
Full-stack Apollo GraphQL app using React and Node JS
Stars: ✭ 31 (-40.38%)
Mutual labels:  graphql-server
githat
Git diff with code syntax highlight
Stars: ✭ 32 (-38.46%)
Mutual labels:  ruby-gem
bucky-core
System testing framework for web application.
Stars: ✭ 32 (-38.46%)
Mutual labels:  ruby-gem
graphql-server
(out of date) A command to add a GraphQL server to your Svelte project
Stars: ✭ 31 (-40.38%)
Mutual labels:  graphql-server
wor-authentication
Gem to add authentication to your application using JWT, with expirable, renewable and customizable tokens!
Stars: ✭ 63 (+21.15%)
Mutual labels:  ruby-gem
character-overlay
Web App for adding an OBS overlay with character information such as name, picture, and health for your favorite role-playing game.
Stars: ✭ 17 (-67.31%)
Mutual labels:  graphql-server
student-api-graphql
A GraphQL Wrapper for Ellucian's Banner Student REST API
Stars: ✭ 19 (-63.46%)
Mutual labels:  graphql-server

GraphQL Remote Loader

Gem Version Build Status

Performant, batched GraphQL queries from within the resolvers of a graphql-ruby API.

Snippet

field :login, String, null: false, description: "The currently authenticated GitHub user's login."

def login
  GitHubLoader.load("viewer { login }").then do |results|
    if results["errors"].present?
      ""
    else
      results["data"]["viewer"]["login"].upcase
    end
  end
end

Description

graphql-remote_loader allows for querying GraphQL APIs from within resolvers of a graphql-ruby API.

This can be used to create GraphQL APIs that depend on data from other GraphQL APIs, either remote or local.

A promise-based resolution strategy from Shopify's graphql-batch is used to batch all requested data into a single GraphQL query. Promises are fulfilled with only the data they requested.

You can think of it as a lightweight version of schema-stitching.

Performance

Each Loader#load invocation does not send a GraphQL query to the remote. The Gem uses graphql-batch to collect all GraphQL queries together, then combines them and sends a single query to the upstream. The gem splits the response JSON up so that each promise is only resolved with data that it asked for.

How to use

First, you'll need to install the gem. Either do gem install graphql-remote_loader or add this to your Gemfile:

gem "graphql-remote_loader"

The gem provides a base loader GraphQL::RemoteLoader::Loader which does most of the heavy lifting. In order to remain client-agnostic, there's an unimplemented no-op that takes a query string and queries the remote GraphQL API.

To use, create a new class that inherits from GraphQL::RemoteLoader::Loader and define def query(query_string). The method takes a query String as input. The expected output is a response Hash, or an object that responds to #to_h.

Example:

require "graphql/remote_loader"

module MyApp
  class GitHubLoader < GraphQL::RemoteLoader::Loader
    def query(query_string)
      parsed_query = GraphQLClient.parse(query_string)
      GraphQLClient.query(parsed_query)
    end
  end
end

This example uses graphql-client. Any client, or even just plain cURL/HTTP can be used.

With your loader setup, you can begin using #load or #load_value in your graphql-ruby resolvers.

Full example

To see a working example of how graphql-remote_loader works, see the complete, working example application.

Running tests

bundle install
bundle exec rspec
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].