graph_types 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0893d8185afa382dae52941b753a942e6fbee6a2'
4
- data.tar.gz: 718fa24faf90e2d06d32b45e68351d6d00fbf328
3
+ metadata.gz: 27ffbf2b3a5de0ebeed3ff1a0515d791c19aba48
4
+ data.tar.gz: 004dc24c125a36ac75404ab1195a832bc3cfeca1
5
5
  SHA512:
6
- metadata.gz: 6be49ccf5ea9d3e6c09e73f701ef922591882716e65fd4c83adfec5bf532534bedf58efe06740155b5a5511b37b3e2265addf10506a74b5b1585de08ca94f746
7
- data.tar.gz: 6c2da755222ca946c257d2ec700c0e38781d3dc8d792a7e7da2bec90d66af848f9afcc4c7a6b37fa87eee2c4d3e7d6e0ff3c9deef66899b809b5a23ff025aab9
6
+ metadata.gz: 9552ce0f0a62de4e906f46d9913005b3d0236de3864bd41457b6f41f5f1f93dae0dc3c2f3fdf44cf079631fca0e102c0dc84d2abaa213616745953cd150bb8f7
7
+ data.tar.gz: f0a2de84dccaba7e0ebd7ec5b75c9b23f19ca1969301118537d790879d4e6c6d68c601a70906da861614183157f2807954d918b31edb33c6575dbebc0335f79b
@@ -1,3 +1,9 @@
1
+ ## v0.2.0
2
+
3
+ - Add Timestampable Interface;
4
+ - Bump Ruby to 2.4.3;
5
+ - Requiring Activerecord over all Rails as dependency.
6
+
1
7
  ## v0.1.0
2
8
 
3
9
  - DataTime type;
data/README.md CHANGED
@@ -1,26 +1,63 @@
1
1
  # GraphTypes
2
2
 
