graphql-client-aws 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql/client/aws.rb +35 -21
  3. metadata +46 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83c4f809b2d8a32a25977d31d21b8ce02b6d75e062345d8818cdf4d41f3bf330
4
- data.tar.gz: aee2f2a73d966803633e6af6fcc7c6ad05c1df6852b4ef5b883b6d338c77b544
3
+ metadata.gz: 0c8c0ce38970f8f7addaa22a17f46af695aad6bce4158f1859dd900ac87f297c
4
+ data.tar.gz: 2b614847dbeac689a738a7257b00b539d8b88a6d68059dfbe30517a81aec9a35
5
5
  SHA512:
6
- metadata.gz: 35e2c84d10ff847f21aab56e9af214857602a9442694b828dff6503c92a64324b841bc7ad89923bd195e19ad339f033239881b4ed3e08c4bff59ab8c1cfd57b7
7
- data.tar.gz: 4dfed70c7928f8b032cebf36b8ed86232f2fe32114a274b890af7d90461f48efcf665f13853cf40e8a6e1a07d3bb0bb02cfaa1249c9d3c9c8bd182c48d30897e
6
+ metadata.gz: 3e55e91e02959aab3ba1716cd8fe243e81bfc9c9d40afa6116d265d80fbeeaa3ca0dc7ab401a73148dc8621f9dd98d860f6717e9ddbdfbdab5af7d0881ba0ea6
7
+ data.tar.gz: f7c0854f90af351cb1e3fe83c0e5e60d42b1e46661cbda0bea7bee5549e9c3bd88e8476a2429d579a6382281f46bcd95817126c518191d4437a1903c4b8d02ce
@@ -7,37 +7,51 @@ module GraphQL
7
7
  class Client
8
8
  class Aws < GraphQL::Client::HTTP
9
9
  def initialize(uri, **opts, &block)
10
- appsync_opts = opts.merge(service: 'appsync')
11
- @signer = ::Aws::Sigv4::Signer.new(appsync_opts)
12
10
  if block_given?
13
11
  super(uri, &block)
14
12
  else
15
13
  super(uri)
16
14
  end
15
+ appsync_signer_option = opts.merge(service: 'appsync')
16
+ @signer = ::Aws::Sigv4::Signer.new(appsync_signer_option)
17
17
  end
18
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"
19
+ def execute(document:, operation_name: nil, variables: {}, context: {})
20
+ request = Net::HTTP::Post.new(uri.request_uri)
21
+
22
+ request['Accept'] = 'application/json'
23
+ headers(context).each { |name, value| request[name] = value }
24
+
25
+ request.body = build_body(document, operation_name, variables)
26
+
27
+ request = sign!(request)
28
+
29
+ response = connection.request(request)
30
+
31
+ case response
32
+ when Net::HTTPOK, Net::HTTPBadRequest
33
+ JSON.parse(response.body)
34
+ else
35
+ { 'errors' => [{ 'message' => "#{response.code} #{response.message}" }] }
24
36
  end
25
37
  end
26
- end
27
38
 
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
39
+ def build_body(document, operation_name, variables)
40
+ body = { 'query' => document.to_query_string }
41
+ body['variables'] = variables if variables.any?
42
+ body['operationName'] = operation_name if operation_name
43
+ JSON.generate(body)
44
+ end
45
+
46
+ def sign!(request)
47
+ signature = @signer.sign_request(http_method: request.method, url: uri, body: request.body)
48
+ request['Host'] = signature.headers['Host']
49
+ request['X-Amz-Date'] = signature.headers['x-amz-date']
50
+ request['X-Amz-Security-Token'] = signature.headers['x-amz-security-token']
51
+ request['X-Amz-Content-Sha256']= signature.headers['x-amz-content-sha256']
52
+ request['Authorization'] = signature.headers['authorization']
53
+ request['Content-Type'] = 'application/graphql'
54
+ request
41
55
  end
42
56
  end
43
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-client-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonodar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-03 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sigv4
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashdiff
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0.beta1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0.beta1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,8 +108,36 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description: A Ruby library for declaring, composing and executing GraphQL queries
98
- for AWS AppSync
140
+ for AWS AppSync IAM Authorization
99
141
  email: ryoheisonoda@outlook.com
100
142
  executables: []
101
143
  extensions: []
@@ -126,5 +168,5 @@ requirements: []
126
168
  rubygems_version: 3.0.4
127
169
  signing_key:
128
170
  specification_version: 4
129
- summary: GraphQL Client for AWS AppSync
171
+ summary: GraphQL Client Adapter for AWS AppSync IAM Authorization
130
172
  test_files: []