graphiti_graphql 0.1.9 → 0.1.14
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/Gemfile.lock +25 -25
- data/lib/graphiti_graphql/federation/resource_dsl.rb +33 -10
- data/lib/graphiti_graphql/schema.rb +16 -9
- data/lib/graphiti_graphql/version.rb +1 -1
- data/lib/graphiti_graphql.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e99c86540776f6e5aa93eaa422f4919cf4434f6116bb040267bd37f3a0036ba8
|
4
|
+
data.tar.gz: bfac34b9d8b0f5e5e96e9169d969b5a3efbe6d01d0c3da964d27649a6b7514be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c8d515d95e749457c887dadfaaedab1e8d9367d57565364a7a5ef969843ad13486f530a4e61623003198c7d099aa571cba2e4269b9e29a4f7941a7b700631ae
|
7
|
+
data.tar.gz: edfe5d07374179c3cceb6dc1fbfd05a6de8cc124759e65b659204f03eb5e0ee1c4980d0515f9b9cccb1ec6095706d7373283435804f5f618e94fb29e045d4b88
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
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
6
|
graphiti (~> 1.3)
|
7
7
|
graphql (~> 1.12)
|
@@ -9,9 +9,9 @@ PATH
|
|
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
|
@@ -7,10 +7,18 @@ module GraphitiGraphQL
|
|
7
7
|
@type_name = type_name
|
8
8
|
end
|
9
9
|
|
10
|
-
def has_many(
|
10
|
+
def has_many(
|
11
|
+
relationship_name,
|
12
|
+
foreign_key: nil,
|
13
|
+
field: true,
|
14
|
+
filter: true,
|
15
|
+
&blk
|
16
|
+
)
|
11
17
|
@caller.federated_has_many relationship_name,
|
12
18
|
type: @type_name,
|
13
19
|
foreign_key: foreign_key,
|
20
|
+
field: field,
|
21
|
+
filter: filter,
|
14
22
|
&blk
|
15
23
|
end
|
16
24
|
end
|
@@ -29,14 +37,18 @@ module GraphitiGraphQL
|
|
29
37
|
config[:federated_resources] ||= []
|
30
38
|
end
|
31
39
|
|
40
|
+
# NB - for external use, use federated_type("Type").has_many instead
|
41
|
+
#
|
32
42
|
# * Add to the list of external graphql-ruby types we need in schema
|
33
43
|
# * Add a readable and filterable FK, without clobbering pre-existing
|
34
|
-
def federated_has_many(name, type:, foreign_key: nil, &blk)
|
44
|
+
def federated_has_many(name, type:, filter: true, field: true, foreign_key: nil, &blk)
|
35
45
|
foreign_key ||= :"#{type.underscore}_id"
|
36
46
|
resource = FederatedResource.new(type)
|
37
47
|
federated_resources << resource
|
38
48
|
resource.add_relationship(:has_many, name, self, foreign_key, &blk)
|
39
49
|
|
50
|
+
return unless (filter || field)
|
51
|
+
|
40
52
|
attribute = attributes.find { |name, config|
|
41
53
|
name.to_sym == foreign_key &&
|
42
54
|
!!config[:readable] &&
|
@@ -44,20 +56,31 @@ module GraphitiGraphQL
|
|
44
56
|
}
|
45
57
|
has_filter = filters.key?(foreign_key)
|
46
58
|
if !attribute && !has_filter
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
59
|
+
if field
|
60
|
+
opts = {
|
61
|
+
only: [:readable],
|
62
|
+
schema: false,
|
63
|
+
readable: :gql?
|
64
|
+
}
|
65
|
+
if filter
|
66
|
+
opts[:only] << :filterable
|
67
|
+
opts[:filterable] = :gql?
|
68
|
+
end
|
69
|
+
attribute foreign_key, :integer, opts
|
70
|
+
elsif filter
|
71
|
+
filter foreign_key, :integer, schema: false
|
72
|
+
attributes[foreign_key][:filterable] = :gql?
|
73
|
+
end
|
74
|
+
elsif has_filter && !attribute && field
|
53
75
|
prior = filters[foreign_key]
|
54
76
|
attribute foreign_key, prior[:type],
|
55
77
|
only: [:readable, :filterable],
|
56
78
|
schema: false,
|
57
79
|
readable: :gql?
|
58
80
|
filters[foreign_key] = prior
|
59
|
-
elsif attribute && !has_filter
|
60
|
-
filter foreign_key, attribute[:type]
|
81
|
+
elsif attribute && !has_filter && filter
|
82
|
+
filter foreign_key, attribute[:type], schema: false
|
83
|
+
attributes[foreign_key][:filterable] = :gql?
|
61
84
|
end
|
62
85
|
end
|
63
86
|
|
@@ -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)
|
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.14
|
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
|