graphql-relay 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/graphql/relay/mutation.rb +1 -1
- data/lib/graphql/relay/relation_connection.rb +11 -6
- data/lib/graphql/relay/version.rb +1 -1
- data/spec/graphql/relay/mutation_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/star_wars_data.rb +1 -1
- data/spec/support/star_wars_schema.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6284053a13755747eea7b324a8c95c6acac7a2ce
|
4
|
+
data.tar.gz: 12fd8d7abd63b48100a90212fc2386762129fdd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df6bf1e5c4f2ac0d10e8f1328159fab1c802e969c26c3c274c3e1075b525aca788b21f24cb8cd1a0ae636838143d00d9c4e83441b94735431ae08c00c288165
|
7
|
+
data.tar.gz: 4a9e932f728d71c8763c072b4d6e419b1d37d5da5607fe68deb7bf87a4c1850ae19ba1328d2a0483accedfcea35ab4e4820d8d76202891363e85ed46cbae3121
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# graphql-relay
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/graphql-relay.svg)](http://badge.fury.io/rb/graphql-relay)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/rmosolgo/graphql-relay-ruby/badges/gpa.svg)](https://codeclimate.com/github/rmosolgo/graphql-relay-ruby)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/rmosolgo/graphql-relay-ruby/badges/coverage.svg)](https://codeclimate.com/github/rmosolgo/graphql-relay-ruby/coverage)
|
6
|
+
|
3
7
|
Helpers for using [`graphql`](https://github.com/rmosolgo/graphql-ruby) with Relay.
|
4
8
|
|
5
9
|
## Installation
|
@@ -35,16 +35,16 @@ module GraphQL
|
|
35
35
|
|
36
36
|
if after
|
37
37
|
_o, order_value = slice_from_cursor(after)
|
38
|
-
|
39
|
-
|
40
|
-
items = items.where(
|
38
|
+
direction_marker = order_direction == :asc ? ">" : "<"
|
39
|
+
where_condition = create_order_condition(order_name, order_value, direction_marker)
|
40
|
+
items = items.where(where_condition)
|
41
41
|
end
|
42
42
|
|
43
43
|
if before
|
44
44
|
_o, order_value = slice_from_cursor(before)
|
45
|
-
|
46
|
-
|
47
|
-
items = items.where(
|
45
|
+
direction_marker = order_direction == :asc ? "<" : ">"
|
46
|
+
where_condition = create_order_condition(order_name, order_value, direction_marker)
|
47
|
+
items = items.where(where_condition)
|
48
48
|
end
|
49
49
|
|
50
50
|
items
|
@@ -65,6 +65,11 @@ module GraphQL
|
|
65
65
|
def order_direction
|
66
66
|
@order_direction ||= order.start_with?("-") ? :desc : :asc
|
67
67
|
end
|
68
|
+
|
69
|
+
def create_order_condition(column, value, direction_marker)
|
70
|
+
name = ActiveRecord::Base.connection.quote_column_name(column)
|
71
|
+
["#{name} #{direction_marker} ?", value]
|
72
|
+
end
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
@@ -30,5 +30,9 @@ describe GraphQL::Relay::Mutation do
|
|
30
30
|
"faction" => {"name" => STAR_WARS_DATA["Faction"]["1"].name }
|
31
31
|
}
|
32
32
|
}}
|
33
|
+
assert_equal(expected, result)
|
34
|
+
# Cleanup:
|
35
|
+
STAR_WARS_DATA["Ship"].delete("9")
|
36
|
+
STAR_WARS_DATA["Faction"]["1"]["ships"].delete("9")
|
33
37
|
end
|
34
38
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,5 +17,5 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
17
17
|
|
18
18
|
|
19
19
|
def query(string, variables={})
|
20
|
-
GraphQL::Query.new(StarWarsSchema, string, variables: variables).result
|
20
|
+
GraphQL::Query.new(StarWarsSchema, string, variables: variables, debug: true).result
|
21
21
|
end
|
@@ -26,7 +26,7 @@ empire = OpenStruct.new({
|
|
26
26
|
})
|
27
27
|
|
28
28
|
## Set up "Bases" in ActiveRecord
|
29
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
29
|
+
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
30
30
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
31
31
|
|
32
32
|
ActiveRecord::Schema.define do
|
@@ -35,7 +35,7 @@ BaseType = GraphQL::ObjectType.define do
|
|
35
35
|
field :planet, types.String
|
36
36
|
end
|
37
37
|
|
38
|
-
# Define a connection which will wrap an
|
38
|
+
# Define a connection which will wrap an ActiveRecord::Relation:
|
39
39
|
BaseConnection = GraphQL::Relay::RelationConnection.create_type(BaseType)
|
40
40
|
|
41
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-relay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
@@ -178,7 +178,8 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
-
description:
|
181
|
+
description: Define global ids, connections and mutations to use GraphQL and Relay
|
182
|
+
with a Ruby server.
|
182
183
|
email:
|
183
184
|
- rdmosolgo@gmail.com
|
184
185
|
executables: []
|