graphiti_gql 0.2.18 → 0.2.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90e832970f0f3329260d83e026c58493b76711ed1fbb7eee3914978014cd4684
4
- data.tar.gz: 993170a348f371cebc8bb101c21b48ca26f6df2ef82c9422061081a6da878880
3
+ metadata.gz: 8ff3654600729760d759d234decc94aeb9fd1927b27017bf14de01c70080ec34
4
+ data.tar.gz: 9e9cc547ace2c05ffbd9952cbe8db82ae9ef499ecc5123deaf72f2087cd6147b
5
5
  SHA512:
6
- metadata.gz: a84908687fd25d4324b6e9d1bc9bc9ef83a3388ca49ad33c829c71828e98992b3fd04476df6d1927ea3d6f17c87b5de89bbb6aa24f60d351f101c7f69b12ec53
7
- data.tar.gz: ad12bf08064111c18ee81b2b4006195c38311846f81310bb158126b0b89c257dabce3b60c32fe7114bace33dca19475e2af0b9d9d5976749cd1eafdcf2bf3e37
6
+ metadata.gz: 496ee06e3e0ba183c867367a759ce0114764c183f0af8df346d18bf8c28bb1c034ba9aa7dcf43d8e04bb11106b05143fdc2d6fd0ca220089489e276d59079a84
7
+ data.tar.gz: a2b5b3a60d06253dcb0aad59fe7f5358c700e360ecd24c421fed659ac2dccce45f3492797d42c74c72e743c7488a7f02417daf8f0352372f87b9faa49af21f96
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)
@@ -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.18"
2
+ VERSION = "0.2.19"
3
3
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti_gql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2022-08-01 00:00:00.000000000 Z
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '7.0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - richmolj@gmail.com
114
114
  executables: []
@@ -171,7 +171,7 @@ licenses:
171
171
  - MIT
172
172
  metadata:
173
173
  homepage_uri: https://www.graphiti.dev
174
- post_install_message:
174
+ post_install_message:
175
175
  rdoc_options: []
176
176
  require_paths:
177
177
  - lib
@@ -186,8 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.0.3.1
190
- signing_key:
189
+ rubygems_version: 3.3.7
190
+ signing_key:
191
191
  specification_version: 4
192
192
  summary: GraphQL support for Graphiti
193
193
  test_files: []