gqli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +31 -0
  5. data/.rubocop_todo.yml +44 -0
  6. data/.travis.yml +13 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +9 -0
  9. data/Gemfile +9 -0
  10. data/Gemfile.lock +154 -0
  11. data/Guardfile +24 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +284 -0
  14. data/Rakefile +33 -0
  15. data/coverage/.last_run.json +5 -0
  16. data/coverage/.resultset.json +512 -0
  17. data/coverage/.resultset.json.lock +0 -0
  18. data/coverage/assets/0.10.2/application.css +799 -0
  19. data/coverage/assets/0.10.2/application.js +1707 -0
  20. data/coverage/assets/0.10.2/colorbox/border.png +0 -0
  21. data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  22. data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  23. data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  24. data/coverage/assets/0.10.2/favicon_green.png +0 -0
  25. data/coverage/assets/0.10.2/favicon_red.png +0 -0
  26. data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  27. data/coverage/assets/0.10.2/loading.gif +0 -0
  28. data/coverage/assets/0.10.2/magnify.png +0 -0
  29. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  30. data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  31. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  32. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  33. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  34. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  35. data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  36. data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  37. data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  38. data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  39. data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  40. data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  41. data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  42. data/coverage/index.html +3255 -0
  43. data/doc/GQLi/Base.html +628 -0
  44. data/doc/GQLi/Client.html +830 -0
  45. data/doc/GQLi/DSL.html +421 -0
  46. data/doc/GQLi/Fragment.html +405 -0
  47. data/doc/GQLi/Introspection.html +837 -0
  48. data/doc/GQLi/Node.html +413 -0
  49. data/doc/GQLi/Query.html +390 -0
  50. data/doc/GQLi/Response.html +370 -0
  51. data/doc/GQLi.html +157 -0
  52. data/doc/_index.html +236 -0
  53. data/doc/class_list.html +51 -0
  54. data/doc/css/common.css +1 -0
  55. data/doc/css/full_list.css +58 -0
  56. data/doc/css/style.css +496 -0
  57. data/doc/file.CHANGELOG.html +76 -0
  58. data/doc/file.LICENSE.html +70 -0
  59. data/doc/file.README.html +365 -0
  60. data/doc/file_list.html +66 -0
  61. data/doc/frames.html +17 -0
  62. data/doc/index.html +365 -0
  63. data/doc/js/app.js +292 -0
  64. data/doc/js/full_list.js +216 -0
  65. data/doc/js/jquery.js +4 -0
  66. data/doc/method_list.html +355 -0
  67. data/doc/top-level-namespace.html +110 -0
  68. data/gqli.gemspec +37 -0
  69. data/lib/gqli/base.rb +53 -0
  70. data/lib/gqli/client.rb +59 -0
  71. data/lib/gqli/dsl.rb +37 -0
  72. data/lib/gqli/fragment.rb +25 -0
  73. data/lib/gqli/introspection.rb +215 -0
  74. data/lib/gqli/node.rb +48 -0
  75. data/lib/gqli/query.rb +29 -0
  76. data/lib/gqli/response.rb +15 -0
  77. data/lib/gqli/version.rb +7 -0
  78. data/lib/gqli.rb +6 -0
  79. data/spec/fixtures/vcr_cassettes/catCollection.yml +63 -0
  80. data/spec/fixtures/vcr_cassettes/client.yml +171 -0
  81. data/spec/fixtures/vcr_cassettes/validation_error.yml +62 -0
  82. data/spec/lib/gqli/client_spec.rb +90 -0
  83. data/spec/lib/gqli/dsl_spec.rb +205 -0
  84. data/spec/lib/gqli/introspection_spec.rb +125 -0
  85. data/spec/spec_helper.rb +25 -0
  86. data/usage.rb +100 -0
  87. data/usage_introspection.rb +63 -0
  88. data/usage_with_inlined_dsl.rb +69 -0
  89. metadata +387 -0
