graphiti_graphql 0.1.8 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +26 -26
- data/graphiti_graphql.gemspec +1 -1
- data/lib/graphiti_graphql/engine.rb +0 -2
- data/lib/graphiti_graphql/federation/resource_dsl.rb +7 -2
- data/lib/graphiti_graphql/schema.rb +19 -12
- data/lib/graphiti_graphql/version.rb +1 -1
- data/lib/graphiti_graphql.rb +5 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e50aa66c6cf3fda89d96665c6f2fc61fa92db821b4d00461101970d72c24eea6
|
4
|
+
data.tar.gz: 1e058e770b73378802fd43b3e852720d9cfa9b5b80cfc77c40ea1e2e2ea602df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ecb9fda5f17d3414b2ae8a39f5e9fddb40f34ed683fc9d966c1098bd86f93422e9ee77439c8f27faed1384ab5876ee67bbfc296980f314c7f656930edee3734
|
7
|
+
data.tar.gz: f00540102b8cccd704a2ef2d6b7cb787c750f23858b78e425e1dc59e452065b16c9d8788065c0a0c2e87a653fac70d803f743f72ead06405f207e549e0f8e132
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphiti_graphql (0.1.
|
4
|
+
graphiti_graphql (0.1.12)
|
5
5
|
activesupport (>= 4.1)
|
6
|
-
graphiti (~> 1.3)
|
6
|
+
graphiti (~> 1.3.2)
|
7
7
|
graphql (~> 1.12)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (6.1.1)
|
13
|
-
activesupport (= 6.1.1)
|
14
|
-
activesupport (6.1.1)
|
12
|
+
activemodel (6.1.4.1)
|
13
|
+
activesupport (= 6.1.4.1)
|
14
|
+
activesupport (6.1.4.1)
|
15
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
16
|
i18n (>= 1.6, < 2)
|
17
17
|
minitest (>= 5.1)
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
ast (2.4.2)
|
24
24
|
byebug (11.1.3)
|
25
25
|
coderay (1.1.3)
|
26
|
-
concurrent-ruby (1.1.
|
26
|
+
concurrent-ruby (1.1.9)
|
27
27
|
diff-lcs (1.4.4)
|
28
28
|
dry-configurable (0.12.1)
|
29
29
|
concurrent-ruby (~> 1.0)
|
@@ -43,8 +43,8 @@ GEM
|
|
43
43
|
dry-core (~> 0.5, >= 0.5)
|
44
44
|
dry-inflector (~> 0.1, >= 0.1.2)
|
45
45
|
dry-logic (~> 1.0, >= 1.0.2)
|
46
|
-
google-protobuf (3.
|
47
|
-
graphiti (1.3.
|
46
|
+
google-protobuf (3.17.3)
|
47
|
+
graphiti (1.3.2)
|
48
48
|
activesupport (>= 4.1)
|
49
49
|
concurrent-ruby (~> 1.0)
|
50
50
|
dry-types (>= 0.15.0, < 2.0)
|
@@ -56,11 +56,11 @@ GEM
|
|
56
56
|
graphiti_spec_helpers (1.0.5)
|
57
57
|
graphiti (>= 1.0.alpha.1)
|
58
58
|
rspec (~> 3.0)
|
59
|
-
graphql (1.12.
|
59
|
+
graphql (1.12.15)
|
60
60
|
graphql-batch (0.4.3)
|
61
61
|
graphql (>= 1.3, < 2)
|
62
62
|
promise.rb (~> 0.7.2)
|
63
|
-
i18n (1.8.
|
63
|
+
i18n (1.8.10)
|
64
64
|
concurrent-ruby (~> 1.0)
|
65
65
|
jsonapi-renderer (0.2.2)
|
66
66
|
jsonapi-serializable (0.3.1)
|
@@ -68,19 +68,19 @@ GEM
|
|
68
68
|
method_source (1.0.0)
|
69
69
|
minitest (5.14.4)
|
70
70
|
parallel (1.20.1)
|
71
|
-
parser (3.0.
|
71
|
+
parser (3.0.2.0)
|
72
72
|
ast (~> 2.4.1)
|
73
73
|
promise.rb (0.7.4)
|
74
|
-
pry (0.
|
74
|
+
pry (0.14.1)
|
75
75
|
coderay (~> 1.1)
|
76
76
|
method_source (~> 1.0)
|
77
|
-
pry-byebug (3.
|
77
|
+
pry-byebug (3.8.0)
|
78
78
|
byebug (~> 11.0)
|
79
|
-
pry (~> 0.
|
79
|
+
pry (~> 0.10)
|
80
80
|
rainbow (3.0.0)
|
81
81
|
rake (10.5.0)
|
82
|
-
regexp_parser (2.
|
83
|
-
rexml (3.2.
|
82
|
+
regexp_parser (2.1.1)
|
83
|
+
rexml (3.2.5)
|
84
84
|
rspec (3.10.0)
|
85
85
|
rspec-core (~> 3.10.0)
|
86
86
|
rspec-expectations (~> 3.10.0)
|
@@ -94,24 +94,24 @@ GEM
|
|
94
94
|
diff-lcs (>= 1.2.0, < 2.0)
|
95
95
|
rspec-support (~> 3.10.0)
|
96
96
|
rspec-support (3.10.2)
|
97
|
-
rubocop (1.
|
97
|
+
rubocop (1.20.0)
|
98
98
|
parallel (~> 1.10)
|
99
99
|
parser (>= 3.0.0.0)
|
100
100
|
rainbow (>= 2.2.2, < 4.0)
|
101
101
|
regexp_parser (>= 1.8, < 3.0)
|
102
102
|
rexml
|
103
|
-
rubocop-ast (>= 1.
|
103
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
104
104
|
ruby-progressbar (~> 1.7)
|
105
105
|
unicode-display_width (>= 1.4.0, < 3.0)
|
106
|
-
rubocop-ast (1.
|
107
|
-
parser (>=
|
108
|
-
rubocop-performance (1.
|
109
|
-
rubocop (>=
|
106
|
+
rubocop-ast (1.11.0)
|
107
|
+
parser (>= 3.0.1.1)
|
108
|
+
rubocop-performance (1.11.5)
|
109
|
+
rubocop (>= 1.7.0, < 2.0)
|
110
110
|
rubocop-ast (>= 0.4.0)
|
111
111
|
ruby-progressbar (1.11.0)
|
112
|
-
standard (
|
113
|
-
rubocop (= 1.
|
114
|
-
rubocop-performance (= 1.
|
112
|
+
standard (1.3.0)
|
113
|
+
rubocop (= 1.20.0)
|
114
|
+
rubocop-performance (= 1.11.5)
|
115
115
|
standardrb (1.0.0)
|
116
116
|
standard
|
117
117
|
tzinfo (2.0.4)
|
@@ -137,4 +137,4 @@ DEPENDENCIES
|
|
137
137
|
standardrb
|
138
138
|
|
139
139
|
BUNDLED WITH
|
140
|
-
2.2.
|
140
|
+
2.2.25
|
data/graphiti_graphql.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
spec.add_dependency "graphiti", "~> 1.3"
|
30
|
+
spec.add_dependency "graphiti", "~> 1.3.2"
|
31
31
|
spec.add_dependency "activesupport", ">= 4.1"
|
32
32
|
spec.add_dependency "graphql", "~> 1.12"
|
33
33
|
|
@@ -64,7 +64,6 @@ module GraphitiGraphQL
|
|
64
64
|
end
|
65
65
|
|
66
66
|
initializer "graphiti_graphql.define_controller" do
|
67
|
-
GraphitiGraphQL::Engine.reloader_class.to_prepare do
|
68
67
|
app_controller = GraphitiGraphQL.config.federation_application_controller || ::ApplicationController
|
69
68
|
# rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
|
70
69
|
class GraphitiGraphQL::ExecutionController < app_controller
|
@@ -74,7 +73,6 @@ module GraphitiGraphQL
|
|
74
73
|
render json: Graphiti.gql(params[:query], params[:variables])
|
75
74
|
end
|
76
75
|
end
|
77
|
-
end
|
78
76
|
end
|
79
77
|
|
80
78
|
initializer "graphiti_graphql.federation" do
|
@@ -7,10 +7,11 @@ module GraphitiGraphQL
|
|
7
7
|
@type_name = type_name
|
8
8
|
end
|
9
9
|
|
10
|
-
def has_many(relationship_name, foreign_key: nil, &blk)
|
10
|
+
def has_many(relationship_name, foreign_key: nil, magic: true, &blk)
|
11
11
|
@caller.federated_has_many relationship_name,
|
12
12
|
type: @type_name,
|
13
13
|
foreign_key: foreign_key,
|
14
|
+
magic: magic,
|
14
15
|
&blk
|
15
16
|
end
|
16
17
|
end
|
@@ -29,14 +30,18 @@ module GraphitiGraphQL
|
|
29
30
|
config[:federated_resources] ||= []
|
30
31
|
end
|
31
32
|
|
33
|
+
# NB - for external use, use federated_type("Type").has_many instead
|
34
|
+
#
|
32
35
|
# * Add to the list of external graphql-ruby types we need in schema
|
33
36
|
# * Add a readable and filterable FK, without clobbering pre-existing
|
34
|
-
def federated_has_many(name, type:, foreign_key: nil, &blk)
|
37
|
+
def federated_has_many(name, type:, magic: true, foreign_key: nil, &blk)
|
35
38
|
foreign_key ||= :"#{type.underscore}_id"
|
36
39
|
resource = FederatedResource.new(type)
|
37
40
|
federated_resources << resource
|
38
41
|
resource.add_relationship(:has_many, name, self, foreign_key, &blk)
|
39
42
|
|
43
|
+
return unless magic
|
44
|
+
|
40
45
|
attribute = attributes.find { |name, config|
|
41
46
|
name.to_sym == foreign_key &&
|
42
47
|
!!config[:readable] &&
|
@@ -52,14 +52,18 @@ module GraphitiGraphQL
|
|
52
52
|
@base_interface || BaseInterface
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.generate(
|
55
|
+
def self.generate(resources: nil, entrypoints: nil)
|
56
56
|
instance = new
|
57
57
|
schema = Class.new(::GraphitiGraphQL.schema_class || GraphQL::Schema)
|
58
58
|
graphiti_schema = GraphitiGraphQL::GraphitiSchema::Wrapper
|
59
59
|
.new(Graphiti::Schema.generate)
|
60
60
|
instance.graphiti_schema = graphiti_schema
|
61
|
+
|
62
|
+
resources ||= graphiti_schema.resources
|
63
|
+
entrypoints ||= self.entrypoints || resources
|
64
|
+
|
61
65
|
instance.schema = schema
|
62
|
-
instance.apply_query(
|
66
|
+
instance.apply_query(resources, entrypoints)
|
63
67
|
instance
|
64
68
|
end
|
65
69
|
|
@@ -72,8 +76,8 @@ module GraphitiGraphQL
|
|
72
76
|
@query_fields = {}
|
73
77
|
end
|
74
78
|
|
75
|
-
def apply_query(
|
76
|
-
query_type = generate_schema_query(
|
79
|
+
def apply_query(resources, entrypoints)
|
80
|
+
query_type = generate_schema_query(resources, entrypoints)
|
77
81
|
Federation::SchemaDecorator.decorate(self) if self.class.federation?
|
78
82
|
|
79
83
|
# NB - don't call .query here of federation will break things
|
@@ -86,7 +90,7 @@ module GraphitiGraphQL
|
|
86
90
|
schema.query # Actually fires the federation code
|
87
91
|
end
|
88
92
|
|
89
|
-
def generate_schema_query(
|
93
|
+
def generate_schema_query(resources, entrypoints)
|
90
94
|
existing_query = schema.instance_variable_get(:@query)
|
91
95
|
existing_query ||= schema.send(:find_inherited_value, :query)
|
92
96
|
# NB - don't call graphql_schema.query here of federation will break things
|
@@ -95,10 +99,13 @@ module GraphitiGraphQL
|
|
95
99
|
query_class.graphql_name "Query"
|
96
100
|
query_class.field_class BaseField
|
97
101
|
|
98
|
-
|
99
|
-
|
102
|
+
# Ensure all types are generated, even if they aren't in a top-level Query
|
103
|
+
# We might now want to expose the query, but do want to federate the Type
|
104
|
+
get_schema_resources(resources).each do |resource|
|
100
105
|
generate_type(resource)
|
106
|
+
end
|
101
107
|
|
108
|
+
get_schema_resources(entrypoints).each do |resource|
|
102
109
|
add_index(query_class, resource)
|
103
110
|
add_show(query_class, resource)
|
104
111
|
end
|
@@ -198,14 +205,14 @@ module GraphitiGraphQL
|
|
198
205
|
top_level_single: true
|
199
206
|
end
|
200
207
|
|
201
|
-
def
|
208
|
+
def get_schema_resources(manually_specified)
|
202
209
|
resources = graphiti_schema.resources
|
203
210
|
if manually_specified
|
204
211
|
resources = resources.select { |r|
|
205
212
|
manually_specified.map(&:name).include?(r.name)
|
206
213
|
}
|
207
214
|
end
|
208
|
-
resources
|
215
|
+
resources.reject(&:remote?)
|
209
216
|
end
|
210
217
|
|
211
218
|
def generate_sort_att_type_for(resource)
|
@@ -505,7 +512,7 @@ module GraphitiGraphQL
|
|
505
512
|
end
|
506
513
|
|
507
514
|
class PageType < GraphQL::Schema::InputObject
|
508
|
-
graphql_name "
|
515
|
+
graphql_name "PageInput"
|
509
516
|
argument :size, Int, required: false
|
510
517
|
argument :number, Int, required: false
|
511
518
|
argument :after, String, required: false
|
@@ -516,8 +523,8 @@ module GraphitiGraphQL
|
|
516
523
|
graphql_name "PageInfo"
|
517
524
|
field :has_next_page, Boolean, null: false
|
518
525
|
field :has_previous_page, Boolean, null: false
|
519
|
-
field :start_cursor, String, null:
|
520
|
-
field :end_cursor, String, null:
|
526
|
+
field :start_cursor, String, null: true
|
527
|
+
field :end_cursor, String, null: true
|
521
528
|
end
|
522
529
|
|
523
530
|
class SortDirType < GraphQL::Schema::Enum
|
data/lib/graphiti_graphql.rb
CHANGED
@@ -53,8 +53,11 @@ module GraphitiGraphQL
|
|
53
53
|
@generated ||= GraphitiGraphQL::Schema.generate
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
# resources: All resources to put in the schema. Mostly just for testing.
|
57
|
+
# entrypoints: All resources to expose as top-level query objects
|
58
|
+
def generate!(resources: nil, entrypoints: nil)
|
59
|
+
@generated = GraphitiGraphQL::Schema
|
60
|
+
.generate(resources: resources, entrypoints: entrypoints)
|
58
61
|
end
|
59
62
|
|
60
63
|
def generated?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti_graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphiti
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.2
|
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:
|
26
|
+
version: 1.3.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|