graphql-remote_loader 1.0.4 → 1.0.5

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: b71151aac9fed6da47c53df2db83f4aa32178436
4
- data.tar.gz: f556f9d29f9080efa8b326a7a21c443c090f2605
3
+ metadata.gz: d72d37be4701ca0a4dd4bad71e989241b8557f01
4
+ data.tar.gz: 0e4c7d0613383cd441d2dc887cc7c5647296a780
5
5
  SHA512:
6
- metadata.gz: dbf5636dc0e6ab2976d763d4d66b30007b892acb608bc8846dc3731eebb87cd3932265843c2fad6470b0ba06ab9925fc42513b8f5a68ffb01b524693d41de320
7
- data.tar.gz: d322e05826e6b70013d6ea692d1c05d47f645bd55cbef6e829e7678deff6eed87dc494320cbab5694d7a702a754c43ab03a8f580e35b67ddb9019b47b10038e9
6
+ metadata.gz: 53941e0b529fcf5c9f89809de804faf1f52e162c3fa8cccbb2f2c6a0b1f44c8d713a4bf291055504ae75c2fa001f926aa6e15a5bed1acfa949e4ec2d2f3553b1
7
+ data.tar.gz: 017da570ea18310a6b3eb4801ffa24ff1e22d087cca6daf2b4d1370813c419443b809dfbdc6337b6f9c0690742b540bb2e0e89b1f3342cf32d12406684f9354e
@@ -1,2 +1,5 @@
1
1
  language: ruby
2
+ # Work around an issue where bundler isn't installed correctly on Ruby 2.5.
3
+ # We should remove this once Travis uses Ruby 2.6 by default.
4
+ rvm: 2.6
2
5
  script: bundle exec rspec
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-remote_loader (1.0.3)
5
- graphql (~> 1.6)
4
+ graphql-remote_loader (1.0.5)
5
+ graphql (~> 1.9)
6
6
  graphql-batch (~> 0.3)
7
7
 
8
8
  GEM
@@ -11,9 +11,9 @@ GEM
11
11
  byebug (10.0.2)
12
12
  coderay (1.1.2)
13
13
  diff-lcs (1.3)
14
- graphql (1.8.11)
15
- graphql-batch (0.3.10)
16
- graphql (>= 0.8, < 2)
14
+ graphql (1.9.12)
15
+ graphql-batch (0.4.1)
16
+ graphql (>= 1.3, < 2)
17
17
  promise.rb (~> 0.7.2)
18
18
  method_source (0.9.1)
19
19
  promise.rb (0.7.4)
@@ -42,11 +42,11 @@ PLATFORMS
42
42
  ruby
43
43
 
44
44
  DEPENDENCIES
45
- bundler (~> 1.14)
45
+ bundler (~> 2.0)
46
46
  graphql-remote_loader!
47
47
  pry-byebug (~> 3.4)
48
48
  rake (~> 10.0)
49
49
  rspec (~> 3.6)
50
50
 
51
51
  BUNDLED WITH
