graphiti_graphql 0.1.11 → 0.1.15

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
  SHA256:
3
- metadata.gz: 3572b13acb369033180b7ab0e4bba6f610d069302dfb3efab30fb4af890ad758
4
- data.tar.gz: 522d580599507c14ca4b477be3787905cf7574b7f9ca487418108ae0afc08cd5
3
+ metadata.gz: 06b6392e0c336de1983a2b40f69a748942e424b85adb20c4e64cbe581eb88ee0
4
+ data.tar.gz: f2d1aed4a0aba07bc3bf2279659011f0da8d33f509a325df5935c6e8500e384c
5
5
  SHA512:
6
- metadata.gz: 697d98b5580457160179f895ded0fd81738c7714773636a9850ecab3b131ca6bab9a4e916c131f7a29519631a7333640135870f2d95d4c14aa2916c67c00b68d
7
- data.tar.gz: 2cc559be1dc33bf52056d1be94e6a3a0cb88a4de240bcd19603dd1661e2f27c6504d1cc315c8ab5b888828868857fb05c9bb535353793ed810cbbd84924e2968
6
+ metadata.gz: befa7b4bdbf8389aeca15592942b72d4904f65e59bb00873e3a17a8d95eef3da70ce2001c80dd9c6863778edef485feeb9c62969047a8aea2972bf1f680cd550
7
+ data.tar.gz: 83d7689197e18b71c1b140ff1cf09b48fb7e6d950cc1b72187e33b38bba23e5d01ff5526c93cd19c9410ea7adf6bc5d19d3fba06aef1d2a993f47e1758de6bac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_graphql (0.1.10)
4
+ graphiti_graphql (0.1.15)
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,14 +23,14 @@ GEM
23
23
  ast (2.4.2)
24
24
  byebug (11.1.3)
25
25
  coderay (1.1.3)
26
- concurrent-ruby (1.1.8)
26
+ concurrent-ruby (1.1.10)
27
27
  diff-lcs (1.4.4)
28
- dry-configurable (0.12.1)
28
+ dry-configurable (0.15.0)
29
29
  concurrent-ruby (~> 1.0)
30
- dry-core (~> 0.5, >= 0.5.0)
31
- dry-container (0.8.0)
30
+ dry-core (~> 0.6)
31
+ dry-container (0.9.0)
32
32
  concurrent-ruby (~> 1.0)
33
- dry-configurable (~> 0.1, >= 0.1.3)
33
+ dry-configurable (~> 0.13, >= 0.13.0)
34
34
  dry-core (0.7.1)
35
35
  concurrent-ruby (~> 1.0)
36
36
  dry-inflector (0.2.1)
@@ -43,9 +43,9 @@ 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.15.2)
47
- graphiti (1.3.0)
48
- activesupport (>= 4.1)
46
+ google-protobuf (3.17.3)
47
+ graphiti (1.3.6)
48
+ activesupport (>= 5.2)
49
49
  concurrent-ruby (~> 1.0)
50
50
  dry-types (>= 0.15.0, < 2.0)
51
51
  graphiti_errors (~> 1.1.0)
@@ -56,30 +56,30 @@ 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.3)
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.9)
63
+ i18n (1.10.0)
64
64
  concurrent-ruby (~> 1.0)
65
65
  jsonapi-renderer (0.2.2)
66
66
  jsonapi-serializable (0.3.1)
67
67
  jsonapi-renderer (~> 0.2.0)
68
68
  method_source (1.0.0)
69
- minitest (5.14.4)
69
+ minitest (5.15.0)
70
70
  parallel (1.20.1)
71
- parser (3.0.0.0)
71
+ parser (3.0.2.0)
72
72
  ast (~> 2.4.1)
73
73
  promise.rb (0.7.4)
74
- pry (0.13.1)
74
+ pry (0.14.1)
75
75
  coderay (~> 1.1)
76
76
  method_source (~> 1.0)
77
- pry-byebug (3.9.0)
77
+ pry-byebug (3.8.0)
78
78
  byebug (~> 11.0)
79
- pry (~> 0.13.0)
79
+ pry (~> 0.10)
80
80
  rainbow (3.0.0)
81
81
  rake (10.5.0)
82
- regexp_parser (2.0.3)
82
+ regexp_parser (2.1.1)
83
83
  rexml (3.2.5)
84
84
  rspec (3.10.0)
85
85
  rspec-core (~> 3.10.0)
@@ -94,30 +94,30 @@ 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.8.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.2.0, < 2.0)
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.4.1)
107
- parser (>= 2.7.1.5)
108
- rubocop-performance (1.9.2)
109
- rubocop (>= 0.90.0, < 2.0)
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 (0.12.0)
113
- rubocop (= 1.8.1)
114
- rubocop-performance (= 1.9.2)
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)
118
118
  concurrent-ruby (~> 1.0)
