graphql-client 0.12.3 → 0.13.0

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
- SHA1:
3
- metadata.gz: 532760d69d3380633bfa7e7555697aa843b72fa7
4
- data.tar.gz: 947e81aeea7eb9058c01b844425e4035a955a003
2
+ SHA256:
3
+ metadata.gz: eb27216cecd8b82430beda5f04f9eb8883be29ba245c0b7db606f835ede4a044
4
+ data.tar.gz: 782d1321f053407d369e1a119feebf9799612b4103395c2ff72a17bb7680a6c2
5
5
  SHA512:
6
- metadata.gz: 34f989f928690406e82004b449264785395ffc00c809e70784b53284889b8c4409f1bbc3226b1ae7ac62df69b1ca8d753871f44b2545746e2b775c0a0bc263e8
7
- data.tar.gz: 7f354451883ab22eefea03dea49cfe1bc848b8a6419ad9f626881a7dece1ec6922b3154a89561d5aa8ada72e9d919ecb24c529b4d13669c28ec63a7ab47d166e
6
+ metadata.gz: 251c12981e0af0c0b4c10261880b9c6f01aea92c2ccdd35a35cc484796354fbd8aeb365d077b93a41618269341e64bceb5a85985df3af623f12abeab6591db23
7
+ data.tar.gz: 023c4081d943267049fc6f7b0be964445fc5f7bb65460015ac3d849177b75a76a1158eae4a67810c9d9ca3a3c5ca61f6f8c689fbafdc3a1010c6d912d9675433
data/README.md CHANGED
@@ -8,14 +8,14 @@ GraphQL Client is a Ruby library for declaring, composing and executing GraphQL
8
8
 
