graphiti 1.0.beta.17 → 1.0.beta.18
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.
- checksums.yaml +4 -4
- data/lib/generators/graphiti/install_generator.rb +4 -1
- data/lib/generators/graphiti/resource_generator.rb +30 -8
- data/lib/graphiti/adapters/abstract.rb +9 -0
- data/lib/graphiti/adapters/active_record.rb +2 -0
- data/lib/graphiti/adapters/null.rb +5 -1
- data/lib/graphiti/query.rb +4 -0
- data/lib/graphiti/schema.rb +1 -2
- data/lib/graphiti/scope.rb +1 -0
- data/lib/graphiti/scoping/paginate.rb +0 -25
- data/lib/graphiti/types.rb +7 -0
- data/lib/graphiti/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb24b2b7bb6f301a77b66b9e7648503fb66b77e6
|
4
|
+
data.tar.gz: 38f73f1c31347e2f71094299c782c38dccce527f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae790c813766213d2daa5fc6b10c36116f4425c00c9cfc6491a78facf8fbafec29809b77bbe40df533a56c1fc9f7d45013cb1acb19d4afa1f021de46274f74a5
|
7
|
+
data.tar.gz: d42f132d7757531c9f8e96f21671098085de4fafec03b819965838d3076d20a1ad75e4c7ac36d75770b2f36a6284d107541c5c1116a31766de5b691adfc22c49
|
@@ -27,7 +27,10 @@ module Graphiti
|
|
27
27
|
end
|
28
28
|
|
29
29
|
inject_into_file 'config/application.rb', after: "Rails::Application\n" do
|
30
|
-
|
30
|
+
<<-'TXT'
|
31
|
+
argv_options = Rails::Server::Options.new.parse!(ARGV)
|
32
|
+
routes.default_url_options[:host] = ENV.fetch('HOST', "http://#{argv_options[:Host]}:#{argv_options[:Port]}")
|
33
|
+
TXT
|
31
34
|
end
|
32
35
|
|
33
36
|
inject_into_file 'spec/rails_helper.rb', after: /RSpec.configure.+^end$/m do
|
@@ -22,10 +22,7 @@ module Graphiti
|
|
22
22
|
|
23
23
|
desc "This generator creates a resource file at app/resources, as well as corresponding controller/specs/route/etc"
|
24
24
|
def generate_all
|
25
|
-
|
26
|
-
raise "You must define a #{class_name} model before generating the corresponding resource."
|
27
|
-
end
|
28
|
-
|
25
|
+
generate_model
|
29
26
|
generate_controller
|
30
27
|
generate_application_resource unless application_resource_defined?
|
31
28
|
generate_route
|
@@ -36,6 +33,27 @@ module Graphiti
|
|
36
33
|
|
37
34
|
private
|
38
35
|
|
36
|
+
class ModelAction
|
37
|
+
attr_reader :class_name
|
38
|
+
def initialize(class_name)
|
39
|
+
@class_name = class_name
|
40
|
+
end
|
41
|
+
|
42
|
+
def invoke!
|
43
|
+
unless class_name.safe_constantize
|
44
|
+
raise "You must define a #{class_name} model before generating the corresponding resource."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def revoke!
|
49
|
+
# Do nothing on destroy
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_model
|
54
|
+
action(ModelAction.new(class_name))
|
55
|
+
end
|
56
|
+
|
39
57
|
def omit_comments?
|
40
58
|
@options['omit-comments']
|
41
59
|
end
|
@@ -60,11 +78,11 @@ module Graphiti
|
|
60
78
|
end
|
61
79
|
|
62
80
|
def generate_route
|
63
|
-
code = "
|
64
|
-
code <<
|
81
|
+
code = "resources :#{plural_route_name}"
|
82
|
+
code << %{, only: [#{actions.map { |a| ":#{a}" }.join(', ')}]} if actions.length < 5
|
65
83
|
code << "\n"
|
66
84
|
inject_into_file 'config/routes.rb', after: /ApplicationResource.*$\n/ do
|
67
|
-
code
|
85
|
+
indent(code, 4)
|
68
86
|
end
|
69
87
|
end
|
70
88
|
|
@@ -83,7 +101,11 @@ module Graphiti
|
|
83
101
|
def generate_resource
|
84
102
|
to = File.join('app/resources', class_path, "#{file_name}_resource.rb")
|
85
103
|
template('resource.rb.erb', to)
|
86
|
-
require "#{::Rails.root}/#{to}"
|
104
|
+
require "#{::Rails.root}/#{to}" if create?
|
105
|
+
end
|
106
|
+
|
107
|
+
def create?
|
108
|
+
behavior == :invoke
|
87
109
|
end
|
88
110
|
|
89
111
|
def model_klass
|
@@ -35,6 +35,7 @@ module Graphiti
|
|
35
35
|
:match,
|
36
36
|
:not_match
|
37
37
|
],
|
38
|
+
uuid: [:eq, :not_eq],
|
38
39
|
integer_id: numerical_operators,
|
39
40
|
integer: numerical_operators,
|
40
41
|
big_decimal: numerical_operators,
|
@@ -87,6 +88,14 @@ module Graphiti
|
|
87
88
|
raise Errors::AdapterNotImplemented.new(self, attribute, :filter_string_not_match)
|
88
89
|
end
|
89
90
|
|
91
|
+
def filter_uuid_eq(scope, attribute, value)
|
92
|
+
raise Errors::AdapterNotImplemented.new(self, attribute, :filter_uuid_eq)
|
93
|
+
end
|
94
|
+
|
95
|
+
def filter_uuid_not_eq(scope, attribute, value)
|
96
|
+
raise Errors::AdapterNotImplemented.new(self, attribute, :filter_uuid_not_eq)
|
97
|
+
end
|
98
|
+
|
90
99
|
def filter_integer_eq(scope, attribute, value)
|
91
100
|
raise Errors::AdapterNotImplemented.new(self, attribute, :filter_integer_eq)
|
92
101
|
end
|
@@ -24,6 +24,7 @@ module Graphiti
|
|
24
24
|
alias :filter_big_decimal_eq :filter_eq
|
25
25
|
alias :filter_date_eq :filter_eq
|
26
26
|
alias :filter_boolean_eq :filter_eq
|
27
|
+
alias :filter_uuid_eq :filter_eq
|
27
28
|
|
28
29
|
def filter_not_eq(scope, attribute, value)
|
29
30
|
scope.where.not(attribute => value)
|
@@ -33,6 +34,7 @@ module Graphiti
|
|
33
34
|
alias :filter_big_decimal_not_eq :filter_not_eq
|
34
35
|
alias :filter_date_not_eq :filter_not_eq
|
35
36
|
alias :filter_boolean_not_eq :filter_not_eq
|
37
|
+
alias :filter_uuid_not_eq :filter_not_eq
|
36
38
|
|
37
39
|
def filter_string_eq(scope, attribute, value, is_not: false)
|
38
40
|
column = scope.klass.arel_table[attribute]
|
@@ -181,7 +181,7 @@ module Graphiti
|
|
181
181
|
end
|
182
182
|
|
183
183
|
def base_scope(model)
|
184
|
-
|
184
|
+
{}
|
185
185
|
end
|
186
186
|
|
187
187
|
# (see Adapters::Abstract#order)
|
@@ -231,6 +231,10 @@ module Graphiti
|
|
231
231
|
def resolve(scope)
|
232
232
|
scope
|
233
233
|
end
|
234
|
+
|
235
|
+
def save(model)
|
236
|
+
model
|
237
|
+
end
|
234
238
|
end
|
235
239
|
end
|
236
240
|
end
|
data/lib/graphiti/query.rb
CHANGED
data/lib/graphiti/schema.rb
CHANGED
data/lib/graphiti/scope.rb
CHANGED
@@ -94,6 +94,7 @@ module Graphiti
|
|
94
94
|
|
95
95
|
def apply_scoping(scope, opts)
|
96
96
|
@object = scope
|
97
|
+
opts[:default_paginate] = false unless @query.paginate?
|
97
98
|
add_scoping(nil, Graphiti::Scoping::DefaultFilter, opts)
|
98
99
|
add_scoping(:filter, Graphiti::Scoping::Filter, opts)
|
99
100
|
add_scoping(:sort, Graphiti::Scoping::Sort, opts)
|
@@ -1,32 +1,7 @@
|
|
1
1
|
module Graphiti
|
2
|
-
# Apply pagination logic to the scope
|
3
|
-
#
|
4
|
-
# If the user requests a page size greater than +MAX_PAGE_SIZE+,
|
5
|
-
# a +Graphiti::Errors::UnsupportedPageSize+ error will be raised.
|
6
|
-
#
|
7
|
-
# Notably, this will not fire when the `default: false` option is passed.
|
8
|
-
# This is the case for sideloads - if the user requests "give me the post
|
9
|
-
# and its comments", we shouldn't implicitly limit those comments to 20.
|
10
|
-
# *BUT* if the user requests, "give me the post and 3 of its comments", we
|
11
|
-
# *should* honor that pagination.
|
12
|
-
#
|
13
|
-
# This can be confusing because there are also 'default' and 'customized'
|
14
|
-
# pagination procs. The default comes 'for free'. Customized pagination
|
15
|
-
# looks like
|
16
|
-
#
|
17
|
-
# class PostResource < ApplicationResource
|
18
|
-
# paginate do |scope, current_page, per_page|
|
19
|
-
# # ... the custom logic ...
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# We should use the default unless the user has customized.
|
24
|
-
# @see Resource.paginate
|
25
2
|
class Scoping::Paginate < Scoping::Base
|
26
3
|
DEFAULT_PAGE_SIZE = 20
|
27
4
|
|
28
|
-
# Apply the pagination logic. Raise error if over the max page size.
|
29
|
-
# @return the scope object we are chaining/modifying
|
30
5
|
def apply
|
31
6
|
if size > resource.max_page_size
|
32
7
|
raise Graphiti::Errors::UnsupportedPageSize
|
data/lib/graphiti/types.rb
CHANGED
@@ -86,6 +86,13 @@ module Graphiti
|
|
86
86
|
kind: 'scalar',
|
87
87
|
description: 'Base Type. Query/persist as integer, render as string.'
|
88
88
|
},
|
89
|
+
uuid: {
|
90
|
+
params: Dry::Types['coercible.string'],
|
91
|
+
read: Dry::Types['coercible.string'],
|
92
|
+
write: Dry::Types['coercible.string'],
|
93
|
+
kind: 'scalar',
|
94
|
+
description: 'Base Type. Like a normal string, but by default only eq/!eq and case-sensitive.'
|
95
|
+
},
|
89
96
|
string: {
|
90
97
|
params: Dry::Types['coercible.string'],
|
91
98
|
read: Dry::Types['coercible.string'],
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.beta.
|
4
|
+
version: 1.0.beta.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|