graphql-client 0.0.20 → 0.0.21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeedc712dec17a0235ba00379f0a47b115d7b813
4
- data.tar.gz: e143f70cb64be0f0fbddeb63d491db75293ef7e0
3
+ metadata.gz: ef076f9ef38c77eab90a79b2c0e26433fc213966
4
+ data.tar.gz: 967304326cf13c1419cf7d58544f176d22e062c7
5
5
  SHA512:
6
- metadata.gz: f23928689fa9b1adde4574ef9ac26a60aa2919ca8122593f0425a27f9d6808883d18d8cc4cfc270c40921c88863d43fa5ce87a0565d2dfcda7df3a6c4c7d69f9
7
- data.tar.gz: 5b5bdfcaf4b76a610448cdd80d1b3e391b97ee71f0f589bcc529fb6bda8df9f658e948f4eb122d7699f90755c4c9da155394d21275b6101bfbae23cb2faa845a
6
+ metadata.gz: 4631d663bdd60ccb619f171d3690e1289b1989251e7834932f8ac9ab426719f2bb8a710ba5766b0a307c56ebf8d6c9861e46861789f5fa160c6f9c8136fb1def
7
+ data.tar.gz: 2549a05547302f9da144400ac806a3d6e076cc4bfe3d282db70c56db3d01b9f3ebbf9805b732e69ab68d7a778c2564750fef283d97e33d4c10839bc7674b05b0
@@ -0,0 +1,41 @@
1
+ # graphql-client
2
+
3
+ ## Usage
4
+
5
+ To work with the client, you'll need to pass two variables to the initializer:
6
+
7
+ * You'll need to have access to a GraphQL schema. This can either be a JSON blob or simply a JSON file. Usually, you can generate this by executing an introspection query to a GraphQL server.
8
+ * You can optionally define a method that executes your schema. Usually, this is going to be some kind of HTTP adapter.
9
+
10
+ Once you've got that, you can set up the client like this:
11
+
12
+ ``` ruby
13
+ require "graphql/client"
14
+
15
+ module SWAPI
16
+ HTTP = GraphQL::Client::HTTP.new("http://graphql-swapi.parseapp.com/")
17
+
18
+ # Fetch latest schema on boot,
19
+ Schema = GraphQL::Client.load_schema(HTTP)
20
+ # However, its smart to dump this to a JSON file and load from disk
21
+ Schema = GraphQL::Client.load_schema("path/to/schema.json")
22
+
23
+ Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
24
+ end
25
+ ```
26
+
27
+ Then, all you'll need to do is pass your GraphQL query to `SWAPI::Client.query` to fetch the response.
28
+
29
+ You can also call `SWAPI::Client.parse` on a query to generate a validation against the GraphQL query.
30
+
31
+ ## Installation
32
+
33
+ Add `graphql-client` to your app's Gemfile:
34
+
35
+ ``` ruby
36
+ gem 'graphql-client'
37
+ ```
38
+
39
+ ## See Also
40
+
41
+ * [graphql-ruby](https://github.com/rmosolgo/graphql-ruby) gem which supports 90% of the features this library provides. ❤️ @rmosolgo
@@ -21,6 +21,8 @@ module GraphQL
21
21
 
22
22
  attr_accessor :document_tracking_enabled
23
23
 
24
+ IntrospectionDocument = GraphQL.parse(GraphQL::Introspection::INTROSPECTION_QUERY).deep_freeze
25
+
24
26
  def self.load_schema(schema)
25
27
  case schema
26
28
  when GraphQL::Schema
@@ -33,6 +35,17 @@ module GraphQL
33
35
  else
34
36
  load_schema(JSON.parse(schema))
35
37
  end
38
+ else
39
+ if schema.respond_to?(:execute)
40
+ load_schema(
41
+ schema.execute(
42
+ document: IntrospectionDocument,
43
+ operation_name: "IntrospectionQuery",
44
+ variables: {},
45
+ context: {}
46
+ )
47
+ )
48
+ end
36
49
  end
37
50
  end
38
51
 
@@ -236,17 +249,6 @@ module GraphQL
236
249
  Response.for(definition, result)
237
250
  end
238
251
 
239
- IntrospectionDocument = GraphQL.parse(GraphQL::Introspection::INTROSPECTION_QUERY).deep_freeze
240
-
241
- def fetch_schema
242
- execute.execute(
243
- document: IntrospectionDocument,
244
- operation_name: "IntrospectionQuery",
245
- variables: {},
246
- context: {}
247
- )
248
- end
249
-
250
252
  # Internal: FragmentSpread and FragmentDefinition extension to allow its
251
253
  # name to point to a lazily defined Proc instead of a static string.
252
254
  module LazyName
@@ -71,7 +71,12 @@ module GraphQL
71
71
  request.body = JSON.generate(body)
72
72
 
73
73
  response = http.request(request)
74
- JSON.parse(response.body)
74
+ case response
75
+ when Net::HTTPOK, Net::HTTPBadRequest
76
+ JSON.parse(response.body)
77
+ else
78
+ { "errors" => [{ "message" => "#{response.code} #{response.message}" }] }
79
+ end
75
80
  end
76
81
  end
77
82
  end
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.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-11 00:00:00.000000000 Z
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -113,6 +113,7 @@ extensions: []
113
113
  extra_rdoc_files: []
114
114
  files:
115
115
  - LICENSE
116
+ - README.md
116
117
  - lib/graphql/client.rb
117
118
  - lib/graphql/client/error.rb
118
119
  - lib/graphql/client/erubis.rb
@@ -144,8 +145,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  version: '0'
145
146
  requirements: []
146
147
  rubyforge_project:
147
- rubygems_version: 2.4.5.1
148
+ rubygems_version: 2.5.1
148
149
  signing_key:
149
150
  specification_version: 4
150
151
  summary: GraphQL Client
151
152
  test_files: []
153
+ has_rdoc: