A summary of data about the Ruby ecosystem.

https://github.com/github-community-projects/graphql-client

A Ruby library for declaring, composing and executing GraphQL queries
https://github.com/github-community-projects/graphql-client

Keywords from Contributors

activerecord activejob mvc rubygems graphql-ruby relay feature-flag ruby-gem rack gem

Last synced: about 23 hours ago
JSON representation

Repository metadata

A Ruby library for declaring, composing and executing GraphQL queries

README.md

graphql-client Gem Version CI

GraphQL Client is a Ruby library for declaring, composing and executing GraphQL queries.

Usage

Installation

Add graphql-client to your Gemfile and then run bundle install.

# Gemfile
gem 'graphql-client'

Configuration

Sample configuration for a GraphQL Client to query from the SWAPI GraphQL Wrapper.

require "graphql/client"
require "graphql/client/http"

# Star Wars API example wrapper
module SWAPI
  # Configure GraphQL endpoint using the basic HTTP network adapter.
  HTTP = GraphQL::Client::HTTP.new("https://example.com/graphql") do
    def headers(context)
      # Optionally set any HTTP headers
      { "User-Agent": "My Client" }
    end
  end  

  # Fetch latest schema on init, this will make a network request
  Schema = GraphQL::Client.load_schema(HTTP)

  # However, it's smart to dump this to a JSON file and load from disk
  #
  # Run it from a script or rake task
  #   GraphQL::Client.dump_schema(SWAPI::HTTP, "path/to/schema.json")
  #
  # Schema = GraphQL::Client.load_schema("path/to/schema.json")

  Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end

Defining Queries

If you haven't already, familiarize yourself with the GraphQL query syntax. Queries are declared with the same syntax inside of a <<-'GRAPHQL' heredoc. There isn't any special query builder Ruby DSL.

This client library encourages all GraphQL queries to be declared statically and assigned to a Ruby constant.

HeroNameQuery = SWAPI::Client.parse <<-'GRAPHQL'
  query {
    hero {
      name
    }
  }
GRAPHQL

Queries can reference variables that are passed in at query execution time.

HeroFromEpisodeQuery = SWAPI::Client.parse <<-'GRAPHQL'
  query($episode: Episode) {
    hero(episode: $episode) {
      name
    }
  }
GRAPHQL

Fragments are declared similarly.

HumanFragment = SWAPI::Client.parse <<-'GRAPHQL'
  fragment on Human {
    name
    homePlanet
  }
GRAPHQL

To include a fragment in a query, reference the fragment by constant.

HeroNameQuery = SWAPI::Client.parse <<-'GRAPHQL'
  {
    luke: human(id: "1000") {
      ...HumanFragment
    }
    leia: human(id: "1003") {
      ...HumanFragment
    }
  }
GRAPHQL

This works for namespaced constants.

module Hero
  Query = SWAPI::Client.parse <<-'GRAPHQL'
    {
      luke: human(id: "1000") {
        ...Human::Fragment
      }
      leia: human(id: "1003") {
        ...Human::Fragment
      }
    }
  GRAPHQL
end

:: is invalid in regular GraphQL syntax, but #parse makes an initial pass on the query string and resolves all the fragment spreads with constantize.

Executing queries

Pass the reference of a parsed query definition to GraphQL::Client#query. Data is returned back in a wrapped GraphQL::Client::Schema::ObjectType struct that provides Ruby-ish accessors.

result = SWAPI::Client.query(Hero::Query)

# The raw data is Hash of JSON values
# result["data"]["luke"]["homePlanet"]

# The wrapped result allows to you access data with Ruby methods
result.data.luke.home_planet

GraphQL::Client#query also accepts variables and context parameters that can be leveraged by the underlying network executor.

result = SWAPI::Client.query(Hero::HeroFromEpisodeQuery, variables: {episode: "JEDI"}, context: {user_id: current_user_id})

Rails ERB integration

If you're using Ruby on Rails ERB templates, theres a ERB extension that allows static queries to be defined in the template itself.

In standard Ruby you can simply assign queries and fragments to constants and they'll be available throughout the app. However, the contents of an ERB template is compiled into a Ruby method, and methods can't assign constants. So a new ERB tag was extended to declare static sections that include a GraphQL query.

<%# app/views/humans/human.html.erb %>
<%graphql
  fragment HumanFragment on Human {
    name
    homePlanet
  }
%>

<p><%= human.name %> lives on <%= human.home_planet %>.</p>

These <%graphql sections are simply ignored at runtime but make their definitions available through constants. The module namespacing is derived from the .erb's path plus the definition name.

>> "views/humans/human".camelize
=> "Views::Humans::Human"
>> Views::Humans::Human::HumanFragment
=> #<GraphQL::Client::FragmentDefinition>

Examples

github/github-graphql-rails-example is an example application using this library to implement views on the GitHub GraphQL API.

Installation

Add graphql-client to your app's Gemfile:

gem 'graphql-client'

