graph_types 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '0893d8185afa382dae52941b753a942e6fbee6a2'
4
+ data.tar.gz: 718fa24faf90e2d06d32b45e68351d6d00fbf328
5
+ SHA512:
6
+ metadata.gz: 6be49ccf5ea9d3e6c09e73f701ef922591882716e65fd4c83adfec5bf532534bedf58efe06740155b5a5511b37b3e2265addf10506a74b5b1585de08ca94f746
7
+ data.tar.gz: 6c2da755222ca946c257d2ec700c0e38781d3dc8d792a7e7da2bec90d66af848f9afcc4c7a6b37fa87eee2c4d3e7d6e0ff3c9deef66899b809b5a23ff025aab9
@@ -0,0 +1,4 @@
1
+ ## v0.1.0
2
+
3
+ - DataTime type;
4
+ - Money type.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 GetNinjas
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.
@@ -0,0 +1,36 @@
1
+ # GraphTypes
2
+
3
+ [![Build Status](https://travis-ci.org/wbotelhos/graph_types.svg)](https://travis-ci.org/wbotelhos/graph_types)
4
+ [![Gem Version](https://badge.fury.io/rb/graph_types.svg)](https://badge.fury.io/rb/graph_types)
5
+
6
+ A Collection of Types for GraphQL.
7
+
8
+ ## DateTimeType
9
+
10
+ ```ruby
11
+ birthday {
12
+ formatted(strftime: "%Y-%m-%d")
13
+ }
14
+ ```
15
+
16
+ ```json
17
+ "birthday": {
18
+ "formatted": "2017-11-21"
19
+ }
20
+ ```
21
+
22
+ ## MoneyType
23
+
24
+ ```ruby
25
+ amount {
26
+ cents
27
+ formatted(delimiter: ".", separator: ",", unit: "R$ ")
28
+ }
29
+ ```
30
+
31
+ ```json
32
+ "amount": {
33
+ "cents": 10000,
34
+ "formatted": "R$ 100,00"
35
+ }
36
+ ```
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphTypes
4
+ end
5
+
6
+ require 'graphql'
7
+ require 'graph_types/date_time_type'
8
+ require 'graph_types/money_type'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphTypes
4
+ DateTimeType = ::GraphQL::ObjectType.define do
5
+ name 'DateTimeType'
6
+
7
+ field :formatted, types.String do
8
+ argument :strftime, types.String, default_value: '%FT%T%Z'
9
+
10
+ resolve ->(object, args, _context) do
11
+ object.strftime args[:strftime]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphTypes
4
+ MoneyType = ::GraphQL::ObjectType.define do
5
+ name 'MoneyType'
6
+
7
+ field :cents, types.Int do
8
+ resolve ->(object, _args, _context) do
9
+ (object.to_f * 100).to_i
10
+ end
11
+ end
12
+
13
+ field :formatted, types.String do
14
+ argument :delimiter, types.String, default_value: '.'
15
+ argument :separator, types.String, default_value: ','
16
+ argument :unit, types.String, default_value: 'R$ '
17
+
18
+ resolve ->(object, args, _context) do
19
+ ActionController::Base.helpers.number_to_currency object.to_f, args.to_h
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphTypes
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe GraphTypes::DateTimeType, '.formatted' do
6
+ let!(:value) { Time.local 2017 }
7
+ let!(:field) { described_class.fields['formatted'] }
8
+
9
+ specify { expect(field.type.to_s).to eq 'String' }
10
+
11
+ describe ':strftime' do
12
+ let(:argument) { field.arguments['strftime'] }
13
+
14
+ specify { expect(argument.type.to_s).to eq 'String' }
15
+ specify { expect(argument.default_value).to eq '%FT%T%Z' }
16
+
17
+ describe '.resolve' do
18
+ subject { field.resolve value, { strftime: '%d/%m/%Y' }, nil }
19
+
20
+ specify { expect(subject).to eq '01/01/2017' }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe GraphTypes::MoneyType, '.formatted' do
6
+ let!(:value) { 1000 }
7
+ let!(:field) { described_class.fields['formatted'] }
8
+
9
+ specify { expect(field.type.to_s).to eq 'String' }
10
+
11
+ describe ':delimiter' do
12
+ let(:argument) { field.arguments['delimiter'] }
13
+
14
+ specify { expect(argument.type.to_s).to eq 'String' }
15
+ specify { expect(argument.default_value).to eq '.' }
16
+
17
+ describe '.resolve' do
18
+ subject { field.resolve value, { delimiter: '*' }, nil }
19
+
20
+ specify { expect(subject).to eq '$1*000.00' }
21
+ end
22
+ end
23
+
24
+ describe ':separator' do
25
+ let(:argument) { field.arguments['separator'] }
26
+
27
+ specify { expect(argument.type.to_s).to eq 'String' }
28
+ specify { expect(argument.default_value).to eq ',' }
29
+
30
+ describe '.resolve' do
31
+ subject { field.resolve value, { separator: '*' }, nil }
32
+
33
+ specify { expect(subject).to eq '$1,000*00' }
34
+ end
35
+ end
36
+
37
+ describe ':unit' do
38
+ let(:argument) { field.arguments['unit'] }
39
+
40
+ specify { expect(argument.type.to_s).to eq 'String' }
41
+ specify { expect(argument.default_value).to eq 'R$ ' }
42
+
43
+ describe '.resolve' do
44
+ subject { field.resolve value, { unit: '*' }, nil }
45
+
46
+ specify { expect(subject).to eq '*1,000.00' }
47
+ end
48
+ end
49
+
50
+ context 'when all arguments is given' do
51
+ describe '.resolve' do
52
+ subject do
53
+ field.resolve value, { delimiter: '!', separator: '@', unit: '*' }, nil
54
+ end
55
+
56
+ specify { expect(subject).to eq '*1!000@00' }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe GraphTypes, 'VERSION' do
6
+ specify { expect(described_class::VERSION).not_to eq nil }
7
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ require 'active_record/railtie'
6
+ require 'graph_types'
7
+ require 'pry-byebug'
8
+
9
+ ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
10
+
11
+ Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/rails'
4
+
5
+ RSpec.configure do |config|
6
+ config.filter_run_when_matching :focus
7
+
8
+ config.disable_monkey_patching!
9
+
10
+ config.order = :random
11
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graph_types
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - GetNinjas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphql
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '5'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: database_cleaner
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: pry-byebug
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-rails
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: A Collection of Types for GraphQL.
118
+ email:
119
+ - tech@getninjas.com.br
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - CHANGELOG.md
125
+ - LICENSE
126
+ - README.md
127
+ - lib/graph_types.rb
128
+ - lib/graph_types/date_time_type.rb
129
+ - lib/graph_types/money_type.rb
130
+ - lib/graph_types/version.rb
131
+ - spec/lib/graph_types/data_time_type_spec.rb
132
+ - spec/lib/graph_types/money_type_spec.rb
133
+ - spec/lib/graph_types/version_spec.rb
134
+ - spec/rails_helper.rb
135
+ - spec/support/common.rb
136
+ homepage: https://github.com/getninjas/graph_types
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.6.14
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: A Collection of Types for GraphQL
160
+ test_files:
161
+ - spec/support/common.rb
162
+ - spec/lib/graph_types/data_time_type_spec.rb
163
+ - spec/lib/graph_types/version_spec.rb
164
+ - spec/lib/graph_types/money_type_spec.rb
165
+ - spec/rails_helper.rb