9
9
  Sample configuration for a GraphQL Client to query from the [SWAPI GraphQL Wrapper](https://github.com/graphql/swapi-graphql).
10
10
 
11
- ``` ruby
11
+ ```ruby
12
12
  require "graphql/client"
13
13
  require "graphql/client/http"
14
14
 
15
15
  # Star Wars API example wrapper
16
16
  module SWAPI
17
17
  # Configure GraphQL endpoint using the basic HTTP network adapter.
18
- HTTP = GraphQL::Client::HTTP.new("http://graphql-swapi.parseapp.com/") do
18
+ HTTP = GraphQL::Client::HTTP.new("https://example.com/graphql") do
19
19
  def headers(context)
20
20
  # Optionally set any HTTP headers
21
21
  { "User-Agent": "My Client" }
@@ -42,7 +42,7 @@ If you haven't already, [familiarize yourself with the GraphQL query syntax](htt
42
42
 
43
43
  This client library encourages all GraphQL queries to be declared statically and assigned to a Ruby constant.
44
44
 
45
- ``` ruby
45
+ ```ruby
46
46
  HeroNameQuery = SWAPI::Client.parse <<-'GRAPHQL'
47
47
  query {
48
48
  hero {
@@ -51,6 +51,7 @@ HeroNameQuery = SWAPI::Client.parse <<-'GRAPHQL'
51
51
  }
52
52
  GRAPHQL
53
53
  ```
54
+
54
55
  Queries can reference variables that are passed in at query execution time.
55
56
 
56
57
  ```ruby
@@ -65,7 +66,7 @@ GRAPHQL
65
66
 
66
67
  Fragments are declared similarly.
67
68
 
68
- ``` ruby
69
+ ```ruby
69
70
  HumanFragment = SWAPI::Client.parse <<-'GRAPHQL'
70
71
  fragment on Human {
71
72
  name
@@ -76,7 +77,7 @@ GRAPHQL
76
77
 
77
78
  To include a fragment in a query, reference the fragment by constant.
78
79
 
79
- ``` ruby
80
+ ```ruby
80
81
  HeroNameQuery = SWAPI::Client.parse <<-'GRAPHQL'
81
82
  {
82
83
  luke: human(id: "1000") {
@@ -91,7 +92,7 @@ GRAPHQL
91
92
 
92
93
  This works for namespaced constants.
93
94
 
94
- ``` ruby
95
+ ```ruby
95
96
  module Hero
96
97
  Query = SWAPI::Client.parse <<-'GRAPHQL'
97
98
  {
@@ -112,7 +113,7 @@ end
112
113
 
113
114
  Pass the reference of a parsed query definition to `GraphQL::Client#query`. Data is returned back in a wrapped `GraphQL::Client::Schema::ObjectType` struct that provides Ruby-ish accessors.
114
115
 
115
- ``` ruby
116
+ ```ruby
116
117
  result = SWAPI::Client.query(Hero::Query)
117
118
 
118
119
  # The raw data is Hash of JSON values
@@ -121,18 +122,20 @@ result = SWAPI::Client.query(Hero::Query)
121
122
  # The wrapped result allows to you access data with Ruby methods
122
123
  result.data.luke.home_planet
123
124
  ```
124
- `GraphQL::Client#query` also accepts variables and context parameters that can be leveraged by the underlying network executor.
125
125
 
126
- ``` ruby
126
+ `GraphQL::Client#query` also accepts variables and context parameters that can be leveraged by the underlying network executor.
127
+
128
+ ```ruby
127
129
  result = SWAPI::Client.query(Hero::HeroFromEpisodeQuery, variables: {episode: "JEDI"}, context: {user_id: current_user_id})
128
130
  ```
131
+
129
132
  ### Rails ERB integration
130
133
 
131
134
  If you're using Ruby on Rails ERB templates, theres a ERB extension that allows static queries to be defined in the template itself.
132
135
 
133
136
  In standard Ruby you can simply assign queries and fragments to constants and they'll be available throughout the app. However, the contents of an ERB template is compiled into a Ruby method, and methods can't assign constants. So a new ERB tag was extended to declare static sections that include a GraphQL query.
134
137
 
135
- ``` erb
138
+ ```erb
136
139
  <%# app/views/humans/human.html.erb %>
137
140
  <%graphql
138
141
  fragment HumanFragment on Human {
@@ -161,7 +164,7 @@ These `<%graphql` sections are simply ignored at runtime but make their definiti
161
164
 
162
165
  Add `graphql-client` to your app's Gemfile:
163
166
 
164
- ``` ruby
167
+ ```ruby
165
168
  gem 'graphql-client'
166
169
  ```
167
170
 
@@ -198,6 +198,7 @@ module GraphQL
198
198
  client: self,
199
199
  irep_node: irep_node,
200
200
  document: sliced_document,
201
+ source_document: doc,
201
202
  source_location: source_location
202
203
  )
203
204
  definitions[node.name] = definition
@@ -25,9 +25,10 @@ module GraphQL
25
25
  end
26
26
  end
27
27
 
28
- def initialize(client:, document:, irep_node:, source_location:)
28
+ def initialize(client:, document:, source_document:, irep_node:, source_location:)
29
29
  @client = client
30
30
  @document = document
31
+ @source_document = source_document
31
32
  @definition_node = irep_node.ast_node
32
33
  @source_location = source_location
33
34
  @schema_class = client.types.define_class(self, irep_node, irep_node.return_type)
@@ -36,17 +37,23 @@ module GraphQL
36
37
  # Internal: Get associated owner GraphQL::Client instance.
37
38
  attr_reader :client
38
39
 
39
- # Internal root schema class for defintion. Returns
40
+ # Internal root schema class for definition. Returns
40
41
  # GraphQL::Client::Schema::ObjectType or
41
42
  # GraphQL::Client::Schema::PossibleTypes.
42
43
  attr_reader :schema_class
43
44
 
44
- # Internal: Get underlying operation or fragment defintion AST node for
45
+ # Internal: Get underlying operation or fragment definition AST node for
45
46
  # definition.
46
47
  #
47
48
  # Returns OperationDefinition or FragmentDefinition object.
48
49
  attr_reader :definition_node
49
50
 
51
+ # Internal: Get original document that created this definition, without
52
+ # any additional dependencies.
53
+ #
54
+ # Returns GraphQL::Language::Nodes::Document.
55
+ attr_reader :source_document
56
+
50
57
  # Public: Global name of definition in client document.
51
58
  #
52
59
  # Returns a GraphQL safe name of the Ruby constant String.
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require "action_view"
3
+
4
+ module GraphQL
5
+ class Client
6
+ begin
7
+ require "action_view/template/handlers/erb/erubi"
8
+ rescue LoadError
9
+ require "graphql/client/erubis_enhancer"
10
+
11
+ # Public: Extended Erubis implementation that supports GraphQL static
12
+ # query sections.
13
+ #
14
+ # <%graphql
15
+ # query GetVersion {
16
+ # version
17
+ # }
18
+ # %>
19
+ # <%= data.version %>
20
+ #
21
+ # Configure ActionView's default ERB implementation to use this class.
22
+ #
23
+ # ActionView::Template::Handlers::ERB.erb_implementation = GraphQL::Client::Erubis
24
+ #
25
+ class ERB < ActionView::Template::Handlers::Erubis
26
+ include ErubisEnhancer
27
+ end
28
+ else
29
+ require "graphql/client/erubi_enhancer"
30
+
31
+ # Public: Extended Erubis implementation that supports GraphQL static
32
+ # query sections.
33
+ #
34
+ # <%graphql
35
+ # query GetVerison {
36
+ # version
37
+ # }
38
+ # %>
39
+ # <%= data.version %>
40
+ #
41
+ # Configure ActionView's default ERB implementation to use this class.
42
+ #
43
+ # ActionView::Template::Handlers::ERB.erb_implementation = GraphQL::Client::Erubi
44
+ #
45
+ class ERB < ActionView::Template::Handlers::ERB::Erubi
46
+ include ErubiEnhancer
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,30 +1,8 @@
1
1
  # frozen_string_literal: true
2
- require "action_view"
3
- require "graphql/client/erubis_enhancer"
2
+ require "graphql/client/erb"
4
3
 
5
4
  module GraphQL
6
5
  class Client
7
- # Ignore deprecation errors loading AV Erubis
8
- ActiveSupport::Deprecation.silence do
9
- ActionView::Template::Handlers::Erubis
10
- end
11
-
12
- # Public: Extended Erubis implementation that supports GraphQL static
13
- # query sections.
14
- #
15
- # <%graphql
16
- # query GetVersion {
17
- # version
18
- # }
19
- # %>
20
- # <%= data.version %>
21
- #
22
- # Configure ActionView's default ERB implementation to use this class.
23
- #
24
- # ActionView::Template::Handlers::ERB.erb_implementation = GraphQL::Client::Erubis
25
- #
26
- class Erubis < ActionView::Template::Handlers::Erubis
27
- include ErubisEnhancer
28
- end
6
+ Erubis = GraphQL::Client::ERB
29
7
  end
30
8
  end
@@ -22,8 +22,8 @@ module GraphQL
22
22
  end
23
23
 
24
24
  initializer "graphql.configure_erb_implementation" do |_app|
25
- require "graphql/client/erubis"
26
- ActionView::Template::Handlers::ERB.erb_implementation = GraphQL::Client::Erubis
25
+ require "graphql/client/erb"
26
+ ActionView::Template::Handlers::ERB.erb_implementation = GraphQL::Client::ERB
27
27
  end
28
28
 
29
29
  initializer "graphql.configure_views_namespace" do |app|
@@ -22,7 +22,10 @@ module GraphQL
22
22
 
23
23
  def define_class(definition, irep_node)
24
24
  fields = irep_node.typed_children[type].inject({}) { |h, (field_name, field_irep_node)|
25
- if definition.indexes[:definitions][field_irep_node.ast_node] == definition.definition_node
25
+ definition_for_field = definition.indexes[:definitions][field_irep_node.ast_node]
26
+
27
+ # Ignore fields defined in other documents.
28
+ if definition.source_document.definitions.include?(definition_for_field)
26
29
  h[field_name.to_sym] = schema_module.define_class(definition, field_irep_node, field_irep_node.definition.type)
27
30
  end
28
31
  h
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-05 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,28 +126,28 @@ dependencies:
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '0.6'
129
+ version: '0.10'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '0.6'
136
+ version: '0.10'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: rubocop
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '0.49'
143
+ version: '0.55'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '0.49'
150
+ version: '0.55'
151
151
  description: A Ruby library for declaring, composing and executing GraphQL queries
152
152
  email: engineering@github.com
153
153
  executables: []
@@ -161,6 +161,7 @@ files:
161
161
  - lib/graphql/client/definition.rb
162
162
  - lib/graphql/client/definition_variables.rb
163
163
  - lib/graphql/client/document_types.rb
164
+ - lib/graphql/client/erb.rb
164
165
  - lib/graphql/client/error.rb
165
166
  - lib/graphql/client/errors.rb
166
167
  - lib/graphql/client/erubi_enhancer.rb
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
212
  version: '0'
212
213
  requirements: []
213
214
  rubyforge_project:
214
- rubygems_version: 2.6.11
215
+ rubygems_version: 2.7.6
215
216
  signing_key:
216
217
  specification_version: 4
217
218
  summary: GraphQL Client