recline 0.0.1 → 0.1.1

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
  SHA1:
3
- metadata.gz: c8a9590957c1a76c1a8fbd07e33e989e6d62657e
4
- data.tar.gz: 71614ece35e0bd3213b25886fb3f2e8e20c01d67
3
+ metadata.gz: 9861c39716e17c3dd5f127d7c2f4164a08f144d6
4
+ data.tar.gz: 5f6757a33cdc34d55b3e59ccbf90f78d6e514ad8
5
5
  SHA512:
6
- metadata.gz: 9dee9e3d0f625fd9eb532419b52618ff2793d3a2eef07e1b118042f65531054d62f01ac6fa5cdac5fdf8c168f0ef91fffbef680c8242021f1c13fe41c4ddceee
7
- data.tar.gz: bfe5da5e83c87a81534158ddac727b4523ab85238509055e2236e3d69829fce00fc154d92e61ccc3362c25e69e60437c6ae58b9dc9b43f4c1acf478801f1e807
6
+ metadata.gz: 29c59aa2cc8b37c549d4b75d2a34fe4ebcc9918e69ca6bf66480dad2cf1eae401a2d1d76595fcd1bb34ea1de93763cd509b5a323537ca5c0d9614adb805bd4fb
7
+ data.tar.gz: 6345aeaca86130e6d9822e63309a1d04e98248913810d73d13aec23fee3792f26e05a106aa49f137cd5f65a5812f24a638e5921e5439f88f3768c099f31889f8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Recline for Rails
1
+ # Recline with Rails
2
2
  Seamless form management for React using GraphQL.
3
3
 
4
4
  **Work in progress.**
@@ -33,7 +33,7 @@ Recline.default_appearance_types = {
33
33
  ```
34
34
 
35
35
  Help me explain this better:
36
- [https://github.com/colepatrickturner/recline.rails/compare](Create a pull request)
36
+ [Create a Pull Request](https://github.com/colepatrickturner/recline.rails/compare)
37
37
 
38
38
  # Installation
39
39
  To begin, install the gem by adding it to the `Gemfile`:
@@ -45,7 +45,7 @@ To begin, install the gem by adding it to the `Gemfile`:
45
45
  Add the following line to an object type that you would like to expose:
46
46
 
47
47
  ```ruby
48
- implements GraphQL::Rails::ActiveReflection::Model.interface, inherit: true
48
+ implements Recline::Model.interface, inherit: true
49
49
  ```
50
50
 
51
51
  And that's it! This will add a `_model` field to your object type that will expose any field that can be mapped to an ActiveModel/ActiveRecord attribute.
@@ -22,7 +22,8 @@ module Recline
22
22
  :checkbox,
23
23
  :location,
24
24
  :media,
25
- :link
25
+ :link,
26
+ :reference
26
27
  ]
27
28
 
28
29
  def self.define_type(input)
@@ -1,10 +1,12 @@
1
+ require 'graphql/rails/active_reflection/attribute_reflection'
2
+
1
3
  class Recline::AttributeReflection < GraphQL::Rails::ActiveReflection::AttributeReflection
2
4
  @schema_name = "ReclineAttribute"
3
5
  attr_accessor :appearance
4
6
 
5
7
  def initialize(field, klass, schema)
6
8
  super
7
- @appearance = Recline.appearance_for(klass, @name)
9
+ @appearance = Recline.appearance_for(field, klass, @name)
8
10
  end
9
11
 
10
12
  def primary_key?
data/lib/recline/model.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'graphql/rails/active_reflection/model'
2
+
1
3
  module Recline
2
4
  class Model < GraphQL::Rails::ActiveReflection::Model
3
5
  def self.interface
@@ -1,3 +1,5 @@
1
+ require 'graphql/rails/active_reflection/model_reflection'
2
+
1
3
  class Recline::ModelReflection < GraphQL::Rails::ActiveReflection::ModelReflection
2
4
  @schema_name = "ReclineModel"
3
5
 
@@ -1,13 +1,14 @@
1
+ require 'graphql/rails/active_reflection'
1
2
  require 'graphql/rails/active_reflection/types/attribute_reflection_type'
2
3
  Recline::Types::AttributeReflectionType = GraphQL::Rails::ActiveReflection::Types::AttributeReflectionType.redefine do
3
4
  name "ReclineAttribute"
4
5
  field :appearance, Recline::Types::AppearanceEnumType
6
+ field :createdAt, types.String, property: :created_at
7
+ field :updatedAt, types.String, property: :updated_at
5
8
 
6
9
  field :read_only, types.Boolean do
7
10
  resolve ->(obj, _args, _ctx) do
8
- !obj.primary_key?
11
+ obj.primary_key?
9
12
  end
10
13
  end
11
14
  end
12
-
13
- puts "Recline::Types::AttributeReflectionType = #{Recline::Types::AttributeReflectionType}"
@@ -1,3 +1,3 @@
1
1
  module Recline
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/recline.rb CHANGED
@@ -1,15 +1,26 @@
1
1
  require 'graphql'
2
2
 
3
3
  module Recline
4
- def self.appearance_for(klass, name)
5
- if klass.respond_to? :recline_appearance
6
- klass.recline_appearance(@name)
4
+ module Types; end
5
+
6
+ def self.appearance_for(field, klass, name)
7
+ if field.metadata.key? :recline_appearance
8
+ return field.metadata[:recline_appearance]
7
9
  else
8
- db_type = klass.type_for_attribute(name.to_s).type
9
- if default_appearance_types.key? db_type
10
- default_appearance_types[db_type]
10
+ field_type = field.type
11
+ while field_type.kind.wraps?
12
+ field_type = field_type.of_type
13
+ end
14
+
15
+ if default_appearance_types.key? field_type
16
+ default_appearance_types[field_type]
11
17
  else
12
- fallback_appearance
18
+ db_type = klass.type_for_attribute(name.to_s).type
19
+ if default_appearance_types.key? db_type
20
+ default_appearance_types[db_type]
21
+ else
22
+ fallback_appearance
23
+ end
13
24
  end
14
25
  end
15
26
  end
@@ -24,12 +35,12 @@ module Recline
24
35
 
25
36
  def default_appearance_types
26
37
  @default_appearance_types ||= {
27
- string: :string,
38
+ GraphQL::ID_TYPE => :string,
39
+ GraphQL::STRING_TYPE => :string,
40
+ GraphQL::INT_TYPE => :number,
41
+ GraphQL::FLOAT_TYPE => :number,
42
+ GraphQL::BOOLEAN_TYPE => :toggle,
28
43
  text: :text,
29
- integer: :number,
30
- float: :number,
31
- decimal: :number,
32
- boolean: :toggle,
33
44
  date: :date,
34
45
  datetime: :datetime,
35
46
  timestamp: :datetime
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cole Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: graphql-rails-activereflection
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.2.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.2.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: activerecord
35
55
  requirement: !ruby/object:Gem::Requirement