graphoid 0.0.2 → 0.0.4

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -32
  3. data/Rakefile +2 -6
  4. data/lib/graphoid/argument.rb +3 -0
  5. data/lib/graphoid/config.rb +2 -0
  6. data/lib/graphoid/definitions/filters.rb +7 -8
  7. data/lib/graphoid/definitions/inputs.rb +8 -6
  8. data/lib/graphoid/definitions/orders.rb +5 -5
  9. data/lib/graphoid/definitions/types.rb +46 -40
  10. data/lib/graphoid/drivers/active_record.rb +37 -37
  11. data/lib/graphoid/drivers/mongoid.rb +75 -53
  12. data/lib/graphoid/graphield.rb +6 -6
  13. data/lib/graphoid/grapho.rb +2 -0
  14. data/lib/graphoid/main.rb +6 -4
  15. data/lib/graphoid/mapper.rb +5 -2
  16. data/lib/graphoid/mutations/create.rb +12 -14
  17. data/lib/graphoid/mutations/delete.rb +12 -14
  18. data/lib/graphoid/mutations/processor.rb +3 -1
  19. data/lib/graphoid/mutations/structure.rb +2 -0
  20. data/lib/graphoid/mutations/update.rb +2 -0
  21. data/lib/graphoid/operators/attribute.rb +6 -5
  22. data/lib/graphoid/operators/inherited/belongs_to.rb +10 -8
  23. data/lib/graphoid/operators/inherited/embeds_many.rb +17 -3
  24. data/lib/graphoid/operators/inherited/embeds_one.rb +17 -3
  25. data/lib/graphoid/operators/inherited/has_many.rb +4 -2
  26. data/lib/graphoid/operators/inherited/has_one.rb +9 -7
  27. data/lib/graphoid/operators/inherited/many_to_many.rb +4 -2
  28. data/lib/graphoid/operators/relation.rb +8 -9
  29. data/lib/graphoid/queries/operation.rb +2 -0
  30. data/lib/graphoid/queries/processor.rb +7 -5
  31. data/lib/graphoid/queries/queries.rb +16 -17
  32. data/lib/graphoid/scalars.rb +28 -26
  33. data/lib/graphoid/utils.rb +6 -4
  34. data/lib/graphoid/version.rb +3 -1
  35. data/lib/graphoid.rb +2 -0
  36. metadata +15 -28
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Graphoid
2
4
  module Queries
3
5
  extend ActiveSupport::Concern
@@ -14,35 +16,32 @@ module Graphoid
14
16
  end
15
17
 
16
18
  query_type.field name: grapho.plural, type: [grapho.type], null: true do
17
- Graphoid::Argument.query_many(self, grapho.filter, grapho.order, { required: false })
19
+ Graphoid::Argument.query_many(self, grapho.filter, grapho.order, required: false)
18
20
  end
19
21
 
20
22
  query_type.field name: "_#{grapho.plural}_meta", type: Graphoid::Types::Meta, null: true do
21
- Graphoid::Argument.query_many(self, grapho.filter, grapho.order, { required: false })
23
+ Graphoid::Argument.query_many(self, grapho.filter, grapho.order, required: false)
22
24
  end
23
25
 
24
26
  query_type.class_eval do
25
27
  define_method :"#{grapho.name}" do |id: nil, where: nil|
26
- begin
27
- return model.find(id) if id
28
- Processor.execute(model, where.to_h).first
29
- rescue Exception => ex
30
- GraphQL::ExecutionError.new(ex.message)
31
- end
28
+ return model.find(id) if id
29
+
30
+ Processor.execute(model, where.to_h).first
31
+ rescue Exception => ex
32
+ GraphQL::ExecutionError.new(ex.message)
32
33
  end
33
34
  end
34
35
 
35
36
  query_type.class_eval do
36
37
  define_method :"#{grapho.plural}" do |where: nil, order: nil, limit: nil, skip: nil|
37
- begin
38
- model = Graphoid.driver.eager_load(context.irep_node, model)
39
- result = Processor.execute(model, where.to_h)
40
- order = Processor.parse_order(model, order.to_h)
41
- result = result.order(order).limit(limit)
42
- Graphoid.driver.skip(result, skip)
43
- rescue Exception => ex
44
- GraphQL::ExecutionError.new(ex.message)
45
- end
38
+ model = Graphoid.driver.eager_load(context.irep_node, model)
39
+ result = Processor.execute(model, where.to_h)
40
+ order = Processor.parse_order(model, order.to_h)
41
+ result = result.order(order).limit(limit)
42
+ Graphoid.driver.skip(result, skip)
43
+ rescue Exception => ex
44
+ GraphQL::ExecutionError.new(ex.message)
46
45
  end
47
46
 
48
47
  alias_method :"_#{grapho.plural}_meta", :"#{grapho.plural}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Graphoid
2
4
  module Upload
3
5
  end
@@ -6,80 +8,80 @@ module Graphoid
6
8
  class << self
7
9
  def generate
8
10
  Graphoid::Scalars::DateTime ||= GraphQL::ScalarType.define do
9
- name "DateTime"
10
- description "DateTime ISO8601 formated"
11
+ name 'DateTime'
12
+ description 'DateTime ISO8601 formated'
11
13
 
12
- coerce_input -> (value, _) do
14
+ coerce_input lambda { |value, _|
13
15
  begin
14
16
  ::DateTime.iso8601(value)
15
17
  rescue Exception => ex
16
18
  GraphQL::ExecutionError.new(ex)
17
19
  end
18
- end
20
+ }
19
21
  end
20
22
 
21
23
  Graphoid::Scalars::Date ||= GraphQL::ScalarType.define do
