graphql-client-aws 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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +46 -0
  4. data/lib/graphql/client/aws.rb +44 -0
  5. metadata +130 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3d639ea59745bbe12c1efaf6d531498b1dc6b9326f8a65fbd08211ee0c19d87b
4
+ data.tar.gz: b2f5c28b642e5a6a5758568b493bc8c1e5e5d141e9509dc6b61f7d5eec63dd8c
5
+ SHA512:
6
+ metadata.gz: cbd1d1d04a3b684e0c0543ef1d6e16dde30c34bceba525aea961c347cd773001a2ac6dcc7f43e790debbc9b35a4e1a2333c3eb93965c4336833679c613453464
7
+ data.tar.gz: b4108c1594bef37203c70578fcd1c23cd7a5c38411a946bca02e2844b85f0b940b05eb15df431664d65e02db7d9fcadf3176ff39a9a7a1424b071831d7c0badb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Sonoda Ryohei
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # graphql-client-aws
2
+
3
+ `graphql-client`([github/graphql-client](https://github.com/github/graphql-client)) を AWS AppSync に対応させるための gem です。
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'graphql-client-aws'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install graphql-client-aws
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+
25
+ [オリジナルのサンプル](https://github.com/github/graphql-client#configuration)を以下のように書き換えて使用します。
26
+
27
+ ```diff
28
+ require "graphql/client"
29
+ - require "graphql/client/http"
30
+ + require "graphql/client/aws"
31
+
32
+ # Star Wars API example wrapper
33
+ module SWAPI
34
+ # Configure GraphQL endpoint using the basic HTTP network adapter.
35
+ - HTTP = GraphQL::Client::HTTP.new("https://example.com/graphql") do
36
+ + HTTP = GraphQL::Client::Aws.new("https://example.com/graphql", region: 'us-east-1') do
37
+ def headers(context)
38
+ # Optionally set any HTTP headers
39
+ { "User-Agent": "My Client" }
40
+ end
41
+ end
42
+ ```
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,44 @@
1
+ require 'graphql/client/http'
2
+ require 'json'
3
+ require 'aws-sigv4'
4
+ require 'net/http'
5
+
6
+ module GraphQL
7
+ class Client
8
+ class Aws < GraphQL::Client::HTTP
9
+ def initialize(uri, **opts, &block)
10
+ appsync_opts = opts.merge(service: 'appsync')
11
+ @signer = ::Aws::Sigv4::Signer.new(appsync_opts)
12
+ if block_given?
13
+ super(uri, &block)
14
+ else
15
+ super(uri)
16
+ end
17
+ end
18
+
19
+ def connection
20
+ SignedHTTP.new(uri.host, uri.port).tap do |client|
21
+ client.signer = @signer
22
+ client.uri = uri
23
+ client.use_ssl = uri.scheme == "https"
24
+ end
25
+ end
26
+ end
27
+
28
+ class SignedHTTP < Net::HTTP
29
+ attr_accessor :signer, :uri
30
+
31
+ # @param [Net::HTTPRequest] req
32
+ def request(req, *args)
33
+ signature = signer.sign_request(http_method: req.method, url: uri, body: req.body)
34
+ req['Host'] = signature.headers['Host']
35
+ req['X-Amz-Date'] = signature.headers['x-amz-date']
36
+ req['X-Amz-Security-Token'] = signature.headers['x-amz-security-token']
37
+ req['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
38
+ req['Authorization'] = signature.headers['authorization']
39
+ req['Content-Type'] = 'application/graphql'
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphql-client-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sonodar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sigv4
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: graphql-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.14.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-console
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Ruby library for declaring, composing and executing GraphQL queries
98
+ for AWS AppSync
99
+ email: ryoheisonoda@outlook.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE
105
+ - README.md
106
+ - lib/graphql/client/aws.rb
107
+ homepage: https://github.com/sonodar/graphql-client-aws-ruby
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.3.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.4
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: GraphQL Client for AWS AppSync
130
+ test_files: []