Sha256: e1c0b13741e81c96c41d2848d751f8bb25618a9b65beb8b7bbbfb37df39fc660

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require_relative './lib/gqli'

puts GQLi::DSL.query {
  __on('Foo') {
    bar
  }
}.to_gql


puts GQLi::DSL.query {
  viewer {
    login
    repositories(first: 10) {
      edges {
        node {
          nameWithOwner
          watchers(first: 10) {
            edges {
              node {
                login
              }
            }
          }
        }
      }
    }
  }
}.to_gql

FragmentFoo = GQLi::DSL.fragment('Foo', 'Bar') {
  foo
  bar(b: 10)
  baz {
    qux(c: 3)
  }
}

puts FragmentFoo.to_gql

puts GQLi::DSL.query {
  ___ FragmentFoo
}.to_gql

puts "-------------"

SPACE_ID = 'cfexampleapi'
ACCESS_TOKEN = 'b4c0n73n7fu1'
CONTENTFUL_GQL = GQLi::Client.new(
  "https://graphql.contentful.com/content/v1/spaces/#{SPACE_ID}",
  headers: { "Authorization" => "Bearer #{ACCESS_TOKEN}" }
)

CatBase = GQLi::DSL.fragment('CatBase', 'Cat') {
  name
  likes
  lives
}

CatBestFriend = GQLi::DSL.fragment('CatBestFriend', 'Cat') {
  bestFriend {
    __on('Cat') {
      ___ CatBase
    }
  }
}

CatImportantFields = GQLi::DSL.fragment('CatImportantFields', 'Cat') {
  ___ CatBase
  ___ CatBestFriend
}

Query = GQLi::DSL.query {
  catCollection(limit: 1) {
    items {
      ___ CatImportantFields
      image {
        url
      }
    }
  }
}

response = CONTENTFUL_GQL.execute(Query)

puts "Query sent:"
puts response.query.to_gql

puts
puts "Response received"
response.data.catCollection.items.each do |c|
  puts "Name:    #{c.name}"
  puts "Likes:   #{c.likes.join(", ")}"
  puts "Lives #: #{c.lives}"
  c.bestFriend.tap do |bf|
    puts "Best Friend:"
    puts "\tName:    #{bf.name}"
    puts "\tLikes:   #{bf.likes.join(", ")}"
    puts "\tLives #: #{bf.lives}"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gqli-1.2.0 usage.rb
gqli-1.1.0 usage.rb
gqli-1.0.0 usage.rb
gqli-0.6.1 usage.rb
gqli-0.6.0 usage.rb
gqli-0.5.0 usage.rb
gqli-0.4.0 usage.rb
gqli-0.3.0 usage.rb
gqli-0.2.0 usage.rb