22
- name "Date"
23
- description "Date ISO8601 formated"
24
+ name 'Date'
25
+ description 'Date ISO8601 formated'
24
26
 
25
- coerce_input -> (value, _) do
27
+ coerce_input lambda { |value, _|
26
28
  begin
27
29
  ::DateTime.iso8601(value)
28
30
  rescue Exception => ex
29
31
  GraphQL::ExecutionError.new(ex)
30
32
  end
31
- end
33
+ }
32
34
  end
33
35
 
34
36
  Graphoid::Scalars::Time ||= GraphQL::ScalarType.define do
35
- name "Time"
36
- description "Time ISO8601 formated"
37
+ name 'Time'
38
+ description 'Time ISO8601 formated'
37
39
 
38
- coerce_input -> (value, _) do
40
+ coerce_input lambda { |value, _|
39
41
  begin
40
42
  ::DateTime.iso8601(value)
41
43
  rescue Exception => ex
42
44
  GraphQL::ExecutionError.new(ex)
43
45
  end
44
- end
46
+ }
45
47
  end
46
48
 
47
49
  Graphoid::Scalars::Timestamp ||= GraphQL::ScalarType.define do
48
- name "Timestamp"
49
- description "Second elapsed since 1970-01-01"
50
+ name 'Timestamp'
51
+ description 'Second elapsed since 1970-01-01'
50
52
 
51
- coerce_input -> (value, _) do
53
+ coerce_input lambda { |value, _|
52
54
  begin
53
55
  ::DateTime.iso8601(value)
54
56
  rescue Exception => ex
55
57
  GraphQL::ExecutionError.new(ex)
56
58
  end
57
- end
59
+ }
58
60
  end
59
61
 
60
62
  Graphoid::Scalars::Text ||= GraphQL::ScalarType.define do
61
- name "Text"
62
- description "Should be string? explain this please."
63
+ name 'Text'
64
+ description 'Should be string? explain this please.'
63
65
  end
64
66
 
65
67
  Graphoid::Scalars::BigInt ||= GraphQL::ScalarType.define do
66
- name "BigInt"
67
- description "WTF ??"
68
+ name 'BigInt'
69
+ description 'WTF ??'
68
70
  end
69
71
 
70
72
  Graphoid::Scalars::Decimal ||= GraphQL::ScalarType.define do
71
- name "Decimal"
72
- description "Define pliiiizzzzzzz"
73
+ name 'Decimal'
74
+ description 'Define pliiiizzzzzzz'
73
75
  end
74
76
 
75
77
  Graphoid::Scalars::Hash ||= GraphQL::ScalarType.define do
76
- name "Hash"
77
- description "Hash scalar"
78
+ name 'Hash'
79
+ description 'Hash scalar'
78
80
  end
79
81
 
80
82
  Graphoid::Scalars::Array ||= GraphQL::ScalarType.define do
81
- name "Array"
82
- description "Array scalar"
83
+ name 'Array'
84
+ description 'Array scalar'
83
85
  end
84
86
  end
85
87
  end
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Graphoid
2
4
  module Utils
3
5
  class << self
4
- def modelize text
6
+ def modelize(text)
5
7
  graphqlize text.to_s.capitalize.camelize
6
8
  end
7
9
 
8
- def camelize text
10
+ def camelize(text)
9
11
  # we are doing it twice because _id gets translated to Id the first time and to id the second time.
10
12
  graphqlize text.to_s.camelize(:lower).camelize(:lower)
11
13
  end
12
14
 
13
- def graphqlize text
15
+ def graphqlize(text)
14
16
  text.to_s.gsub(/::/, '_')
15
17
  end
16
18
 
@@ -18,7 +20,7 @@ module Graphoid
18
20
  fields.keys.map(&:underscore).map(&:to_sym)
19
21
  end
20
22
 
21
- def underscore props, fields = []
23
+ def underscore(props, fields = [])
22
24
  attrs = {}
23
25
  props.each do |key, value|
24
26
  key = key.underscore if fields.exclude?(key)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Graphoid
2
- VERSION = '0.0.2'
4
+ VERSION = '0.0.4'
3
5
  end
data/lib/graphoid.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'graphoid/utils'
2
4
  require 'graphoid/grapho'
3
5
  require 'graphoid/mapper'
metadata CHANGED
@@ -1,58 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximiliano Perez Coto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: graphql
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.0
19
+ version: 1.8.17
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.0
26
+ version: 1.8.17
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec-collection_matchers
28
+ name: rails
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ">="
31
+ - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
33
+ version: 5.1.6
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: A gem that helps you autogenerate a GraphQL api from MongoId models.
40
+ version: 5.1.6
41
+ description: A gem that helps you autogenerate a GraphQL API from Mongoid or ActiveRecord
42
+ models.
56
43
  email:
57
44
  - maxiperezc@gmail.com
58
45
  executables: []
@@ -94,7 +81,7 @@ files:
94
81
  - lib/graphoid/scalars.rb
95
82
  - lib/graphoid/utils.rb
96
83
  - lib/graphoid/version.rb
97
- homepage: http://www.github.com/maxiperezc/graphoid
84
+ homepage: http://www.maxiperezcoto.com
98
85
  licenses:
99
86
  - MIT
100
87
  metadata: {}
@@ -116,5 +103,5 @@ requirements: []
116
103
  rubygems_version: 3.0.3
117
104
  signing_key:
118
105
  specification_version: 4
119
- summary: Generate GraphQL from ActiveRecord or Mongoid
106
+ summary: Generates a GraphQL API from Rails ActiveRecord or Mongoid
120
107
  test_files: []