119
119
  unicode-display_width (2.0.0)
120
- zeitwerk (2.4.2)
120
+ zeitwerk (2.5.4)
121
121
 
122
122
  PLATFORMS
123
123
  ruby
@@ -137,4 +137,4 @@ DEPENDENCIES
137
137
  standardrb
138
138
 
139
139
  BUNDLED WITH
140
- 2.2.16
140
+ 2.2.25
data/README.md CHANGED
@@ -50,6 +50,8 @@ And then in `config/application.rb`:
50
50
  # require "sprockets/railtie"
51
51
  ```
52
52
 
53
+ Alternatively, follow [this comment](https://github.com/rmosolgo/graphiql-rails/issues/53#issuecomment-877819958).
54
+
53
55
  ## Usage
54
56
 
55
57
  #### Blending with graphql-ruby
@@ -21,7 +21,8 @@ module GraphitiGraphQL
21
21
  case Rails::VERSION::MAJOR
22
22
  when 4 then ActionDispatch::Reloader
23
23
  when 5 then ActiveSupport::Reloader
24
- when 6 then ::Rails.application.reloader
24
+ else
25
+ ::Rails.application.reloader
25
26
  end
26
27
  end
27
28
 
@@ -64,15 +65,16 @@ module GraphitiGraphQL
64
65
  end
65
66
 
66
67
  initializer "graphiti_graphql.define_controller" do
67
- app_controller = GraphitiGraphQL.config.federation_application_controller || ::ApplicationController
68
- # rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
69
- class GraphitiGraphQL::ExecutionController < app_controller
70
- register_exception Graphiti::Errors::UnreadableAttribute, message: true
71
- def execute
72
- params = request.params # avoid strong_parameters
73
- render json: Graphiti.gql(params[:query], params[:variables])
74
- end
68
+ require "#{Rails.root}/app/controllers/application_controller"
69
+ app_controller = GraphitiGraphQL.config.federation_application_controller || ::ApplicationController
70
+ # rubocop:disable Lint/ConstantDefinitionInBlock(Standard)
71
+ class GraphitiGraphQL::ExecutionController < app_controller
72
+ register_exception Graphiti::Errors::UnreadableAttribute, message: true
73
+ def execute
74
+ params = request.params # avoid strong_parameters
75
+ render json: Graphiti.gql(params[:query], params[:variables])
75
76
  end
77
+ end
76
78
  end
77
79
 
78
80
  initializer "graphiti_graphql.federation" do
@@ -7,10 +7,18 @@ 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(
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
- attribute foreign_key, :integer,
48
- only: [:readable, :filterable],
49
- schema: false,
50
- readable: :gql?,
51
- filterable: :gql?
52
- elsif has_filter && !attribute
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(entrypoint_resources = nil)
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(entrypoint_resources || entrypoints)
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(entries)
76
- query_type = generate_schema_query(entries)
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(entrypoint_resources = nil)
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
@@ -97,13 +101,11 @@ module GraphitiGraphQL
97
101
 
98
102
  # Ensure all types are generated, even if they aren't in a top-level Query
99
103
  # We might now want to expose the query, but do want to federate the Type
100
- graphiti_schema.resources.each do |resource|
101
- next if resource.remote?
104
+ get_schema_resources(resources).each do |resource|
102
105
  generate_type(resource)
103
106
  end
104
107
 
105
- get_entrypoints(entrypoint_resources).each do |resource|
106
- next if resource.remote?
108
+ get_schema_resources(entrypoints).each do |resource|
107
109
  add_index(query_class, resource)
108
110
  add_show(query_class, resource)
109
111
  end
@@ -203,14 +205,14 @@ module GraphitiGraphQL
203
205
  top_level_single: true
204
206
  end
205
207
 
206
- def get_entrypoints(manually_specified)
208
+ def get_schema_resources(manually_specified)
207
209
  resources = graphiti_schema.resources
208
210
  if manually_specified
209
211
  resources = resources.select { |r|
210
212
  manually_specified.map(&:name).include?(r.name)
211
213
  }
212
214
  end
213
- resources
215
+ resources.reject(&:remote?)
214
216
  end
215
217
 
216
218
  def generate_sort_att_type_for(resource)
@@ -1,3 +1,3 @@
1
1
  module GraphitiGraphQL
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -53,8 +53,11 @@ module GraphitiGraphQL
53
53
  @generated ||= GraphitiGraphQL::Schema.generate
54
54
  end
55
55
 
56
- def generate!(entrypoint_resources = nil)
57
- @generated = GraphitiGraphQL::Schema.generate(entrypoint_resources)
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.11
4
+ version: 0.1.15
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-16 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphiti
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  - !ruby/object:Gem::Version
275
275
  version: '0'
276
276
  requirements: []
277
- rubygems_version: 3.2.22
277
+ rubygems_version: 3.3.7
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: GraphQL support for Graphiti