3
- [![Build Status](https://travis-ci.org/wbotelhos/graph_types.svg)](https://travis-ci.org/wbotelhos/graph_types)
3
+ [![Build Status](https://travis-ci.org/getninjas/graph_types.svg)](https://travis-ci.org/getninjas/graph_types)
4
4
  [![Gem Version](https://badge.fury.io/rb/graph_types.svg)](https://badge.fury.io/rb/graph_types)
5
5
 
6
6
  A Collection of Types for GraphQL.
7
7
 
8
- ## DateTimeType
8
+ ## Installation
9
9
 
10
+ Install from RubyGems by adding it to your `Gemfile`, then bundling.
11
+
12
+ ```ruby
13
+ # Gemfile
14
+ gem 'graph_types'
15
+ ```
16
+ ```
17
+ $ bundle install
18
+ ```
19
+
20
+ ## Types:
21
+
22
+ #### DateTimeType
23
+
24
+ Declaration:
25
+ ```ruby
26
+ DummyType = GraphQL::ObjectType.define do
27
+ name "Dummy"
28
+
29
+ field :name, !types.String
30
+ field :createdAt, !GraphTypes::DateTimeType, property: :created_at
31
+ end
32
+ ```
33
+
34
+ Search:
10
35
  ```ruby
11
36
  birthday {
12
37
  formatted(strftime: "%Y-%m-%d")
13
38
  }
14
39
  ```
15
40
 
41
+ Result:
16
42
  ```json
17
43
  "birthday": {
18
- "formatted": "2017-11-21"
44
+ "formatted": "2018-01-22"
19
45
  }
20
46
  ```
21
47
 
22
- ## MoneyType
48
+ #### MoneyType
49
+
50
+ Declaration:
51
+ ```ruby
52
+ DummyType = GraphQL::ObjectType.define do
53
+ name "Dummy"
54
+
55
+ field :name, !types.String
56
+ field :price, !GraphTypes::MoneyType, property: :price
57
+ end
58
+ ```
23
59
 
60
+ Search:
24
61
  ```ruby
25
62
  amount {
26
63
  cents
@@ -28,9 +65,43 @@ amount {
28
65
  }
29
66
  ```
30
67
 
68
+ Result:
31
69
  ```json
32
70
  "amount": {
33
71
  "cents": 10000,
34
72
  "formatted": "R$ 100,00"
35
73
  }
36
74
  ```
75
+
76
+ ## Interfaces:
77
+
78
+ #### TimestampableInterface:
79
+
80
+ Declaration:
81
+ ```ruby
82
+ DummyType = GraphQL::ObjectType.define do
83
+ name "Dummy"
84
+
85
+ interfaces [TimestampableInterface]
86
+ end
87
+ ```
88
+
89
+ Search:
90
+ ```ruby
91
+ dummy {
92
+ createdAt {
93
+ formatted(strftime: "%FT%T%Z")
94
+ }
95
+ updatedAt {
96
+ formatted(strftime: "%FT%T%Z")
97
+ }
98
+ }
99
+ ```
100
+
101
+ Result:
102
+ ```json
103
+ "dummy": {
104
+ "createdAt": "2018-01-11T17:36:07BRST",
105
+ "updatedAt": "2018-01-11T17:36:07BRST"
106
+ }
107
+ ```
@@ -4,5 +4,8 @@ module GraphTypes
4
4
  end
5
5
 
6
6
  require 'graphql'
7
- require 'graph_types/date_time_type'
8
- require 'graph_types/money_type'
7
+
8
+ require 'graph_types/types/date_time_type'
9
+ require 'graph_types/types/money_type'
10
+
11
+ require 'graph_types/interfaces/timestampable_interface'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ TimestampableInterface = GraphQL::InterfaceType.define do
4
+ name "Timestampable"
5
+
6
+ description "An object that have timestamps fields (created_at and updated_at)."
7
+
8
+ field :createdAt, !GraphTypes::DateTimeType, property: :created_at
9
+
10
+ field :updatedAt, !GraphTypes::DateTimeType, property: :updated_at
11
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GraphTypes
4
4
  DateTimeType = ::GraphQL::ObjectType.define do
5
- name 'DateTimeType'
5
+ name 'DateTime'
6
6
 
7
7
  field :formatted, types.String do
8
8
  argument :strftime, types.String, default_value: '%FT%T%Z'
@@ -2,7 +2,7 @@
2
2
 
3
3
  module GraphTypes
4
4
  MoneyType = ::GraphQL::ObjectType.define do
5
- name 'MoneyType'
5
+ name 'Money'
6
6
 
7
7
  field :cents, types.Int do
8
8
  resolve ->(object, _args, _context) do
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphTypes
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe TimestampableInterface do
6
+ let!(:value) { Time.local 2018 }
7
+ let!(:dummy) { OpenStruct.new created_at: value, updated_at: value }
8
+
9
+ subject { TimestampableInterface }
10
+
11
+ describe 'fields' do
12
+ let(:result) { field.resolve(dummy, nil, nil) }
13
+
14
+ describe '.createdAt' do
15
+ let(:field) { subject.fields['createdAt'] }
16
+
17
+ it { expect(result).to eq dummy[:created_at] }
18
+ it { expect(field.type.to_s).to eq 'DateTime!' }
19
+ end
20
+
21
+ describe '.updatedAt' do
22
+ let(:field) { subject.fields['updatedAt'] }
23
+
24
+ it { expect(result).to eq dummy[:updated_at] }
25
+ it { expect(field.type.to_s).to eq 'DateTime!' }
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,49 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GetNinjas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-23 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: graphql
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
27
33
  - !ruby/object:Gem::Dependency
28
- name: rails
34
+ name: graphql
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '5'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '6'
39
+ version: '0'
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
44
  - - ">="
42
45
  - !ruby/object:Gem::Version
43
- version: '5'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '6'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: database_cleaner
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -125,11 +125,13 @@ files:
125
125
  - LICENSE
126
126
  - README.md
127
127
  - lib/graph_types.rb
128
- - lib/graph_types/date_time_type.rb
129
- - lib/graph_types/money_type.rb
128
+ - lib/graph_types/interfaces/timestampable_interface.rb
129
+ - lib/graph_types/types/date_time_type.rb
130
+ - lib/graph_types/types/money_type.rb
130
131
  - lib/graph_types/version.rb
131
- - spec/lib/graph_types/data_time_type_spec.rb
132
- - spec/lib/graph_types/money_type_spec.rb
132
+ - spec/lib/graph_types/interfaces/timestampable_interface_spec.rb
133
+ - spec/lib/graph_types/types/data_time_type_spec.rb
134
+ - spec/lib/graph_types/types/money_type_spec.rb
133
135
  - spec/lib/graph_types/version_spec.rb
134
136
  - spec/rails_helper.rb
135
137
  - spec/support/common.rb
@@ -159,7 +161,8 @@ specification_version: 4
159
161
  summary: A Collection of Types for GraphQL
160
162
  test_files:
161
163
  - spec/support/common.rb
162
- - spec/lib/graph_types/data_time_type_spec.rb
164
+ - spec/lib/graph_types/types/data_time_type_spec.rb
165
+ - spec/lib/graph_types/types/money_type_spec.rb
163
166
  - spec/lib/graph_types/version_spec.rb
164
- - spec/lib/graph_types/money_type_spec.rb
167
+ - spec/lib/graph_types/interfaces/timestampable_interface_spec.rb
165
168
  - spec/rails_helper.rb