data/doc/index.html ADDED
@@ -0,0 +1,365 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; Documentation by YARD 0.9.16
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+ <span class="title">File: README</span>
41
+
42
+ </div>
43
+
44
+ <div id="search">
45
+
46
+ <a class="full_list_link" id="class_list_link"
47
+ href="class_list.html">
48
+
49
+ <svg width="24" height="24">
50
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
51
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
+ </svg>
54
+ </a>
55
+
56
+ </div>
57
+ <div class="clear"></div>
58
+ </div>
59
+
60
+ <div id="content"><div id='filecontents'>
61
+ <h1 id="label-GQLi+-+GraphQL+Client+for+humans">GQLi - GraphQL Client for humans</h1>
62
+
63
+ <p>GQLi is a DSL (Domain Specific Language) to consume GraphQL APIs.</p>
64
+
65
+ <h2 id="label-Installation">Installation</h2>
66
+
67
+ <p>Install it via the command line:</p>
68
+
69
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_gqli'>gqli</span>
70
+ </code></pre>
71
+
72
+ <p>Or add it to your <code>Gemfile</code>:</p>
73
+
74
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>gqli</span><span class='tstring_end'>&#39;</span></span>
75
+ </code></pre>
76
+
77
+ <h2 id="label-Usage">Usage</h2>
78
+
79
+ <h3 id="label-Creating+a+GraphQL+Client">Creating a GraphQL Client</h3>
80
+
81
+ <p>For the examples throught this README, we&#39;ll be using the Contentful
82
+ and Github GraphQL APIs. Therefore, here&#39;s the initialization code
83
+ required for both of them:</p>
84
+
85
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>gqli</span><span class='tstring_end'>&#39;</span></span>
86
+
87
+ <span class='comment'># Creating a Contentful GraphQL Client
88
+ </span><span class='const'>SPACE_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>&#39;</span></span>
89
+ <span class='const'>CF_ACCESS_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>&#39;</span></span>
90
+ <span class='const'>CONTENTFUL_GQL</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/Client.html" title="GQLi::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="GQLi/Client.html#initialize-instance_method" title="GQLi::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
91
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>https://graphql.contentful.com/content/v1/spaces/</span><span class='embexpr_beg'>#{</span><span class='const'>SPACE_ID</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
92
+ <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Authorization</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Bearer </span><span class='embexpr_beg'>#{</span><span class='const'>CF_ACCESS_TOKEN</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
93
+ <span class='rparen'>)</span>
94
+
95
+ <span class='comment'># Creating a Github GraphQL Client
96
+ </span><span class='const'>GITHUB_ACCESS_TOKEN</span> <span class='op'>=</span> <span class='const'>ENV</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>GITHUB_TOKEN</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
97
+ <span class='const'>GITHUB_GQL</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/Client.html" title="GQLi::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="GQLi/Client.html#initialize-instance_method" title="GQLi::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
98
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>https://api.github.com/graphql</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
99
+ <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Authorization</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Bearer </span><span class='embexpr_beg'>#{</span><span class='const'>GITHUB_ACCESS_TOKEN</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
100
+ <span class='rparen'>)</span>
101
+ </code></pre>
102
+
103
+ <h3 id="label-Creating+a+Query">Creating a Query</h3>
104
+
105
+ <p>Queries are the way we have to request data from a GraphQL API. This gem
106
+ provides a simple DSL to create your own queries.</p>
107
+
108
+ <p>The query operator is <code>GQLi::DSL.query</code>.</p>
109
+
110
+ <pre class="code ruby"><code class="ruby"><span class='comment'># Query to fetch the usernames for the first 10 watchers of the first 10 repositories I belong to
111
+ </span><span class='const'>WatchersQuery</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span><span class='period'>.</span><span class='id identifier rubyid_query'><span class='object_link'><a href="GQLi/DSL.html#query-class_method" title="GQLi::DSL.query (method)">query</a></span></span> <span class='lbrace'>{</span>
112
+ <span class='id identifier rubyid_viewer'>viewer</span> <span class='lbrace'>{</span>
113
+ <span class='id identifier rubyid_login'>login</span>
114
+ <span class='id identifier rubyid_repositories'>repositories</span><span class='lparen'>(</span><span class='label'>first:</span> <span class='int'>10</span><span class='rparen'>)</span> <span class='lbrace'>{</span>
115
+ <span class='id identifier rubyid_edges'>edges</span> <span class='lbrace'>{</span>
116
+ <span class='id identifier rubyid_node'>node</span> <span class='lbrace'>{</span>
117
+ <span class='id identifier rubyid_nameWithOwner'>nameWithOwner</span>
118
+ <span class='id identifier rubyid_watchers'>watchers</span><span class='lparen'>(</span><span class='label'>first:</span> <span class='int'>10</span><span class='rparen'>)</span> <span class='lbrace'>{</span>
119
+ <span class='id identifier rubyid_edges'>edges</span> <span class='lbrace'>{</span>
120
+ <span class='id identifier rubyid_node'>node</span> <span class='lbrace'>{</span>
121
+ <span class='id identifier rubyid_login'>login</span>
122
+ <span class='rbrace'>}</span>
123
+ <span class='rbrace'>}</span>
124
+ <span class='rbrace'>}</span>
125
+ <span class='rbrace'>}</span>
126
+ <span class='rbrace'>}</span>
127
+ <span class='rbrace'>}</span>
128
+ <span class='rbrace'>}</span>
129
+ <span class='rbrace'>}</span>
130
+ </code></pre>
131
+
132
+ <h3 id="label-Divide+and+conquer+-+using+Fragments">Divide and conquer - using Fragments</h3>
133
+
134
+ <p>Some times, we want to reuse parts of queries. For that, we can split
135
+ chunks of our queries into Fragments.</p>
136
+
137
+ <p>The fragment operator is <code>GQLi::DSL.fragment</code>.</p>
138
+
139
+ <p>To include fragments within other nodes, use the <code><em>_</em></code>
140
+ operator as shown below.</p>
141
+
142
+ <p>To do type matching, use the <code>__on</code> operator as shown below.</p>
143
+
144
+ <pre class="code ruby"><code class="ruby"><span class='comment'># Base fragment that will be reused for all Cat queries.
145
+ </span><span class='const'>CatBase</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fragment'><span class='object_link'><a href="GQLi/DSL.html#fragment-class_method" title="GQLi::DSL.fragment (method)">fragment</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatBase</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
146
+ <span class='id identifier rubyid_name'>name</span>
147
+ <span class='id identifier rubyid_likes'>likes</span>
148
+ <span class='id identifier rubyid_lives'>lives</span>
149
+ <span class='rbrace'>}</span>
150
+
151
+ <span class='const'>CatBestFriend</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fragment'><span class='object_link'><a href="GQLi/DSL.html#fragment-class_method" title="GQLi::DSL.fragment (method)">fragment</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatBestFriend</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
152
+ <span class='id identifier rubyid_bestFriend'>bestFriend</span> <span class='lbrace'>{</span>
153
+ <span class='comment'># Here, because `bestFriend` is polimorphic in our GraphQL API,
154
+ </span> <span class='comment'># we need to explicitly state for which Type we want to include our fragment.
155
+ </span> <span class='comment'># To do a type match, instead of GraphQLs `... on SomeType` we do `__on(&#39;SomeType&#39;)`.
156
+ </span> <span class='id identifier rubyid___on'>__on</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
157
+ <span class='comment'># To include a fragment, instead of GraphQLs `...`, we use `___`.
158
+ </span> <span class='id identifier rubyid____'>___</span> <span class='const'>CatBase</span>
159
+ <span class='rbrace'>}</span>
160
+ <span class='rbrace'>}</span>
161
+ <span class='rbrace'>}</span>
162
+
163
+ <span class='comment'># A fragment reusing multiple fragments
164
+ </span><span class='const'>CatImportantFields</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fragment'><span class='object_link'><a href="GQLi/DSL.html#fragment-class_method" title="GQLi::DSL.fragment (method)">fragment</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatImportantFields</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
165
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatBase</span>
166
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatBestFriend</span>
167
+ <span class='rbrace'>}</span>
168
+
169
+ <span class='comment'># A fragment used to define a query, alongside other regular fields.
170
+ </span><span class='const'>CatQuery</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span><span class='period'>.</span><span class='id identifier rubyid_query'><span class='object_link'><a href="GQLi/DSL.html#query-class_method" title="GQLi::DSL.query (method)">query</a></span></span> <span class='lbrace'>{</span>
171
+ <span class='id identifier rubyid_catCollection'>catCollection</span><span class='lparen'>(</span><span class='label'>limit:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='lbrace'>{</span>
172
+ <span class='id identifier rubyid_items'>items</span> <span class='lbrace'>{</span>
173
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatImportantFields</span>
174
+ <span class='id identifier rubyid_image'>image</span> <span class='lbrace'>{</span>
175
+ <span class='id identifier rubyid_url'>url</span>
176
+ <span class='rbrace'>}</span>
177
+ <span class='rbrace'>}</span>
178
+ <span class='rbrace'>}</span>
179
+ <span class='rbrace'>}</span>
180
+ </code></pre>
181
+
182
+ <h3 id="label-Executing+the+queries">Executing the queries</h3>
183
+
184
+ <p>To execute the queries, you need to pass a <code>Query</code> object to the
185
+ client&#39;s <code>#execute</code> method. This will return a
186
+ <code>Response</code> object which contains the <code>data</code> and the
187
+ <code>query</code> executed.</p>
188
+
189
+ <p>For example:</p>
190
+
191
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'>CONTENTFUL_GQL</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span><span class='const'>CatQuery</span><span class='rparen'>)</span>
192
+
193
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Query sent:</span><span class='tstring_end'>&quot;</span></span>
194
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_query'>query</span><span class='period'>.</span><span class='id identifier rubyid_to_gql'>to_gql</span>
195
+
196
+ <span class='id identifier rubyid_puts'>puts</span>
197
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Response received</span><span class='tstring_end'>&quot;</span></span>
198
+ <span class='id identifier rubyid_response'>response</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_catCollection'>catCollection</span><span class='period'>.</span><span class='id identifier rubyid_items'>items</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
199
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Name: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_nam'>nam</span><span class='embexpr_end'>}</span><span class='tstring_content'>e</span><span class='tstring_end'>&quot;</span></span>
200
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Likes: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_likes'>likes</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>, </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
201
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Lives #: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_lives'>lives</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
202
+ <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_bestFriend'>bestFriend</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_bf'>bf</span><span class='op'>|</span>
203
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Best Friend:</span><span class='tstring_end'>&quot;</span></span>
204
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\tName: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_bf'>bf</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
205
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\tLikes: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_bf'>bf</span><span class='period'>.</span><span class='id identifier rubyid_likes'>likes</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>, </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
206
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\tLives #: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_bf'>bf</span><span class='period'>.</span><span class='id identifier rubyid_lives'>lives</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
207
+ <span class='kw'>end</span>
208
+ <span class='kw'>end</span>
209
+ </code></pre>
210
+
211
+ <p>This will output:</p>
212
+
213
+ <pre class="code ruby"><code class="ruby">Query sent:
214
+ query {
215
+ catCollection(limit: 1) {
216
+ items {
217
+ name
218
+ likes
219
+ lives
220
+ bestFriend {
221
+ ... on Cat {
222
+ name
223
+ likes
224
+ lives
225
+ }
226
+ }
227
+ image {
228
+ url
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ Response received
235
+ Name: e
236
+ Likes: cheezburger
237
+ Lives #: 1
238
+ Best Friend:
239
+ Name: Nyan Cat
240
+ Likes: rainbows, fish
241
+ Lives #: 1337
242
+ </code></pre>
243
+
244
+ <h3 id="label-Schema+Introspection+and+Validation">Schema Introspection and Validation</h3>
245
+
246
+ <p>By default this library will fetch and cache a copy of the GraphQL Schema
247
+ for any API you create a client for.</p>
248
+
249
+ <p>This schema is used for query validation before running queries against the
250
+ APIs. In case a query is invalid for the given schema, an exception will be
251
+ raised.</p>
252
+
253
+ <p>To disable schema caching completely, when you initialize your client, send
254
+ <code>validate_query: false</code>.</p>
255
+
256
+ <p>Queries executed using the <code>#execute</code> method on the client will
257
+ be validated before executing the request if the option is set to
258
+ <code>true</code> (which it is by default).</p>
259
+
260
+ <p>To avoid validating a query, you can use <code>#execute!</code> instead.</p>
261
+
262
+ <p>To validate the query outside of the scope of an HTTP request, you can use
263
+ <code>MY_CLIENT.schema.valid?(query)</code>.</p>
264
+
265
+ <h3 id="label-Embedding+the+DSL+in+your+classes">Embedding the DSL in your classes</h3>
266
+
267
+ <p>If you want to avoid the need for prepending all GQLi DSL&#39;s calls with
268
+ <code>GQLi::DSL.</code>, then you can <code>extend</code> and/or
269
+ <code>include</code> the module within your own classes. When using
270
+ <code>extend</code>, you will have access to the DSL at a class level. When
271
+ using <code>include</code> you will have access to the DSL at an object
272
+ level.</p>
273
+
274
+ <pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>ContentfulClient</span>
275
+ <span class='id identifier rubyid_extend'>extend</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span> <span class='comment'># Makes DSL available at a class level
276
+ </span> <span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/DSL.html" title="GQLi::DSL (module)">DSL</a></span></span> <span class='comment'># Makes DSL available at an object level
277
+ </span>
278
+ <span class='const'>SPACE_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>cfexampleapi</span><span class='tstring_end'>&#39;</span></span>
279
+ <span class='const'>ACCESS_TOKEN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>b4c0n73n7fu1</span><span class='tstring_end'>&#39;</span></span>
280
+ <span class='const'>CONTENTFUL_GQL</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="GQLi.html" title="GQLi (module)">GQLi</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="GQLi/Client.html" title="GQLi::Client (class)">Client</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="GQLi/Client.html#initialize-instance_method" title="GQLi::Client#initialize (method)">new</a></span></span><span class='lparen'>(</span>
281
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>https://graphql.contentful.com/content/v1/spaces/</span><span class='embexpr_beg'>#{</span><span class='const'>SPACE_ID</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span>
282
+ <span class='label'>headers:</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Authorization</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Bearer </span><span class='embexpr_beg'>#{</span><span class='const'>ACCESS_TOKEN</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
283
+ <span class='rparen'>)</span>
284
+
285
+ <span class='const'>CatBase</span> <span class='op'>=</span> <span class='id identifier rubyid_fragment'>fragment</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatBase</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
286
+ <span class='id identifier rubyid_name'>name</span>
287
+ <span class='id identifier rubyid_likes'>likes</span>
288
+ <span class='id identifier rubyid_lives'>lives</span>
289
+ <span class='rbrace'>}</span>
290
+
291
+ <span class='const'>CatBestFriend</span> <span class='op'>=</span> <span class='id identifier rubyid_fragment'>fragment</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatBestFriend</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
292
+ <span class='id identifier rubyid_bestFriend'>bestFriend</span> <span class='lbrace'>{</span>
293
+ <span class='id identifier rubyid___on'>__on</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
294
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatBase</span>
295
+ <span class='rbrace'>}</span>
296
+ <span class='rbrace'>}</span>
297
+ <span class='rbrace'>}</span>
298
+
299
+ <span class='const'>CatImportantFields</span> <span class='op'>=</span> <span class='id identifier rubyid_fragment'>fragment</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CatImportantFields</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Cat</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span>
300
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatBase</span>
301
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatBestFriend</span>
302
+ <span class='rbrace'>}</span>
303
+
304
+ <span class='kw'>def</span> <span class='id identifier rubyid_cats'>cats</span><span class='lparen'>(</span><span class='id identifier rubyid_limit'>limit</span><span class='rparen'>)</span>
305
+ <span class='const'>CONTENTFUL_GQL</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span><span class='lparen'>(</span>
306
+ <span class='id identifier rubyid_query'>query</span> <span class='lbrace'>{</span>
307
+ <span class='id identifier rubyid_catCollection'>catCollection</span><span class='lparen'>(</span><span class='label'>limit:</span> <span class='id identifier rubyid_limit'>limit</span><span class='rparen'>)</span> <span class='lbrace'>{</span>
308
+ <span class='id identifier rubyid_items'>items</span> <span class='lbrace'>{</span>
309
+ <span class='id identifier rubyid____'>___</span> <span class='const'>CatImportantFields</span>
310
+ <span class='id identifier rubyid_image'>image</span> <span class='lbrace'>{</span>
311
+ <span class='id identifier rubyid_url'>url</span>
312
+ <span class='rbrace'>}</span>
313
+ <span class='rbrace'>}</span>
314
+ <span class='rbrace'>}</span>
315
+ <span class='rbrace'>}</span>
316
+ <span class='rparen'>)</span>
317
+ <span class='kw'>end</span>
318
+ <span class='kw'>end</span>
319
+
320
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='const'>ContentfulClient</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='period'>.</span><span class='id identifier rubyid_cats'>cats</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span>
321
+ </code></pre>
322
+
323
+ <h2 id="label-Yet+to+be+implemented">Yet to be implemented</h2>
324
+ <ul><li>
325
+ <p>Mutation queries</p>
326
+ </li><li>
327
+ <p>Subscription queries</p>
328
+ </li><li>
329
+ <p>Detailed validation errors</p>
330
+ </li></ul>
331
+
332
+ <h2 id="label-Get+involved">Get involved</h2>
333
+
334
+ <p><a href="http://makeapullrequest.com"><img
335
+ src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?maxAge=31557600"></a></p>
336
+
337
+ <p>We appreciate any help on our repositories.</p>
338
+
339
+ <h2 id="label-License">License</h2>
340
+
341
+ <p>This repository is published under the <a href="LICENSE.txt">MIT</a>
342
+ license.</p>
343
+
344
+ <h2 id="label-Code+of+Conduct">Code of Conduct</h2>
345
+
346
+ <p>We want to provide a safe, inclusive, welcoming, and harassment-free space
347
+ and experience for all participants, regardless of gender identity and
348
+ expression, sexual orientation, disability, physical appearance,
349
+ socioeconomic status, body size, ethnicity, nationality, level of
350
+ experience, age, religion (or lack thereof), or other identity markers.</p>
351
+
352
+ <p><a
353
+ href="https://github.com/contentful-developer-relations/community-code-of-conduct">Read
354
+ our full Code of Conduct</a>.</p>
355
+ </div></div>
356
+
357
+ <div id="footer">
358
+ Generated on Mon Oct 15 13:10:42 2018 by
359
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
360
+ 0.9.16 (ruby-2.5.1).
361
+ </div>
362
+
363
+ </div>
364
+ </body>
365
+ </html>