See Also


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 661
Total Committers: 55
Avg Commits per committer: 12.018
Development Distribution Score (DDS): 0.378

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Joshua Peek j****h@j****m 411
Robert Mosolgo r****o@g****m 52
John Hawthorn j****n@h****l 48
Garrett Bjerkhoel me@g****m 17
Garen J. Torikian g****n 12
Arthur Schreiber a****r@g****m 10
dependabot[bot] 4****] 10
Pat Nakajima p****a@g****m 8
jmeridth j****h@g****m 8
Aaron Patterson a****n@g****m 6
John Crepezzi j****i@g****m 5
Josh Soref j****f 4
Issy Long me@i****m 4
Damon Aw d****y@g****m 4
mvgijssel m****n@h****m 4
meganemura m****a 3
wuarmin a****n@w****m 3
Joel Turkel j****l@s****m 3
Adam Roben a****m@r****g 2
Chris Bloom c****7@g****m 2
Edouard CHIN e****n@s****m 2
Jakob Class m****i@g****m 2
Jean Boussier j****r@g****m 2
Kevin Sawicki k****n@g****m 2
Luke Sanwick l****k@g****m 2
Elvin Efendi e****v@g****m 2
hogelog k****o@g****m 2
Thomas Maurer t****a@g****m 2
Thomas Burgaud t****d@e****u 2
Sam Clopton s****e@g****m 2
and 25 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 2 days ago

Total issues: 15
Total pull requests: 65
Average time to close issues: 12 days
Average time to close pull requests: 27 days
Total issue authors: 13
Total pull request authors: 20
Average comments per issue: 1.27
Average comments per pull request: 0.86
Merged pull request: 25
Bot issues: 0
Bot pull requests: 32

Past year issues: 2
Past year pull requests: 7
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 2
Past year pull request authors: 4
Past year average comments per issue: 1.5
Past year average comments per pull request: 0.0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/github-community-projects/graphql-client

Top Issue Authors

  • rmosolgo (2)
  • wuarmin (2)
  • eizengan (1)
  • patch0 (1)
  • nowakoo (1)
  • vvbogdanov87 (1)
  • tlubz (1)
  • jhass (1)
  • oystein-brevio (1)
  • justinko (1)
  • dogweather (1)
  • rellampec (1)
  • ElvinEfendi (1)

Top Pull Request Authors

  • dependabot[bot] (32)
  • rellampec (4)
  • wuarmin (3)
  • jmeridth (3)
  • rmosolgo (3)
  • ElvinEfendi (2)
  • meganemura (2)
  • hogelog (2)
  • Samsinite (2)
  • ajsharma (1)
  • billybonks (1)
  • mikdiet (1)
  • yuki24 (1)
  • Tabby (1)
  • itojum (1)

Top Issue Labels

Top Pull Request Labels

  • dependencies (32)
  • github_actions (16)
  • ruby (16)

Package metadata

gem.coop: graphql-client

A Ruby library for declaring, composing and executing GraphQL queries

  • Homepage: https://github.com/github-community-projects/graphql-client
  • Documentation: http://www.rubydoc.info/gems/graphql-client/
  • Licenses: MIT
  • Latest release: 0.26.0 (published over 1 year ago)
  • Last Synced: 2026-11-15T16:11:12.893Z (2 days ago)
  • Versions: 73
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 96,938,359 Total
  • Docker Downloads: 434,442,383
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.156%
    • Docker downloads count: 0.3%
    • Downloads: 0.324%
  • Maintainers (4)
rubygems.org: graphql-client

A Ruby library for declaring, composing and executing GraphQL queries

  • Homepage: https://github.com/github-community-projects/graphql-client
  • Documentation: http://www.rubydoc.info/gems/graphql-client/
  • Licenses: MIT
  • Latest release: 0.26.0 (published over 1 year ago)
  • Last Synced: 2026-11-16T08:41:19.696Z (1 day ago)
  • Versions: 73
  • Dependent Packages: 45
  • Dependent Repositories: 1,113
  • Downloads: 96,956,982 Total
  • Docker Downloads: 434,442,383
  • Rankings:
    • Docker downloads count: 0.352%
    • Downloads: 0.405%
    • Dependent packages count: 0.611%
    • Dependent repos count: 0.97%
    • Average: 0.982%
    • Forks count: 1.761%
    • Stargazers count: 1.794%
  • Maintainers (4)
proxy.golang.org: github.com/github-community-projects/graphql-client


Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems
  • debug >= 1.0.0 development
graphql-client.gemspec rubygems
  • actionpack >= 3.2.22 development
  • erubi ~> 1.6 development
  • erubis ~> 2.7 development
  • minitest ~> 5.9 development
  • rake ~> 13.1.0 development
  • rubocop ~> 1.57.0 development
  • rubocop-github >= 0 development
  • activesupport >= 3.0
  • graphql >= 0
.github/workflows/release.yml actions
  • actions/checkout v4 composite
  • ruby/setup-ruby v1 composite
  • rubygems/release-gem v1 composite

Score: 29.355836821527717