gql_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c82a50afcfb8dc9780c84faa64f3fdbe634b21d
4
+ data.tar.gz: 270c23e1b7e48b7b2e847b6025000fdc09b256b9
5
+ SHA512:
6
+ metadata.gz: ca78077afedf92f8f43456cc29e03d41e4310f412236a8a39ecf853f092bf98b5e4698b6ad40f88e37c8a8ef9ba904cee476c57dccaeb325f105a5dd9207828c
7
+ data.tar.gz: 9d400d4a8de8737d4e37520dbb2634be1aa9d4ba007c97b4745e0d64ca7491510a1f275c13b337104341d33117edb8a25fd1ca7fdd6703df94e09f2a7a6c35b0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gql_client.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gql_client (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.16)
16
+ gql_client!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 lezwon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # GqlClient
2
+
3
+ GraphQl Client gem to make requests using GraphQL Query Language.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gql_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gql_client
20
+
21
+ ## Usage
22
+ ```
23
+ require 'gql_client'
24
+
25
+ url = "http://example.com/graphql"
26
+ headers = {
27
+ "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9"
28
+ }
29
+
30
+ query = <<~GRAPHQL
31
+ {
32
+ infoForItem(id: 1234)
33
+ {
34
+ id
35
+ name
36
+ size
37
+ }
38
+ }
39
+ GRAPHQL
40
+ ```
41
+ ### Single Request
42
+ ```
43
+ response = GqlClient.execute(url, query, headers)
44
+ ```
45
+
46
+ ### Session based Request
47
+
48
+ ```
49
+ session = GqlClient::Session.new(url, headers)
50
+ response = session.execute(query)
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lezwon/GqlClient.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gql_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gql_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gql_client"
8
+ spec.version = GqlClient::VERSION
9
+ spec.authors = ["lezwon"]
10
+ spec.email = ["lezwon@gmail.com"]
11
+
12
+ spec.summary = "GraphQl Client gem to make requests using GraphQL Query Language"
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ # if spec.respond_to?(:metadata)
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+ # else
20
+ # raise "RubyGems 2.0 or newer is required to protect against " \
21
+ # "public gem pushes."
22
+ # end
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
@@ -0,0 +1,3 @@
1
+ module GqlClient
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gql_client.rb ADDED
@@ -0,0 +1,69 @@
1
+ require "gql_client/version"
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+
7
+ module GqlClient
8
+ def self.execute(url, query, headers, variables = {})
9
+ url = URI(url)
10
+ http = Net::HTTP.new(url.host, url.port)
11
+
12
+ request = Net::HTTP::Post.new(url, headers)
13
+ request["cookie"] = 'request_method=POST'
14
+ request["content-type"] = 'application/json'
15
+
16
+ body = {
17
+ "query": query,
18
+ "variables": variables
19
+ }
20
+
21
+ request.body = body.to_json
22
+
23
+ response = http.request(request)
24
+ response.code == "200" ? JSON.parse(response.read_body) : response.read_body
25
+ end
26
+
27
+ class Session
28
+
29
+ attr_accessor :request
30
+ attr_accessor :http
31
+
32
+ INTROSPECTION_QUERY_FILE = "introspection_query.graphql"
33
+
34
+ def initialize(url, headers)
35
+ url = URI(url)
36
+ @http = Net::HTTP.new(url.host, url.port)
37
+
38
+ @request = Net::HTTP::Post.new(url, headers)
39
+ @request["cookie"] = 'request_method=POST'
40
+ @request["content-type"] = 'application/json'
41
+ end
42
+
43
+ def schema
44
+ @schema ||= begin
45
+ request.body = {"query": introspection_query }.to_json
46
+ response = http.request(request)
47
+ raise StandardError, "Introspection Query Failed" unless response.code == "200"
48
+ JSON.parse(response.read_body)
49
+ end
50
+ end
51
+
52
+ def introspection_query
53
+ File.read(INTROSPECTION_QUERY_FILE)
54
+ end
55
+
56
+ def execute(query, variables = {})
57
+ body = {
58
+ "query": query,
59
+ "variables": variables
60
+ }
61
+
62
+ request.body = body.to_json
63
+
64
+ response = http.request(request)
65
+ response.code == "200" ? JSON.parse(response.read_body) : response.read_body
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,78 @@
1
+
2
+ query IntrospectionQuery {
3
+ __schema {
4
+ queryType { name }
5
+ mutationType { name }
6
+ subscriptionType { name }
7
+ types {
8
+ ...FullType
9
+ }
10
+ directives {
11
+ name
12
+ description
13
+ args {
14
+ ...InputValue
15
+ }
16
+ onOperation
17
+ onFragment
18
+ onField
19
+ }
20
+ }
21
+ }
22
+
23
+ fragment FullType on __Type {
24
+ kind
25
+ name
26
+ description
27
+ fields(includeDeprecated: true) {
28
+ name
29
+ description
30
+ args {
31
+ ...InputValue
32
+ }
33
+ type {
34
+ ...TypeRef
35
+ }
36
+ isDeprecated
37
+ deprecationReason
38
+ }
39
+ inputFields {
40
+ ...InputValue
41
+ }
42
+ interfaces {
43
+ ...TypeRef
44
+ }
45
+ enumValues(includeDeprecated: true) {
46
+ name
47
+ description
48
+ isDeprecated
49
+ deprecationReason
50
+ }
51
+ possibleTypes {
52
+ ...TypeRef
53
+ }
54
+ }
55
+
56
+ fragment InputValue on __InputValue {
57
+ name
58
+ description
59
+ type { ...TypeRef }
60
+ defaultValue
61
+ }
62
+
63
+ fragment TypeRef on __Type {
64
+ kind
65
+ name
66
+ ofType {
67
+ kind
68
+ name
69
+ ofType {
70
+ kind
71
+ name
72
+ ofType {
73
+ kind
74
+ name
75
+ }
76
+ }
77
+ }
78
+ }
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gql_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lezwon
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - lezwon@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - gql_client.gemspec
57
+ - lib/gql_client.rb
58
+ - lib/gql_client/version.rb
59
+ - lib/introspection_query.graphql
60
+ homepage:
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.14
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: GraphQl Client gem to make requests using GraphQL Query Language
84
+ test_files: []