{"id":13877983,"url":"https://github.com/github-community-projects/graphql-client","last_synced_at":"2026-02-07T00:19:41.180Z","repository":{"id":218979260,"uuid":"747415838","full_name":"github-community-projects/graphql-client","owner":"github-community-projects","description":"A Ruby library for declaring, composing and executing GraphQL queries","archived":false,"fork":false,"pushed_at":"2025-12-06T11:49:41.000Z","size":772,"stargazers_count":60,"open_issues_count":8,"forks_count":228,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-10T05:59:27.562Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github-community-projects.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-23T22:04:42.000Z","updated_at":"2025-12-06T11:49:45.000Z","dependencies_parsed_at":"2024-02-08T22:15:24.978Z","dependency_job_id":"179db32a-5b78-460f-940b-1799ce96f2c2","html_url":"https://github.com/github-community-projects/graphql-client","commit_stats":null,"previous_names":["github-community-projects/graphql-client"],"tags_count":70,"template":false,"template_full_name":null,"purl":"pkg:github/github-community-projects/graphql-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-community-projects%2Fgraphql-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-community-projects%2Fgraphql-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-community-projects%2Fgraphql-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-community-projects%2Fgraphql-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github-community-projects","download_url":"https://codeload.github.com/github-community-projects/graphql-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github-community-projects%2Fgraphql-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29181331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T23:15:33.022Z","status":"ssl_error","status_checked_at":"2026-02-06T23:15:09.128Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:01:36.688Z","updated_at":"2026-02-07T00:19:41.158Z","avatar_url":"https://github.com/github-community-projects.png","language":"Ruby","funding_links":[],"categories":["Ruby","GraphQL"],"sub_categories":[],"readme":"# graphql-client [![Gem Version](https://badge.fury.io/rb/graphql-client.svg)](https://badge.fury.io/rb/graphql-client) [![CI](https://github.com/github-community-projects/graphql-client/workflows/CI/badge.svg)](https://github.com/github-community-projects/graphql-client/actions?query=workflow)\n\nGraphQL Client is a Ruby library for declaring, composing and executing GraphQL queries.\n\n## Usage\n\n### Installation\n\nAdd `graphql-client` to your Gemfile and then run `bundle install`.\n\n```ruby\n# Gemfile\ngem 'graphql-client'\n```\n\n### Configuration\n\nSample configuration for a GraphQL Client to query from the [SWAPI GraphQL Wrapper](https://github.com/graphql/swapi-graphql).\n\n```ruby\nrequire \"graphql/client\"\nrequire \"graphql/client/http\"\n\n# Star Wars API example wrapper\nmodule SWAPI\n  # Configure GraphQL endpoint using the basic HTTP network adapter.\n  HTTP = GraphQL::Client::HTTP.new(\"https://example.com/graphql\") do\n    def headers(context)\n      # Optionally set any HTTP headers\n      { \"User-Agent\": \"My Client\" }\n    end\n  end  \n\n  # Fetch latest schema on init, this will make a network request\n  Schema = GraphQL::Client.load_schema(HTTP)\n\n  # However, it's smart to dump this to a JSON file and load from disk\n  #\n  # Run it from a script or rake task\n  #   GraphQL::Client.dump_schema(SWAPI::HTTP, \"path/to/schema.json\")\n  #\n  # Schema = GraphQL::Client.load_schema(\"path/to/schema.json\")\n\n  Client = GraphQL::Client.new(schema: Schema, execute: HTTP)\nend\n```\n\n### Defining Queries\n\nIf you haven't already, [familiarize yourself with the GraphQL query syntax](http://graphql.org/docs/queries/). Queries are declared with the same syntax inside of a `\u003c\u003c-'GRAPHQL'` heredoc. There isn't any special query builder Ruby DSL.\n\nThis client library encourages all GraphQL queries to be declared statically and assigned to a Ruby constant.\n\n```ruby\nHeroNameQuery = SWAPI::Client.parse \u003c\u003c-'GRAPHQL'\n  query {\n    hero {\n      name\n    }\n  }\nGRAPHQL\n```\n\nQueries can reference variables that are passed in at query execution time.\n\n```ruby\nHeroFromEpisodeQuery = SWAPI::Client.parse \u003c\u003c-'GRAPHQL'\n  query($episode: Episode) {\n    hero(episode: $episode) {\n      name\n    }\n  }\nGRAPHQL\n```\n\nFragments are declared similarly.\n\n```ruby\nHumanFragment = SWAPI::Client.parse \u003c\u003c-'GRAPHQL'\n  fragment on Human {\n    name\n    homePlanet\n  }\nGRAPHQL\n```\n\nTo include a fragment in a query, reference the fragment by constant.\n\n```ruby\nHeroNameQuery = SWAPI::Client.parse \u003c\u003c-'GRAPHQL'\n  {\n    luke: human(id: \"1000\") {\n      ...HumanFragment\n    }\n    leia: human(id: \"1003\") {\n      ...HumanFragment\n    }\n  }\nGRAPHQL\n```\n\nThis works for namespaced constants.\n\n```ruby\nmodule Hero\n  Query = SWAPI::Client.parse \u003c\u003c-'GRAPHQL'\n    {\n      luke: human(id: \"1000\") {\n        ...Human::Fragment\n      }\n      leia: human(id: \"1003\") {\n        ...Human::Fragment\n      }\n    }\n  GRAPHQL\nend\n```\n\n`::` is invalid in regular GraphQL syntax, but `#parse` makes an initial pass on the query string and resolves all the fragment spreads with [`constantize`](http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-constantize).\n\n### Executing queries\n\nPass 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.\n\n```ruby\nresult = SWAPI::Client.query(Hero::Query)\n\n# The raw data is Hash of JSON values\n# result[\"data\"][\"luke\"][\"homePlanet\"]\n\n# The wrapped result allows to you access data with Ruby methods\nresult.data.luke.home_planet\n```\n\n`GraphQL::Client#query` also accepts variables and context parameters that can be leveraged by the underlying network executor.\n\n```ruby\nresult = SWAPI::Client.query(Hero::HeroFromEpisodeQuery, variables: {episode: \"JEDI\"}, context: {user_id: current_user_id})\n```\n\n### Rails ERB integration\n\nIf you're using Ruby on Rails ERB templates, theres a ERB extension that allows static queries to be defined in the template itself.\n\nIn 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.\n\n```erb\n\u003c%# app/views/humans/human.html.erb %\u003e\n\u003c%graphql\n  fragment HumanFragment on Human {\n    name\n    homePlanet\n  }\n%\u003e\n\n\u003cp\u003e\u003c%= human.name %\u003e lives on \u003c%= human.home_planet %\u003e.\u003c/p\u003e\n```\n\nThese `\u003c%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.\n\n```\n\u003e\u003e \"views/humans/human\".camelize\n=\u003e \"Views::Humans::Human\"\n\u003e\u003e Views::Humans::Human::HumanFragment\n=\u003e #\u003cGraphQL::Client::FragmentDefinition\u003e\n```\n\n## Examples\n\n[github/github-graphql-rails-example](https://github.com/github/github-graphql-rails-example) is an example application using this library to implement views on the GitHub GraphQL API.\n\n## Installation\n\nAdd `graphql-client` to your app's Gemfile:\n\n```ruby\ngem 'graphql-client'\n```\n\n## See Also\n\n* [graphql-ruby](https://github.com/rmosolgo/graphql-ruby) gem which implements 80% of what this library provides. ❤️ [@rmosolgo](https://github.com/rmosolgo)\n* [Facebook's GraphQL homepage](http://graphql.org/)\n* [Facebook's Relay homepage](https://facebook.github.io/relay/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub-community-projects%2Fgraphql-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub-community-projects%2Fgraphql-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub-community-projects%2Fgraphql-client/lists"}