graphql-activerecord 0.12.3 → 0.12.4
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/CHANGELOG.md +3 -0
- data/README.md +15 -0
- data/lib/graphql/activerecord.rb +1 -1
- data/lib/graphql/models/reflection.rb +15 -2
- data/lib/graphql/models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef54c410d9c6025638b8514775613c8e9b9f8209
|
4
|
+
data.tar.gz: 9e9cf95bd507c1a302896cdbfb7949dc962664c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0ed228fdd01523a7eff5eca8cea42523ab937d568d5d1b352eca8cf51064213414493dc254071370a83eb12da5d956fd57a1f9f661fa9bf88efa1886fb59de
|
7
|
+
data.tar.gz: c8d22b40c91596a0b87bebbeafec19245b4ad3d340a9b555cb0311394cd923bab2448461f938f041608a9d0c97498ddd028dca4bb53f8f6f4f39a4edd9fd607f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 0.12.4
|
4
|
+
Added the `GraphQL::Models.unknown_scalar` option (#45)
|
5
|
+
|
3
6
|
# 0.12.3
|
4
7
|
- If possible, try to get the description for a field from the column's comment in the database. (#40)
|
5
8
|
- Automatically generated union types (for polymorphic associations) used `demodulize` on the class name. If your model is `Name::Spaced`, this fixes a bug where it generates an invalid name. (#42)
|
data/README.md
CHANGED
@@ -198,6 +198,21 @@ GraphQL::Models::DatabaseTypes.register(:decimal, "DecimalType")
|
|
198
198
|
GraphQL::Models::DatabaseTypes.register(:date, DateType, DateInputType)
|
199
199
|
```
|
200
200
|
|
201
|
+
You can also provide a proc, if you want a catch-all, or if it's different for different models:
|
202
|
+
```ruby
|
203
|
+
GraphQL::Models.unknown_scalar = -> (type, klass, attribute) do
|
204
|
+
case type
|
205
|
+
when :uuid
|
206
|
+
UuidType
|
207
|
+
when :daterange
|
208
|
+
# If you need separate input/output types, use this syntax:
|
209
|
+
GraphQL::Models::DatabaseTypes::TypeStruct.new(DateRangeInputType, DateRangeOutputType)
|
210
|
+
else
|
211
|
+
GraphQL::STRING_TYPE
|
212
|
+
end
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
201
216
|
#### Nullability of attributes
|
202
217
|
The gem will mark a field as non-nullable if:
|
203
218
|
- the database column is non-null
|
data/lib/graphql/activerecord.rb
CHANGED
@@ -38,7 +38,7 @@ require 'graphql/models/mutator'
|
|
38
38
|
module GraphQL
|
39
39
|
module Models
|
40
40
|
class << self
|
41
|
-
attr_accessor :model_from_id, :authorize, :id_for_model, :model_to_graphql_type
|
41
|
+
attr_accessor :model_from_id, :authorize, :id_for_model, :model_to_graphql_type, :unknown_scalar
|
42
42
|
end
|
43
43
|
|
44
44
|
# Returns a promise that will traverse the associations and resolve to the model at the end of the path.
|
@@ -49,8 +49,21 @@ module GraphQL::Models
|
|
49
49
|
|
50
50
|
result = DatabaseTypes.registered_type(active_record_type.type)
|
51
51
|
|
52
|
-
if
|
53
|
-
|
52
|
+
if result.nil? && GraphQL::Models.unknown_scalar
|
53
|
+
type = GraphQL::Models.unknown_scalar.call(active_record_type.type, model_class, attribute)
|
54
|
+
|
55
|
+
if type.is_a?(GraphQL::BaseType) && (type.unwrap.is_a?(GraphQL::ScalarType) || type.unwrap.is_a?(GraphQL::EnumType))
|
56
|
+
result = DatabaseTypes::TypeStruct.new(type, type)
|
57
|
+
elsif type.is_a?(DatabaseTypes::TypeStruct)
|
58
|
+
result = type
|
59
|
+
else
|
60
|
+
raise "Got unexpected value #{type.inspect} from `unknown_scalar` proc. Expected a GraphQL::ScalarType, GraphQL::EnumType, or GraphQL::Models::DatabaseTypes::TypeStruct."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if result.nil?
|
65
|
+
# rubocop:disable Metrics/LineLength
|
66
|
+
raise "Don't know how to map database type #{active_record_type.type.inspect} to a GraphQL type. Forget to register it with GraphQL::Models::DatabaseTypes? (attribute #{attribute} on #{model_class.name})"
|
54
67
|
end
|
55
68
|
|
56
69
|
# Arrays: Rails doesn't have a generalized way to detect arrays, so we use this method to do it:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Foster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|