gql-crystal

Version, currently 0.1.02 versions

github.com/dgodd/gql-crystal

No description declared in shard.yml.

0 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  gql-crystal:
    github: dgodd/gql-crystal
    version: ~> 0.1.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

GQL

Build Status GitHub release

Creates simple Graphql clients

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      gql:
        github: dgodd/gql-crystal
  2. Run shards install

Usage

require "http/client"
require "gql"

@[GQL::Serializable::Options(query_args: {updatedSince: ISO8601DateTime, first: Int, after: String})]
class AdvertSearch
  include GQL::Serializable

  class PageInfo
    include GQL::Serializable

    property has_next_page : Bool
    property end_cursor : String
  end

  class Advert
    include GQL::Serializable

    property id : String
    property legacy_id : Int64
    property title : String
    property updated_at : String
  end

  class Adverts
    include GQL::Serializable

    @[GQL::Field(sub: true)]
    property page_info : PageInfo
    @[GQL::Field(type: AdvertSearch::Advert, sub: true)]
    property nodes : Array(Advert)
  end

  class AdvertSearch
    include GQL::Serializable

    @[GQL::Field(graphql: "adverts(first: $first, after: $after)", sub: true)]
    property adverts : Adverts
  end

  @[GQL::Field(graphql: "advertSearch(attributes: { updatedSince: $updatedSince })", sub: true)]
  property advert_search : AdvertSearch

  def page_info
    advert_search.adverts.page_info
  end
end

client = HTTP::Client.new("marketplacer.lvh.me", port: 3000, tls: false)
pp AdvertSearch.post(client, { updatedSince: "2020-06-24T08:45:14+10:00", first: 10 })
data = nil
loop do
  after = data.page_info.end_cursor if data
  data = AdvertSearch.post(client, updated_since: "2020-06-24T08:45:14+10:00", first: 10, after: after)
  pp data
  break unless data && data.page_info.has_next_page
end

Development

crystal spec

Contributing

  1. Fork it (https://github.com/your-github-user/gql-crystal/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors