graphiti_gql 0.2.17 → 0.2.20

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: 18a776555ead439b1ddfb5ff28835e1da6c5673b93287379d3cd8de4d366d5b7
4
- data.tar.gz: 919983d1eb5ad3653b4a95d22d9ed0f1d46d159fce21b2095746118e7e3bd175
3
+ metadata.gz: 17c54a15f86e3855f814dcea6a7093ceb0b0252de6685c57017a19f3c83160db
4
+ data.tar.gz: e0f018dbe747eaa43401f3f02ef77a526e3f5f2a0dad8964dd138bc083a38ad6
5
5
  SHA512:
6
- metadata.gz: e70f2ee088082aae875d1f98117e65f9a2daf1c08a752ea79142b3ca371c30c64333b75d4e54d890356a62cc11dcef8a6c7d214936b9ffa94241c893ec672cfb
7
- data.tar.gz: 29c371f94406f5b37beb82e6e440f5f52b3bca2345f2cc7b719ecea5f67ce28333a25820c6fd46f87ca540a218e18a6bd24e67e862f1fd6db66ab53203b1241b
6
+ metadata.gz: b863f5de471a4991d28f35c544567cf7420b78852c202c527b79399deb7e67f7c03e4f539cd628e9827354670e259ba44a8762191aaa88a97e3c474d753ff0de
7
+ data.tar.gz: e857d78632c3055263d4ae6287ab30836752c28cdd41836f411a82f4b64119b1420a79447c5a042c2829d24b57eec040d14a1eb9d2705aacc70935612ce5d5f8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_gql (0.2.15)
4
+ graphiti_gql (0.2.18)
5
5
  graphiti (~> 1.3.9)
6
6
  graphql (~> 2.0)
7
7
  graphql-batch (~> 0.5)
@@ -201,9 +201,11 @@ module GraphitiGql
201
201
  if sideload_fields.blank?
202
202
  sideload_fields = @resource.sideload(inc.to_sym).resource.attributes.select { |_, config| config[:readable] }.map(&:first)
203
203
  end
204
+ sideload_fields = sideload_fields.map { |sf| sf.to_s.camelize(:lower) }
205
+ sideload_fields |= [:__typename]
204
206
  sideload_fields.each do |name|
205
207
  q << %|
206
- #{indent}#{name.to_s.camelize(:lower)}|
208
+ #{indent}#{name}|
207
209
  end
208
210
 
209
211
  if to_one
@@ -3,7 +3,8 @@ module GraphitiGql
3
3
  module Fields
4
4
  class Attribute
5
5
  # If sideload is present, we're applying m2m metadata to an edge
6
- def initialize(name, config, sideload = nil)
6
+ def initialize(resource, name, config, sideload = nil)
7
+ @resource = resource
7
8
  @config = config
8
9
  @name = name
9
10
  @alias = config[:alias]
@@ -57,14 +58,34 @@ module GraphitiGql
57
58
  private
58
59
 
59
60
  def field_type
60
- field_type = Graphiti::Types[@config[:type]][:graphql_type]
61
- if !field_type
62
- canonical_graphiti_type = Graphiti::Types.name_for(@config[:type])
63
- field_type = GQL_TYPE_MAP[canonical_graphiti_type.to_sym]
64
- field_type = String if @name == :id
61
+ if [:integer_enum, :string_enum].any? { |t| @config[:type] == t }
62
+ return find_or_create_enum_type
63
+ else
64
+ field_type = Graphiti::Types[@config[:type]][:graphql_type]
65
+ if !field_type
66
+ canonical_graphiti_type = Graphiti::Types.name_for(@config[:type])
67
+ field_type = GQL_TYPE_MAP[canonical_graphiti_type.to_sym]
68
+ field_type = String if @name == :id
69
+ end
70
+ field_type = [field_type] if @config[:type].to_s.starts_with?("array_of")
71
+ field_type
72
+ end
73
+ end
74
+
75
+ def find_or_create_enum_type
76
+ resource_type_name = Schema.registry.key_for(@resource, interface: false)
77
+ enum_type_name = "#{resource_type_name}_#{@name}"
78
+ if (registered = Schema.registry[enum_type_name])
79
+ registered[:type]
80
+ else
81
+ klass = Class.new(GraphQL::Schema::Enum)
82
+ klass.graphql_name(enum_type_name)
83
+ @config[:allow].each do |allowed|
84
+ klass.value(allowed)
85
+ end
86
+ Schema.registry[enum_type_name] = { type: klass }
87
+ klass
65
88
  end
66
- field_type = [field_type] if @config[:type].to_s.starts_with?("array_of")
67
- field_type
68
89
  end
69
90
  end
70
91
  end
@@ -64,7 +64,7 @@ module GraphitiGql
64
64
  edge_resource = @sideload.class.edge_resource
65
65
  edge_resource.attributes.each_pair do |name, config|
66
66
  next if name == :id
67
- Schema::Fields::Attribute.new(name, config, @sideload).apply(edge_type_class)
67
+ Schema::Fields::Attribute.new(edge_resource, name, config, @sideload).apply(edge_type_class)
68
68
  end
69
69
  registered_parent = Schema.registry.get(@sideload.parent_resource.class)
70
70
  parent_name = registered_parent[:type].graphql_name
@@ -90,7 +90,7 @@ module GraphitiGql
90
90
  def add_fields(type, resource)
91
91
  resource.attributes.each_pair do |name, config|
92
92
  if config[:readable]
93
- Fields::Attribute.new(name, config).apply(type)
93
+ Fields::Attribute.new(@resource, name, config).apply(type)
94
94
  end
95
95
  end
96
96
  end
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.17"
2
+ VERSION = "0.2.20"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-28 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -124,7 +124,6 @@ files:
124
124
  - LICENSE.txt
125
125
  - README.md
126
126
  - Rakefile
127
- - app/controllers/graphiti_gql/execution_controller.rb
128
127
  - bin/bundle
129
128
  - bin/byebug
130
129
  - bin/coderay
@@ -136,7 +135,6 @@ files:
136
135
  - bin/rake
137
136
  - bin/rspec
138
137
  - bin/setup
139
- - config/routes.rb
140
138
  - graphiti_gql.gemspec
141
139
  - lib/graphiti_gql.rb
142
140
  - lib/graphiti_gql/active_resource.rb
@@ -1,18 +0,0 @@
1
- module GraphitiGql
2
- class ExecutionController < GraphitiGql.config.application_controller
3
- def execute
4
- params = request.params # avoid strong_parameters
5
- variables = params[:variables] || {}
6
- result = GraphitiGql.run params[:query],
7
- params[:variables],
8
- graphql_context
9
- render json: result
10
- end
11
-
12
- private
13
-
14
- def default_context
15
- defined?(:current_user)
16
- end
17
- end
18
- end
data/config/routes.rb DELETED
@@ -1,6 +0,0 @@
1
- GraphitiGql::Engine.routes.draw do
2
- # Default json so our error handler takes effect
3
- scope defaults: {format: :json} do
4
- post "/" => "execution#execute"
5
- end
6
- end