Code Monkey home page Code Monkey logo

graphql-relay-walker's Introduction

GraphQL Relay Walker Build Status Gem Version

GraphQL::Relay::Walker is a Ruby library that generates queries for walking a Relay GraphQL schema. Given a GraphQL::Schema, you can walk from a given starting point, exercising any defined connections. This can be useful for various kinds of automated testing. Check out the GitHub Walker example to see it in action.

Setup

You can install this library as a Ruby Gem:

$ gem install graphql-relay-walker

Usage

require "graphql/relay/walker"

id = "<some starting node id>"
query = GraphQL::Relay::Walker.query_string(client.schema)


GraphQL::Relay::Walker.walk(from_id: id) do |frame|
  # The global relay id of the object we're looking at.
  frame.gid

  # The frame where we discovered this object's GID.
  frame.parent

  # Execute the query and store the result in the frame.
  # The implementation here is up to you, but you should set
  # `frame.result` to the Hash result of executing the query.
  frame.result = execute(query, variables: {"id" => frame.gid})

  # Parse the results, adding any newly discovered IDs to our queue.
  frame.enqueue_found_gids
end

Usage with GraphQL::Client

Requiring graphql/relay/walker/client_ext will add a GraphQL::Client#walk method. This simplifies things by allowing the client to build and execute the query for you.

Here's how you would walk the SWAPI GraphQL Wrapper, starting from Luke Skywalker, assuming a client configuration like this.

require "graphql/relay/walker/client_ext"

skywalker_gid = "cGVvcGxlOjE="

SWAPI::Client.walk(from_id: skywalker_gid) do |frame|
  # The global relay id of the object we're looking at.
  frame.gid

  # The frame where we discovered this object's GID.
  frame.parent

  # The result of executing the query for this frame's GID.
  frame.result
end

Development

  1. Clone repository and install dependencies
$ git clone https://github.com/github/graphql-relay-walker
$ cd graphql-relay-walker
$ bundle install
  1. Run tests
$ bundle exec rake

Compatibility & Versioning

This project is designed to work with MRI Ruby 2.2.2 or greater. It may work on other versions of Ruby.

All releases adhere to strict semantic versioning. For Example, major.minor.patch-pre (aka. stick.carrot.oops-peek).

Contributions & Feedback

We love community contributions! If you're planning to send us a pull request, please make sure read our Contributing Guidelines first.

Found a bug or have a question? Open up an issue.

License

The MIT License (MIT)

Copyright (C) 2016 GitHub, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

graphql-relay-walker's People

Contributors

brandonblack avatar bswinnerton avatar cjoudrey avatar gjtorikian avatar haileys avatar mastahyeti avatar rmosolgo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-relay-walker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.