52
- 1.15.4
52
+ 2.0.2
data/README.md CHANGED
@@ -6,18 +6,6 @@ Performant, batched GraphQL queries from within the resolvers of a [`graphql-rub
6
6
 
7
7
  ## Snippet
8
8
 
9
- For default error handling(null if errors) and no post-processing:
10
-
11
- ```ruby
12
- field :login, String, null: true, description: "The currently authenticated GitHub user's login."
13
-
14
- def login
15
- GitHubLoader.load_value("viewer", "login")
16
- end
17
- ```
18
-
19
- If you need error handling, post-processing, or complex queries:
20
-
21
9
  ```ruby
22
10
  field :login, String, null: false, description: "The currently authenticated GitHub user's login."
23
11
 
@@ -32,12 +20,8 @@ def login
32
20
  end
33
21
  ```
34
22
 
35
- ## Full example
36
-
37
- To see a working example of how `graphql-remote_loader` works, see the [complete, working example application](https://github.com/d12/graphql-remote_loader_example).
38
-
39
23
  ## Description
40
- `graphql-remote_loader` allows for querying GraphQL APIs from within resolvers of a [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby) API.
24
+ `graphql-remote_loader` allows for querying GraphQL APIs from within resolvers of a [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby) API.
41
25
 
42
26
  This can be used to create GraphQL APIs that depend on data from other GraphQL APIs, either remote or local.
43
27
 
@@ -45,6 +29,10 @@ A promise-based resolution strategy from Shopify's [`graphql-batch`](https://git
45
29
 
46
30
  You can think of it as a lightweight version of schema-stitching.
47
31
 
32
+ ## Performance
33
+
34
+ Each `Loader#load` invocation does not send a GraphQL query to the remote. The Gem uses graphql-batch to collect all GraphQL queries together, then combines them and sends a single query to the upstream. The gem splits the response JSON up so that each promise is only resolved with data that it asked for.
35
+
48
36
  ## How to use
49
37
  First, you'll need to install the gem. Either do `gem install graphql-remote_loader` or add this to your Gemfile:
50
38
 
@@ -52,9 +40,9 @@ First, you'll need to install the gem. Either do `gem install graphql-remote_loa
52
40
  gem "graphql-remote_loader"
53
41
  ```
54
42
 
55
- The gem provides a base loader `GraphQL::RemoteLoader::Loader` which does most of the heavy lifting. In order to remain client-agnostic, there's an unimplemented no-op that queries the external GraphQL API.
43
+ The gem provides a base loader `GraphQL::RemoteLoader::Loader` which does most of the heavy lifting. In order to remain client-agnostic, there's an unimplemented no-op that takes a query string and queries the remote GraphQL API.
56
44
 
57
- To use, create a new class that inherits from `GraphQL::RemoteLoader::Loader` and define `def query(query_string)`. The method takes a query String as input. The expected output is a response `Hash`, or some object that responds to `#to_h`.
45
+ To use, create a new class that inherits from `GraphQL::RemoteLoader::Loader` and define `def query(query_string)`. The method takes a query String as input. The expected output is a response `Hash`, or an object that responds to `#to_h`.
58
46
 
59
47
  Example:
60
48
 
@@ -75,6 +63,10 @@ This example uses [`graphql-client`](https://github.com/github/graphql-client).
75
63
 
76
64
  With your loader setup, you can begin using `#load` or `#load_value` in your `graphql-ruby` resolvers.
77
65
 
66
+ ## Full example
67
+
68
+ To see a working example of how `graphql-remote_loader` works, see the [complete, working example application](https://github.com/d12/graphql-remote_loader_example).
69
+
78
70
  ## Running tests
79
71
 
80
72
  ```
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  # spec.executables = [""]
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "graphql", "~> 1.6"
24
+ spec.add_dependency "graphql", "~> 1.9"
25
25
  spec.add_dependency "graphql-batch", "~> 0.3"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.6"
30
30
  spec.add_development_dependency "pry-byebug", "~> 3.4"
@@ -45,7 +45,9 @@ module GraphQL
45
45
  if matching_fragment_definition
46
46
  merge_query_recursive(a_definition, matching_fragment_definition)
47
47
  else
48
- b_query.definitions << a_definition
48
+ # graphql-ruby Nodes aren't meant to be mutated, but I'd rather slightly abuse graphql-ruby vs
49
+ # maintain my own Ruby data and parsing library implementing the GraphQL spec.
50
+ b_query.instance_variable_set(:@definitions, [b_query.definitions, a_definition].flatten)
49
51
  end
50
52
  end
51
53
  end
@@ -79,7 +81,7 @@ module GraphQL
79
81
  matching_field.instance_variable_set(:@prime, new_prime)
80
82
  merge_query_recursive(a_query_selection, matching_field) unless exempt_node_types.any? { |type| matching_field.is_a?(type) }
81
83
  else
82
- b_query.selections << a_query_selection
84
+ b_query.instance_variable_set(:@selections, [b_query.selections, a_query_selection].flatten)
83
85
  end
84
86
  end
85
87
  end
@@ -112,11 +114,11 @@ module GraphQL
112
114
  unless exempt_node_types.any? { |type| selection.is_a? type }
113
115
  prime_factor = selection.instance_variable_get(:@prime)
114
116
 
115
- selection.alias = if selection.alias
117
+ selection.instance_variable_set(:@alias, if selection.alias
116
118
  "p#{prime_factor}#{selection.alias}"
117
119
  else
118
120
  "p#{prime_factor}#{selection.name}"
119
- end
121
+ end)
120
122
  end
121
123
 
122
124
  # Some nodes don't have selections (e.g. fragment spreads)
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module RemoteLoader
3
- VERSION = "1.0.4"
3
+ VERSION = "1.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-remote_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Woodthorpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-18 00:00:00.000000000 Z
11
+ date: 2019-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: graphql-batch
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.14'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.14'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.5.2
136
+ rubygems_version: 2.6.13
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Performant remote GraphQL queries from within a Ruby GraphQL API.