respondo-graphql 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +37 -0
- data/LICENSE +201 -0
- data/README.md +58 -18
- data/lib/generators/respondo_graphql/install/install_generator.rb +8 -6
- data/lib/respondo_graphql/configuration.rb +0 -8
- data/lib/respondo_graphql/controller_helpers.rb +51 -38
- data/lib/respondo_graphql/railtie.rb +15 -9
- data/lib/respondo_graphql/response_builder.rb +1 -1
- data/lib/respondo_graphql/short_helpers.rb +37 -0
- data/lib/respondo_graphql/version.rb +1 -1
- data/lib/respondo_graphql.rb +18 -9
- data/respondo-graphql.gemspec +3 -3
- metadata +10 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: deae34e9c1716d50cdd03df2265bf61a2243f0803c9839d5371575cb3847d504
|
|
4
|
+
data.tar.gz: 5a64d09beb1bcbbdb72268e532aa71f305f651d084fa70573da8529a9b43ee52
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43080f78322f5f502f08db4b9c888ba2ad20217f0efb0f614b0cb073444a943739bc7cf0efdb0edf1bfba1b7b886479fe6153360070d788b4c156b283b0e3f11
|
|
7
|
+
data.tar.gz: d15005511151f0c2554667aa76a66622a40969be732c9bd5e6bfb6cf51ef6855ed26160d57c7ff418a20d396eaba9bcff2724a882eadecb679e24e4f57489636
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.0] — Prefixed helpers, short names only without respondo (breaking vs. 0.1.0)
|
|
4
|
+
|
|
5
|
+
### Changed (breaking)
|
|
6
|
+
- **Every helper is now `render_graphql_*`** (`render_ok` -> `render_graphql_ok`,
|
|
7
|
+
`render_not_found` -> `render_graphql_not_found`, … all 50). In 0.1.0 the names were
|
|
8
|
+
identical to the `respondo` (JSON) gem's, so a project using both could get the
|
|
9
|
+
wrong format depending on where a module was included. With the prefix,
|
|
10
|
+
`render_ok` is always JSON and `render_graphql_ok` is always GraphQL.
|
|
11
|
+
- Private methods are prefixed too (`render_graphql_success`, `render_graphql_error`,
|
|
12
|
+
`extract_graphql_errors`), because `respondo` defines private `render_success`,
|
|
13
|
+
`render_error` and `extract_errors` that would otherwise collide.
|
|
14
|
+
- The Railtie always includes the `render_graphql_*` helpers into `ActionController::Base` /
|
|
15
|
+
`::API`. The short names (`render_ok`, …) are included as well when the `respondo` (JSON)
|
|
16
|
+
gem is **not** loaded; with `respondo` present they are left to respondo (JSON).
|
|
17
|
+
|
|
18
|
+
### Removed (breaking)
|
|
19
|
+
- `config.auto_include` and `RespondoGraphql.auto_include?`. The option existed only to
|
|
20
|
+
avoid the name collision, and it was easy to misread. Delete any
|
|
21
|
+
`config.auto_include = ...` line from your initializer (the generator only ever wrote
|
|
22
|
+
it as a comment).
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- `RespondoGraphql::ShortHelpers`: the short names (`render_ok`, `render_not_found`, … all
|
|
26
|
+
50), each delegating to its `render_graphql_*` twin. Included for you when `respondo`
|
|
27
|
+
is not installed; with `respondo` installed, include it explicitly in the controllers
|
|
28
|
+
where you want `render_ok` to be GraphQL (it warns when `respondo`'s JSON helpers are
|
|
29
|
+
also visible there).
|
|
30
|
+
- `RespondoGraphql.json_gem_loaded?`.
|
|
31
|
+
|
|
32
|
+
### Migrating from 0.1.0
|
|
33
|
+
- Without `respondo`: nothing to do, `render_ok` and `render_graphql_ok` both work.
|
|
34
|
+
- With `respondo`: rename `render_` to `render_graphql_` in your GraphQL controllers (or
|
|
35
|
+
`include RespondoGraphql::ShortHelpers` in them to keep the short names there).
|
|
36
|
+
|
|
37
|
+
Arguments and output are unchanged. Do not put `ShortHelpers` in a controller that also
|
|
38
|
+
needs `render_ok` to be JSON.
|
|
39
|
+
|
|
3
40
|
## [0.1.0] — Initial release
|
|
4
41
|
|
|
5
42
|
First release of `respondo-graphql`, the GraphQL sibling of the `respondo` JSON
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Shailendra Kumar
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Respondo Graphql 🎯
|
|
4
4
|
|
|
5
5
|
**Consistent GraphQL-spec responses for Rails controllers — in one line.**
|
|
6
6
|
|
|
7
|
+
[](https://rubygems.org/gems/respondo-graphql)
|
|
8
|
+
[](https://rubygems.org/gems/respondo-graphql)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://www.ruby-lang.org/)
|
|
11
|
+
|
|
7
12
|
</div>
|
|
8
13
|
|
|
9
14
|
---
|
|
10
15
|
|
|
11
16
|
`respondo-graphql` is the GraphQL sibling of [`respondo`](https://github.com/spatelpatidar/respondo) (JSON). It is a **standalone gem**: it has no dependency on `respondo`, its own namespace (`RespondoGraphql`), its own config, and its own generator. Install either one, or both.
|
|
12
17
|
|
|
13
|
-
It gives your controllers one expressive helper per situation (`
|
|
18
|
+
It gives your controllers one expressive helper per situation (`render_graphql_ok`, `render_graphql_not_found`, `render_graphql_unprocessable`, …) and always answers in the GraphQL response shape: `data`, `errors`, `extensions`.
|
|
14
19
|
|
|
15
20
|
## Install
|
|
16
21
|
|
|
@@ -24,7 +29,7 @@ bundle install
|
|
|
24
29
|
rails generate respondo_graphql:install
|
|
25
30
|
```
|
|
26
31
|
|
|
27
|
-
The Railtie includes the helpers into `ActionController::Base` and `ActionController::API` for you
|
|
32
|
+
The Railtie includes the helpers into `ActionController::Base` and `ActionController::API` for you, so no `include` is needed: `render_graphql_ok`, `render_graphql_not_found`, … always, and the short `render_ok`, `render_not_found`, … too when the `respondo` JSON gem is **not** installed. (If it is installed, see [Using both gems](#using-both-gems).)
|
|
28
33
|
|
|
29
34
|
## Usage
|
|
30
35
|
|
|
@@ -32,23 +37,23 @@ The Railtie includes the helpers into `ActionController::Base` and `ActionContro
|
|
|
32
37
|
class GraphqlController < ApplicationController
|
|
33
38
|
def show
|
|
34
39
|
user = User.find_by(id: params[:id])
|
|
35
|
-
return
|
|
40
|
+
return render_graphql_not_found(message: "User not found") unless user
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
render_graphql_ok(data: { user: user }, message: "User fetched")
|
|
38
43
|
end
|
|
39
44
|
|
|
40
45
|
def create
|
|
41
46
|
user = User.new(user_params)
|
|
42
47
|
if user.save
|
|
43
|
-
|
|
48
|
+
render_graphql_created(data: { user: user }, message: "Account created")
|
|
44
49
|
else
|
|
45
|
-
|
|
50
|
+
render_graphql_unprocessable(message: "Validation failed", errors: user.errors)
|
|
46
51
|
end
|
|
47
52
|
end
|
|
48
53
|
end
|
|
49
54
|
```
|
|
50
55
|
|
|
51
|
-
**Success** — `
|
|
56
|
+
**Success** — `render_graphql_ok(data: { user: { id: 1 } }, message: "User fetched")`
|
|
52
57
|
|
|
53
58
|
```json
|
|
54
59
|
{
|
|
@@ -84,13 +89,15 @@ GraphQL requires `data` to be a map, so an Array or scalar payload is wrapped as
|
|
|
84
89
|
|
|
85
90
|
## Helpers
|
|
86
91
|
|
|
87
|
-
Same
|
|
92
|
+
Same helpers, signatures and statuses as the `respondo` JSON gem, with a `graphql_` infix: `render_ok` (JSON) becomes `render_graphql_ok` (GraphQL). Nothing is shared between the two gems, so using both in one project is safe (see [Using both gems](#using-both-gems)).
|
|
88
93
|
|
|
89
94
|
| Group | Helpers | Arguments |
|
|
90
95
|
|---|---|---|
|
|
91
|
-
| 2xx with payload | `
|
|
92
|
-
| 2xx no payload | `
|
|
93
|
-
| 4xx / 5xx | `
|
|
96
|
+
| 2xx with payload | `render_graphql_ok` `render_graphql_created` `render_graphql_accepted` `render_graphql_non_authoritative` `render_graphql_partial_content` `render_graphql_multi_status` `render_graphql_already_reported` `render_graphql_im_used` | `data:` `message:` `meta:` `pagination:` |
|
|
97
|
+
| 2xx no payload | `render_graphql_no_content` `render_graphql_reset_content` | `message:` `meta:` `pagination:` |
|
|
98
|
+
| 4xx / 5xx | `render_graphql_bad_request` `render_graphql_unauthorized` `render_graphql_forbidden` `render_graphql_not_found` `render_graphql_conflict` `render_graphql_unprocessable` `render_graphql_too_many_requests` `render_graphql_server_error` `render_graphql_service_unavailable` … (40 in total) | `message:` `errors:` `meta:` |
|
|
99
|
+
|
|
100
|
+
**204 and 205 have no body.** HTTP forbids a body on `204 No Content` and `205 Reset Content`, and Rails drops it, so `render_graphql_no_content` and `render_graphql_reset_content` reach the client with an empty body. Use `render_graphql_ok` when the client needs the message, or set `config.always_ok = true` (every response becomes HTTP 200, body included).
|
|
94
101
|
|
|
95
102
|
1xx (informational) and 3xx (redirect) helpers are deliberately left out: they are transport-level and have no meaning in a GraphQL response. The full list is in `RespondoGraphql::ControllerHelpers::SUCCESS_HELPERS` and `ERROR_HELPERS`.
|
|
96
103
|
|
|
@@ -107,23 +114,56 @@ RespondoGraphql.configure do |config|
|
|
|
107
114
|
config.data_key = :result # wrapper for Array / scalar data
|
|
108
115
|
config.default_meta = { api_version: "v1" }
|
|
109
116
|
config.serializer = ->(obj) { MySerializer.new(obj).as_json }
|
|
110
|
-
config.auto_include = true # see "Using both gems"
|
|
111
117
|
end
|
|
112
118
|
```
|
|
113
119
|
|
|
114
|
-
**`always_ok`** — many GraphQL clients, Apollo among them, treat non-2xx responses as network failures. Set `config.always_ok = true` to send every response with HTTP 200 and let the `errors` array carry the failure. The default (`false`) keeps each helper's own status (404 for `
|
|
120
|
+
**`always_ok`** — many GraphQL clients, Apollo among them, treat non-2xx responses as network failures. Set `config.always_ok = true` to send every response with HTTP 200 and let the `errors` array carry the failure. The default (`false`) keeps each helper's own status (404 for `render_graphql_not_found`, …).
|
|
115
121
|
|
|
116
122
|
## Using both gems
|
|
117
123
|
|
|
118
|
-
`respondo` and `respondo-graphql`
|
|
124
|
+
`respondo` (JSON) and `respondo-graphql` can live in the same project. With `respondo` installed, the Railtie of each gem includes its own helpers into every controller and the `render_graphql_*` names never overlap with `respondo`'s, so there is nothing to configure:
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
class ReportsController < ApplicationController
|
|
128
|
+
def show
|
|
129
|
+
render_ok(data: @report) # JSON — respondo
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class GraphqlController < ApplicationController
|
|
134
|
+
def execute
|
|
135
|
+
render_graphql_ok(data: @result) # GraphQL — respondo-graphql
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`render_ok` is always JSON and `render_graphql_ok` is always GraphQL, in whichever controller you are, because every method this gem defines (public and private) carries the `render_graphql_` prefix. Each gem keeps its own configuration: `Respondo.configure` does not affect GraphQL responses, and `RespondoGraphql.configure` does not affect JSON ones.
|
|
141
|
+
|
|
142
|
+
### Which name do I use?
|
|
143
|
+
|
|
144
|
+
| Your project | `render_graphql_ok` | `render_ok` |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| only `respondo-graphql` | works, GraphQL | works, GraphQL (the short names are included for you) |
|
|
147
|
+
| `respondo-graphql` **and** `respondo` | works, GraphQL | respondo's JSON, so use the `render_graphql_*` names for GraphQL |
|
|
148
|
+
|
|
149
|
+
The gem checks whether `respondo` is loaded when Rails boots. There is no setting for it. The prefixed names work in both cases, so code written with them never changes meaning.
|
|
150
|
+
|
|
151
|
+
To get `render_ok` as GraphQL in one controller of a project that also has `respondo`, include the short names there on purpose:
|
|
119
152
|
|
|
120
153
|
```ruby
|
|
121
154
|
class GraphqlController < ApplicationController
|
|
122
|
-
include RespondoGraphql::
|
|
155
|
+
include RespondoGraphql::ShortHelpers # explicit, per controller
|
|
156
|
+
|
|
157
|
+
def execute
|
|
158
|
+
render_ok(data: @result) # = render_graphql_ok
|
|
159
|
+
end
|
|
123
160
|
end
|
|
124
161
|
```
|
|
125
162
|
|
|
126
|
-
|
|
163
|
+
- It is never included automatically next to `respondo`, so it cannot change what `render_ok` means in a controller you did not choose.
|
|
164
|
+
- If the `respondo` JSON helpers are visible in that controller, a warning is printed when the class loads, so the switch is never silent. Use `render_graphql_*` in any controller that also needs JSON.
|
|
165
|
+
- Include it **after** the controller already has the JSON helpers (the normal Rails case: `ApplicationController` inherits them from `ActionController::API`). If you include `ShortHelpers` in a class and *then* include `Respondo::ControllerHelpers` in that same class, the JSON helpers come first and `render_ok` is JSON again.
|
|
166
|
+
- It includes `ControllerHelpers` for you, and the `render_graphql_*` names keep working.
|
|
127
167
|
|
|
128
168
|
## When to use this vs. graphql-ruby
|
|
129
169
|
|
|
@@ -140,4 +180,4 @@ bundle exec rspec
|
|
|
140
180
|
|
|
141
181
|
## License
|
|
142
182
|
|
|
143
|
-
Released under the [
|
|
183
|
+
Released under the [Apache License 2.0](LICENSE).
|
|
@@ -69,7 +69,7 @@ module RespondoGraphql
|
|
|
69
69
|
out section("HTTP status")
|
|
70
70
|
out line(" Many GraphQL clients (e.g. Apollo) treat non-2xx responses as network")
|
|
71
71
|
out line(" errors. Answer y to always send HTTP 200 and report failures in `errors`.")
|
|
72
|
-
out line(" Answer n to keep each helper's status (404 for
|
|
72
|
+
out line(" Answer n to keep each helper's status (404 for render_graphql_not_found, ...).")
|
|
73
73
|
out blank
|
|
74
74
|
@cfg[:always_ok] = confirm(" Always send HTTP 200? (y/n) ")
|
|
75
75
|
end
|
|
@@ -146,10 +146,12 @@ module RespondoGraphql
|
|
|
146
146
|
lines << " # Custom serializer — receives the payload, returns a Hash/Array."
|
|
147
147
|
lines << " # config.serializer = ->(obj) { MySerializer.new(obj).as_json }"
|
|
148
148
|
lines << ""
|
|
149
|
-
lines << " #
|
|
150
|
-
lines << " #
|
|
151
|
-
lines << " #
|
|
152
|
-
lines << " #
|
|
149
|
+
lines << " # render_graphql_ok, render_graphql_not_found, ... work in every controller"
|
|
150
|
+
lines << " # with no include. Without the respondo (JSON) gem, render_ok, render_not_found, ..."
|
|
151
|
+
lines << " # work too. With respondo installed its render_ok stays JSON; to get the short"
|
|
152
|
+
lines << " # names as GraphQL in one controller, add"
|
|
153
|
+
lines << " # include RespondoGraphql::ShortHelpers"
|
|
154
|
+
lines << " # to that controller."
|
|
153
155
|
lines << "end"
|
|
154
156
|
lines << ""
|
|
155
157
|
lines.join("\n")
|
|
@@ -166,7 +168,7 @@ module RespondoGraphql
|
|
|
166
168
|
out blank
|
|
167
169
|
out line(" Next steps:")
|
|
168
170
|
out line(" 1. Review config/initializers/respondo_graphql.rb")
|
|
169
|
-
out line(" 2. Use
|
|
171
|
+
out line(" 2. Use render_graphql_ok / render_graphql_not_found / ... in your controllers")
|
|
170
172
|
out line(" 3. Re-run rails generate respondo_graphql:install to regenerate")
|
|
171
173
|
out blank
|
|
172
174
|
out divider
|
|
@@ -42,13 +42,6 @@ module RespondoGraphql
|
|
|
42
42
|
# Defaults to false so helper status codes keep meaning what they say.
|
|
43
43
|
attr_accessor :always_ok
|
|
44
44
|
|
|
45
|
-
# When true (default) the Railtie includes the helpers into
|
|
46
|
-
# ActionController::Base / ::API, so no `include` is needed. It is skipped
|
|
47
|
-
# automatically when the respondo (JSON) gem is also loaded, because both
|
|
48
|
-
# gems define the same helper names — include RespondoGraphql::ControllerHelpers
|
|
49
|
-
# in your GraphQL controller instead.
|
|
50
|
-
attr_accessor :auto_include
|
|
51
|
-
|
|
52
45
|
def initialize
|
|
53
46
|
@default_success_message = "Success"
|
|
54
47
|
@default_error_message = "An error occurred"
|
|
@@ -58,7 +51,6 @@ module RespondoGraphql
|
|
|
58
51
|
@default_meta = {}
|
|
59
52
|
@data_key = :result
|
|
60
53
|
@always_ok = false
|
|
61
|
-
@auto_include = true
|
|
62
54
|
end
|
|
63
55
|
end
|
|
64
56
|
end
|
|
@@ -4,31 +4,36 @@ module RespondoGraphql
|
|
|
4
4
|
# Mixed into Rails controllers to render GraphQL-spec responses with
|
|
5
5
|
# expressive, status-aware helpers.
|
|
6
6
|
#
|
|
7
|
+
# Every public and private method here is prefixed (render_graphql_*, ...) so
|
|
8
|
+
# this module can sit in the same controller as the respondo (JSON) gem's
|
|
9
|
+
# helpers: render_ok is always JSON, render_graphql_ok is always GraphQL, and
|
|
10
|
+
# neither depends on include order.
|
|
11
|
+
#
|
|
7
12
|
# Success helpers (2xx) — accept data:, message:, meta:, pagination:
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
13
|
+
# render_graphql_ok, render_graphql_created, render_graphql_accepted, render_graphql_non_authoritative,
|
|
14
|
+
# render_graphql_partial_content, render_graphql_multi_status, render_graphql_already_reported,
|
|
15
|
+
# render_graphql_im_used
|
|
11
16
|
#
|
|
12
17
|
# Success helpers (2xx) without a payload — accept message:, meta:, pagination:
|
|
13
|
-
#
|
|
18
|
+
# render_graphql_no_content, render_graphql_reset_content
|
|
14
19
|
#
|
|
15
20
|
# Error helpers (4xx / 5xx) — accept message:, errors:, meta:
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
21
|
+
# render_graphql_bad_request, render_graphql_unauthorized, render_graphql_payment_required,
|
|
22
|
+
# render_graphql_forbidden, render_graphql_not_found, render_graphql_method_not_allowed,
|
|
23
|
+
# render_graphql_not_acceptable, render_graphql_proxy_auth_required, render_graphql_request_timeout,
|
|
24
|
+
# render_graphql_conflict, render_graphql_gone, render_graphql_length_required,
|
|
25
|
+
# render_graphql_precondition_failed, render_graphql_payload_too_large, render_graphql_uri_too_long,
|
|
26
|
+
# render_graphql_unsupported_media_type, render_graphql_range_not_satisfiable,
|
|
27
|
+
# render_graphql_expectation_failed, render_graphql_im_a_teapot, render_graphql_misdirected_request,
|
|
28
|
+
# render_graphql_unprocessable, render_graphql_locked, render_graphql_failed_dependency,
|
|
29
|
+
# render_graphql_too_early, render_graphql_upgrade_required, render_graphql_precondition_required,
|
|
30
|
+
# render_graphql_too_many_requests, render_graphql_request_header_fields_too_large,
|
|
31
|
+
# render_graphql_unavailable_for_legal_reasons, render_graphql_server_error,
|
|
32
|
+
# render_graphql_not_implemented, render_graphql_bad_gateway, render_graphql_service_unavailable,
|
|
33
|
+
# render_graphql_gateway_timeout, render_graphql_http_version_not_supported,
|
|
34
|
+
# render_graphql_variant_also_negotiates, render_graphql_insufficient_storage,
|
|
35
|
+
# render_graphql_loop_detected, render_graphql_not_extended,
|
|
36
|
+
# render_graphql_network_authentication_required
|
|
32
37
|
#
|
|
33
38
|
# 1xx (informational) and 3xx (redirect) helpers are intentionally not
|
|
34
39
|
# provided: they are transport-level and have no meaning in a GraphQL response.
|
|
@@ -95,15 +100,15 @@ module RespondoGraphql
|
|
|
95
100
|
default_message = spec[:message]
|
|
96
101
|
|
|
97
102
|
if spec[:data]
|
|
98
|
-
# e.g.
|
|
99
|
-
define_method(:"
|
|
100
|
-
|
|
103
|
+
# e.g. render_graphql_ok(data: @user, message: "User fetched", meta: {}, pagination: nil)
|
|
104
|
+
define_method(:"render_graphql_#{name}") do |data: nil, message: default_message, meta: {}, pagination: nil|
|
|
105
|
+
render_graphql_success(data: data, message: message, meta: meta, pagination: pagination,
|
|
101
106
|
code: spec[:code], status: spec[:status])
|
|
102
107
|
end
|
|
103
108
|
else
|
|
104
|
-
# e.g.
|
|
105
|
-
define_method(:"
|
|
106
|
-
|
|
109
|
+
# e.g. render_graphql_no_content(message: "Deleted", meta: {}, pagination: nil)
|
|
110
|
+
define_method(:"render_graphql_#{name}") do |message: default_message, meta: {}, pagination: nil|
|
|
111
|
+
render_graphql_success(data: nil, message: message, meta: meta, pagination: pagination,
|
|
107
112
|
code: spec[:code], status: spec[:status])
|
|
108
113
|
end
|
|
109
114
|
end
|
|
@@ -112,9 +117,9 @@ module RespondoGraphql
|
|
|
112
117
|
ERROR_HELPERS.each do |name, spec|
|
|
113
118
|
default_message = spec[:message]
|
|
114
119
|
|
|
115
|
-
# e.g.
|
|
116
|
-
define_method(:"
|
|
117
|
-
|
|
120
|
+
# e.g. render_graphql_not_found(message: "User not found", errors: nil, meta: {})
|
|
121
|
+
define_method(:"render_graphql_#{name}") do |message: default_message, errors: nil, meta: {}|
|
|
122
|
+
render_graphql_error(message: message, errors: errors, meta: meta, code: spec[:code], status: spec[:status])
|
|
118
123
|
end
|
|
119
124
|
end
|
|
120
125
|
|
|
@@ -132,7 +137,7 @@ module RespondoGraphql
|
|
|
132
137
|
# @param pagination [Hash, nil] pagination hash built by the caller
|
|
133
138
|
# @param code [Integer, nil] numeric HTTP code recorded in extensions
|
|
134
139
|
# @param status [Symbol, Integer] HTTP status (default: :ok / 200)
|
|
135
|
-
def
|
|
140
|
+
def render_graphql_success(data: nil, message: nil, meta: {}, code: nil, pagination: nil, status: :ok)
|
|
136
141
|
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
137
142
|
|
|
138
143
|
payload = ResponseBuilder.new(
|
|
@@ -144,7 +149,7 @@ module RespondoGraphql
|
|
|
144
149
|
request: try(:request)
|
|
145
150
|
).build
|
|
146
151
|
|
|
147
|
-
render json: payload, status:
|
|
152
|
+
render json: payload, status: respondo_graphql_http_status(code, status)
|
|
148
153
|
end
|
|
149
154
|
|
|
150
155
|
# Render a failed GraphQL response: data is null, `errors` explains why.
|
|
@@ -154,7 +159,7 @@ module RespondoGraphql
|
|
|
154
159
|
# @param code [Integer, String, nil] HTTP code (Integer) or machine-readable code (String)
|
|
155
160
|
# @param meta [Hash] extra fields merged into extensions
|
|
156
161
|
# @param status [Symbol, Integer] HTTP status (default: :unprocessable_content / 422)
|
|
157
|
-
def
|
|
162
|
+
def render_graphql_error(message: nil, errors: nil, code: nil, meta: {}, status: :unprocessable_content)
|
|
158
163
|
merged_meta = code ? meta.merge(code: code, status: status) : meta
|
|
159
164
|
|
|
160
165
|
payload = ResponseBuilder.new(
|
|
@@ -162,20 +167,28 @@ module RespondoGraphql
|
|
|
162
167
|
data: nil,
|
|
163
168
|
message: message,
|
|
164
169
|
meta: merged_meta,
|
|
165
|
-
errors:
|
|
170
|
+
errors: extract_graphql_errors(errors),
|
|
166
171
|
request: try(:request)
|
|
167
172
|
).build
|
|
168
173
|
|
|
169
|
-
render json: payload, status:
|
|
174
|
+
render json: payload, status: respondo_graphql_http_status(code, status)
|
|
170
175
|
end
|
|
171
176
|
|
|
172
|
-
#
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
# The HTTP status Rails should send.
|
|
178
|
+
# * config.always_ok -> every response is HTTP 200.
|
|
179
|
+
# * otherwise a numeric code (every helper has one) is sent as-is. Rack has
|
|
180
|
+
# renamed several status symbols between versions (:payload_too_large,
|
|
181
|
+
# :unprocessable_entity, ...), so a number is the one form that works on
|
|
182
|
+
# every Rack/Rails version.
|
|
183
|
+
# * without a numeric code (a direct render_graphql_error call) the symbol is used.
|
|
184
|
+
def respondo_graphql_http_status(code, status)
|
|
185
|
+
return :ok if RespondoGraphql.config.always_ok
|
|
186
|
+
|
|
187
|
+
code.is_a?(Integer) ? code : status
|
|
175
188
|
end
|
|
176
189
|
|
|
177
190
|
# Normalize errors into a plain Hash regardless of source type.
|
|
178
|
-
def
|
|
191
|
+
def extract_graphql_errors(errors)
|
|
179
192
|
return nil if errors.nil?
|
|
180
193
|
return errors.to_hash if defined?(ActiveModel::Errors) && errors.is_a?(ActiveModel::Errors)
|
|
181
194
|
return errors if errors.is_a?(Hash)
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RespondoGraphql
|
|
4
|
-
# Includes
|
|
5
|
-
#
|
|
4
|
+
# Includes this gem's helpers into ActionController::Base and ActionController::API,
|
|
5
|
+
# so no `include` is needed in a controller.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
7
|
+
# * render_graphql_ok, render_graphql_not_found, ... always.
|
|
8
|
+
# * render_ok, render_not_found, ... (RespondoGraphql::ShortHelpers) only when the
|
|
9
|
+
# respondo (JSON) gem is NOT loaded. With respondo present those short names
|
|
10
|
+
# belong to respondo (JSON), so they are left alone; use render_graphql_* for
|
|
11
|
+
# GraphQL, or `include RespondoGraphql::ShortHelpers` in a controller that
|
|
12
|
+
# should answer `render_ok` in GraphQL.
|
|
13
|
+
#
|
|
14
|
+
# The check runs when ActionController loads, after Bundler has required every gem,
|
|
15
|
+
# so the order of the gems in the Gemfile does not matter.
|
|
12
16
|
class Railtie < Rails::Railtie
|
|
13
17
|
initializer "respondo_graphql.include_controller_helpers" do
|
|
14
18
|
ActiveSupport.on_load(:action_controller_base) do
|
|
15
|
-
include RespondoGraphql::ControllerHelpers
|
|
19
|
+
include RespondoGraphql::ControllerHelpers
|
|
20
|
+
include RespondoGraphql::ShortHelpers unless RespondoGraphql.json_gem_loaded?
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
ActiveSupport.on_load(:action_controller_api) do
|
|
19
|
-
include RespondoGraphql::ControllerHelpers
|
|
24
|
+
include RespondoGraphql::ControllerHelpers
|
|
25
|
+
include RespondoGraphql::ShortHelpers unless RespondoGraphql.json_gem_loaded?
|
|
20
26
|
end
|
|
21
27
|
end
|
|
22
28
|
end
|
|
@@ -93,7 +93,7 @@ module RespondoGraphql
|
|
|
93
93
|
extensions
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
# A String `code:` passed to
|
|
96
|
+
# A String `code:` passed to render_graphql_error is already machine-readable and
|
|
97
97
|
# is used as-is; otherwise the status symbol is used, e.g. :not_found
|
|
98
98
|
# becomes "NOT_FOUND". Falls back to "ERROR" when neither is available.
|
|
99
99
|
def error_code
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RespondoGraphql
|
|
4
|
+
# Short names: `render_ok`, `render_not_found`, ... Each one simply calls its
|
|
5
|
+
# render_graphql_* twin.
|
|
6
|
+
#
|
|
7
|
+
# The Railtie includes this module for you when the respondo (JSON) gem is NOT
|
|
8
|
+
# installed, so `render_ok` just works. When respondo IS installed it is not included
|
|
9
|
+
# (those names are respondo's JSON helpers). You can still opt in per controller:
|
|
10
|
+
#
|
|
11
|
+
# class GraphqlController < ApplicationController
|
|
12
|
+
# include RespondoGraphql::ShortHelpers
|
|
13
|
+
#
|
|
14
|
+
# def execute
|
|
15
|
+
# render_ok(data: result) # same as render_graphql_ok(data: result)
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# In that controller the short names then mean GraphQL, and a warning is printed
|
|
20
|
+
# when the JSON helpers are visible there, so the switch is never silent.
|
|
21
|
+
module ShortHelpers
|
|
22
|
+
def self.included(base)
|
|
23
|
+
base.include(ControllerHelpers)
|
|
24
|
+
return unless defined?(::Respondo::ControllerHelpers) && base.ancestors.include?(::Respondo::ControllerHelpers)
|
|
25
|
+
|
|
26
|
+
warn "[respondo-graphql] #{base} includes RespondoGraphql::ShortHelpers while respondo's JSON helpers " \
|
|
27
|
+
"are available: render_ok & co. now answer in GraphQL in this controller. " \
|
|
28
|
+
"Use render_graphql_* everywhere if it also needs JSON."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
(ControllerHelpers::SUCCESS_HELPERS.keys + ControllerHelpers::ERROR_HELPERS.keys).each do |name|
|
|
32
|
+
define_method(:"render_#{name}") do |**options|
|
|
33
|
+
public_send(:"render_graphql_#{name}", **options)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/respondo_graphql.rb
CHANGED
|
@@ -5,6 +5,7 @@ require_relative "respondo_graphql/configuration"
|
|
|
5
5
|
require_relative "respondo_graphql/serializer"
|
|
6
6
|
require_relative "respondo_graphql/response_builder"
|
|
7
7
|
require_relative "respondo_graphql/controller_helpers"
|
|
8
|
+
require_relative "respondo_graphql/short_helpers"
|
|
8
9
|
|
|
9
10
|
# RespondoGraphql — consistent GraphQL-spec responses for Rails controllers.
|
|
10
11
|
#
|
|
@@ -15,15 +16,23 @@ require_relative "respondo_graphql/controller_helpers"
|
|
|
15
16
|
# config.always_ok = true # HTTP 200 for every response
|
|
16
17
|
# end
|
|
17
18
|
#
|
|
18
|
-
# @example Use in a controller
|
|
19
|
+
# @example Use in a controller (helpers are always render_graphql_*)
|
|
19
20
|
# class GraphqlController < ApplicationController
|
|
20
21
|
# def show
|
|
21
|
-
#
|
|
22
|
+
# render_graphql_ok(data: { user: User.find(params[:id]) }, message: "User fetched")
|
|
22
23
|
# end
|
|
23
24
|
# end
|
|
24
25
|
#
|
|
25
|
-
# @example
|
|
26
|
-
#
|
|
26
|
+
# @example Without the respondo (JSON) gem: both names work, no include needed
|
|
27
|
+
# render_ok(data: user) # GraphQL
|
|
28
|
+
# render_graphql_ok(data: user) # GraphQL (same thing)
|
|
29
|
+
#
|
|
30
|
+
# @example Next to the respondo (JSON) gem: use the prefix for GraphQL
|
|
31
|
+
# render_ok(data: user) # JSON (respondo)
|
|
32
|
+
# render_graphql_ok(data: user) # GraphQL (respondo-graphql)
|
|
33
|
+
#
|
|
34
|
+
# @example Include manually (outside Rails)
|
|
35
|
+
# class GraphqlController
|
|
27
36
|
# include RespondoGraphql::ControllerHelpers
|
|
28
37
|
# end
|
|
29
38
|
module RespondoGraphql
|
|
@@ -43,11 +52,11 @@ module RespondoGraphql
|
|
|
43
52
|
@config = Configuration.new
|
|
44
53
|
end
|
|
45
54
|
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
def
|
|
50
|
-
|
|
55
|
+
# True when the respondo (JSON) gem is loaded. Its helpers use the same short
|
|
56
|
+
# names (render_ok, ...), so only then are the short names left out and
|
|
57
|
+
# render_graphql_* is the way to call this gem.
|
|
58
|
+
def json_gem_loaded?
|
|
59
|
+
defined?(::Respondo::ControllerHelpers) ? true : false
|
|
51
60
|
end
|
|
52
61
|
end
|
|
53
62
|
end
|
data/respondo-graphql.gemspec
CHANGED
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
Standalone gem — it does not depend on the respondo (JSON) gem.
|
|
19
19
|
DESC
|
|
20
20
|
spec.homepage = "https://github.com/spatelpatidar/respondo-graphql"
|
|
21
|
-
spec.license = "
|
|
22
|
-
spec.required_ruby_version = ">=
|
|
21
|
+
spec.license = "Apache-2.0"
|
|
22
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
23
23
|
|
|
24
24
|
spec.metadata = {
|
|
25
25
|
"homepage_uri" => spec.homepage,
|
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
"rubygems_mfa_required" => "true"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
spec.files = Dir["lib/**/*.rb", "README.md", "LICENSE
|
|
32
|
+
spec.files = Dir["lib/**/*.rb", "README.md", "LICENSE", "CHANGELOG.md", "respondo-graphql.gemspec"]
|
|
33
33
|
spec.require_paths = ["lib"]
|
|
34
34
|
|
|
35
35
|
spec.add_development_dependency "railties", "~> 8.1.3"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: respondo-graphql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- shailendra Kumar
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -94,6 +94,7 @@ extensions: []
|
|
|
94
94
|
extra_rdoc_files: []
|
|
95
95
|
files:
|
|
96
96
|
- CHANGELOG.md
|
|
97
|
+
- LICENSE
|
|
97
98
|
- README.md
|
|
98
99
|
- lib/generators/respondo_graphql/install/install_generator.rb
|
|
99
100
|
- lib/respondo-graphql.rb
|
|
@@ -103,18 +104,19 @@ files:
|
|
|
103
104
|
- lib/respondo_graphql/railtie.rb
|
|
104
105
|
- lib/respondo_graphql/response_builder.rb
|
|
105
106
|
- lib/respondo_graphql/serializer.rb
|
|
107
|
+
- lib/respondo_graphql/short_helpers.rb
|
|
106
108
|
- lib/respondo_graphql/version.rb
|
|
107
109
|
- respondo-graphql.gemspec
|
|
108
110
|
homepage: https://github.com/spatelpatidar/respondo-graphql
|
|
109
111
|
licenses:
|
|
110
|
-
-
|
|
112
|
+
- Apache-2.0
|
|
111
113
|
metadata:
|
|
112
114
|
homepage_uri: https://github.com/spatelpatidar/respondo-graphql
|
|
113
115
|
source_code_uri: https://github.com/spatelpatidar/respondo-graphql
|
|
114
116
|
changelog_uri: https://github.com/spatelpatidar/respondo-graphql/blob/main/CHANGELOG.md
|
|
115
117
|
bug_tracker_uri: https://github.com/spatelpatidar/respondo-graphql/issues
|
|
116
118
|
rubygems_mfa_required: 'true'
|
|
117
|
-
post_install_message:
|
|
119
|
+
post_install_message:
|
|
118
120
|
rdoc_options: []
|
|
119
121
|
require_paths:
|
|
120
122
|
- lib
|
|
@@ -122,15 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
122
124
|
requirements:
|
|
123
125
|
- - ">="
|
|
124
126
|
- !ruby/object:Gem::Version
|
|
125
|
-
version:
|
|
127
|
+
version: 2.7.0
|
|
126
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
129
|
requirements:
|
|
128
130
|
- - ">="
|
|
129
131
|
- !ruby/object:Gem::Version
|
|
130
132
|
version: '0'
|
|
131
133
|
requirements: []
|
|
132
|
-
rubygems_version: 3.4.
|
|
133
|
-
signing_key:
|
|
134
|
+
rubygems_version: 3.4.1
|
|
135
|
+
signing_key:
|
|
134
136
|
specification_version: 4
|
|
135
137
|
summary: Consistent GraphQL-spec responses for Rails controllers — data, errors, extensions.
|
|
136
138
|
test_files: []
|