nulogy_graphql_api 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0610f7398cf9e5bdd286b954237677cffc7252a55eea6b6ab39d074c5f8419eb
4
+ data.tar.gz: d0eefb1f32964b05d61c53fc7d0195d33d33d34deb2bcb5a0e98d5ab0e040c14
5
+ SHA512:
6
+ metadata.gz: 35934eb8f98a759437d27e81bc09b8cd2660e25f5bf4f97efb670e77af5deaba874ef248d3b197480d94ed1a9f07dd5ef5d465da67348fca1526f882859194e3
7
+ data.tar.gz: 07cde3c7bb90ed41455e215e6e05d648605d4eb978a4b12a7310cad65116a535f5f82b98d1eee67b969591537bad477f2c315abc77421e69cb0f0c4ad4156017
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ /Gemfile.lock
14
+ /spec/dummy/log/test.log
15
+
16
+ # Appraisals
17
+ *.gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require integration_spec_helper
@@ -0,0 +1 @@
1
+ --display-cop-names
@@ -0,0 +1,11 @@
1
+ #
2
+ # The Rubocop directory and file configuration for Packmanager.
3
+ #
4
+
5
+ AllCops:
6
+ Include:
7
+ - '**/*.rb'
8
+ - 'Gemfile'
9
+
10
+ Exclude:
11
+ - '**/spec/dummy/**/*'
@@ -0,0 +1,138 @@
1
+ require: rubocop-rspec
2
+
3
+ inherit_from:
4
+ - .rubocop.directories.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.6
8
+
9
+ Layout/EmptyLinesAroundAttributeAccessor:
10
+ Enabled: true
11
+
12
+ Layout/EndAlignment:
13
+ Enabled: true
14
+ EnforcedStyleAlignWith: variable
15
+
16
+ Layout/FirstArgumentIndentation:
17
+ Enabled: true
18
+ EnforcedStyle: consistent
19
+
20
+ Layout/FirstHashElementIndentation:
21
+ Enabled: true
22
+ EnforcedStyle: consistent
23
+
24
+ Layout/HashAlignment:
25
+ Enabled: true
26
+ EnforcedHashRocketStyle: key
27
+ EnforcedColonStyle: key
28
+ EnforcedLastArgumentHashStyle: always_ignore
29
+
30
+ Layout/LineLength:
31
+ Max: 140
32
+
33
+ Layout/MultilineOperationIndentation:
34
+ Enabled: true
35
+ EnforcedStyle: indented
36
+ IndentationWidth: 2
37
+
38
+ Layout/SpaceAroundMethodCallOperator:
39
+ Enabled: false
40
+
41
+ Lint/DeprecatedOpenSSLConstant:
42
+ Enabled: true
43
+
44
+ Lint/MixedRegexpCaptureTypes:
45
+ Enabled: true
46
+
47
+ Lint/RaiseException:
48
+ Enabled: false
49
+
50
+ Lint/StructNewOverride:
51
+ Enabled: false
52
+
53
+ Metrics:
54
+ Enabled: false
55
+
56
+ RSpec/AnyInstance:
57
+ Enabled: false
58
+
59
+ RSpec/DescribedClass:
60
+ Enabled: false
61
+
62
+ RSpec/ExampleLength:
63
+ Max: 20
64
+
65
+ RSpec/MultipleExpectations:
66
+ Max: 5
67
+
68
+ RSpec/LeadingSubject:
69
+ Enabled: false
70
+
71
+ RSpec/MessageSpies:
72
+ Enabled: false
73
+
74
+ RSpec/NotToNot:
75
+ EnforcedStyle: to_not
76
+
77
+ Style/ExponentialNotation:
78
+ Enabled: false
79
+
80
+ Style/HashEachMethods:
81
+ Enabled: false
82
+
83
+ Style/HashTransformKeys:
84
+ Enabled: false
85
+
86
+ Style/HashTransformValues:
87
+ Enabled: false
88
+
89
+ Style/BlockDelimiters:
90
+ Enabled: false
91
+
92
+ Style/Documentation:
93
+ Enabled: false
94
+
95
+ Style/EmptyMethod:
96
+ Enabled: false
97
+
98
+ Style/ExpandPathArguments:
99
+ Enabled: false
100
+
101
+ Style/FrozenStringLiteralComment:
102
+ Enabled: false
103
+
104
+ Style/IfUnlessModifier:
105
+ Enabled: false
106
+
107
+ Style/GuardClause:
108
+ Enabled: false
109
+
110
+ Style/MutableConstant:
111
+ Enabled: false
112
+
113
+ Style/RaiseArgs:
114
+ Enabled: false
115
+
116
+ Style/RedundantRegexpCharacterClass:
117
+ Enabled: true
118
+
119
+ Style/RedundantRegexpEscape:
120
+ Enabled: true
121
+
122
+ Style/RescueModifier:
123
+ Enabled: false
124
+
125
+ Style/RescueStandardError:
126
+ EnforcedStyle: implicit
127
+
128
+ Style/SlicingWithRange:
129
+ Enabled: true
130
+
131
+ Style/StringLiterals:
132
+ EnforcedStyle: double_quotes
133
+
134
+ Style/SymbolArray:
135
+ Enabled: false
136
+
137
+ Style/WordArray:
138
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.6.6
@@ -0,0 +1,7 @@
1
+ appraise "rails-5" do
2
+ gem "rails", "5.2.4"
3
+ end
4
+
5
+ appraise "rails-6" do
6
+ gem "rails", "6.0.0"
7
+ end
@@ -0,0 +1,38 @@
1
+ # Change log
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.4.0 (2020-07-06)
6
+
7
+ **Breaking Changes**
8
+
9
+ * Remove the GraphqlApiController
10
+ * Add the ErrorHandling controller concern
11
+
12
+ ## 0.3.1 (2020-07-03)
13
+
14
+ * Support Rails 6
15
+
16
+ ## 0.3.0 (2020-06-25)
17
+
18
+ **Breaking Changes**
19
+
20
+ * Remove spec helpers related to subscriptions
21
+
22
+ ## 0.2.0 (2020-06-24)
23
+
24
+ **Breaking Changes**
25
+
26
+ * Rename `GraphqlExecutor.call` to `execute`
27
+ * Change `schema` parameter on `execute_graphql` test helper to positional
28
+
29
+ ## 0.1.1 (2020-06-24)
30
+
31
+ **New Features**
32
+
33
+ * RSpec custom matchers
34
+ * RSpec helpers
35
+
36
+ ## 0.1.0 (2020-06-05)
37
+
38
+ * Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at danielsi@nulogy.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nulogy_graphql_api.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.9"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Daniel Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,242 @@
1
+ # NulogyGraphqlApi
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem "nulogy_graphql_api", "0.4.0", git: "https://github.com/nulogy/nulogy_graphql_api.git"
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nulogy_graphql_api
18
+
19
+ ## Usage
20
+
21
+ #### Developing
22
+
23
+ - [Receiving Requests](#receiving-requests)
24
+ - [Error Handling](#error-handling)
25
+ - [Types](#types)
26
+ - [UserErrorType](#usererrortype)
27
+ - [UUID](#uuid)
28
+ - [Rake task](#rake-task)
29
+
30
+ #### Testing
31
+
32
+ - [RSpec helpers](#rspec-helpers)
33
+ - [Test helpers](#test-helpers)
34
+ - [Custom matchers](#custom-matchers)
35
+
36
+
37
+ #### Receiving Requests
38
+
39
+ Given that you have already defined your GraphQL `Schema` you can receive requests by defining a controller action and execute the params by calling the `NulogyGraphqlApi::GraphqlExecutor`.
40
+
41
+ - Remember to configure your routes to include the controller action.
42
+ - We called the action `execute` in the example below, but you can call it whatever makes more sense for your app.
43
+
44
+ ```ruby
45
+ module MyApp
46
+ class GraphqlApiController < ApplicationController
47
+ include NulogyGraphqlApi::ErrorHandling
48
+
49
+ def execute
50
+ NulogyGraphqlApi::GraphqlExecutor.execute(
51
+ params,
52
+ context,
53
+ Schema,
54
+ NulogyGraphqlApi::TransactionService.new
55
+ )
56
+ end
57
+ end
58
+ end
59
+ ```
60
+
61
+ #### Error Handling
62
+
63
+ The `NulogyGraphqlApi::ErrorHandling` concern rescues from any unhandled `StandardError`. If you need to log errors before the response is sent to the client you can override the `render_error` method.
64
+
65
+ ```ruby
66
+ module MyApp
67
+ class GraphqlApiController < ApplicationController
68
+ include NulogyGraphqlApi::ErrorHandling
69
+
70
+ def render_error(exception)
71
+ MyApp::ExceptionNotifier.notify(exception)
72
+
73
+ super
74
+ end
75
+ end
76
+ end
77
+ ```
78
+
79
+ ### Types
80
+
81
+ #### UserErrorType
82
+
83
+ This type provides a way of returning end-user errors. You can find more details about this error handling strategy in [this document](https://docs.google.com/document/d/19JBm3gKfn0poxo07fg9rSy5iJ2N9cf3NjuVp0xQnXPQ/edit?usp=sharing).
84
+
85
+ ```ruby
86
+ module MyApp
87
+ class CreateEntity < GraphQL::Schema::Mutation
88
+ field :entity, MyApp::EntityType, null: false
89
+ field :errors, [NulogyGraphqlApi::Types::UserErrorType], null: false
90
+
91
+ def resolve(args)
92
+ entity = create_entity(args)
93
+
94
+ {
95
+ entity: entity,
96
+ errors: extract_errors(entity)
97
+ }
98
+ end
99
+
100
+ def extract_errors(entity)
101
+ entity.errors.map do |attribute, message|
102
+ {
103
+ path: path_for(attribute),
104
+ message: entity.errors.full_message(attribute, message)
105
+ }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ ```
111
+
112
+ #### UUID
113
+
114
+ This type provides a way of returning UUID values.
115
+
116
+ ```ruby
117
+ module MyApp
118
+ class EntityType < GraphQL::Schema::Object
119
+ field :id, NulogyGraphqlApi::Types::UUID, null: false
120
+ end
121
+ end
122
+ ```
123
+
124
+ ### Rake task
125
+
126
+ There is a Rake task to generate the `schema.graphql` file. All you need to provide is the path to the old and the new schema files so that the task can detect breaking changes. If you don't have an old schema file because it's your first time generating it then the rake task will just create one for you.
127
+
128
+ ```ruby
129
+ namespace :my_app_graphql_api do
130
+ desc "Generate the graphql schema of the api."
131
+
132
+ task :generate_schema => :environment do
133
+ old_schema_file_path = MyApp::Engine.root.join("schema.graphql")
134
+ new_schema_file_path = MyApp::Engine.root.join("app/graphql/my_app/schema.rb")
135
+
136
+ Rake::Task["nulogy_graphql_api:generate_schema"]
137
+ .invoke(old_schema_file_path, new_schema_file_path)
138
+ end
139
+ end
140
+ ```
141
+
142
+ ### RSpec helpers
143
+
144
+ Add this to your `spec_helpers.rb` file:
145
+
146
+ ```ruby
147
+ require "nulogy_graphql_api/rspec"
148
+ ```
149
+
150
+ Then you can include helpers and matchers as in:
151
+
152
+ ```ruby
153
+ RSpec.configure do |config|
154
+ config.include NulogyGraphqlApi::GraphqlMatchers, graphql: true
155
+ config.include NulogyGraphqlApi::GraphqlHelpers, graphql: true
156
+ end
157
+ ```
158
+
159
+ #### Test helpers
160
+
161
+ The `execute_graphql` helper execute GraphQL operations directly against the provided schema. This is how it can be used:
162
+
163
+ ```ruby
164
+ RSpec.describe MyApp::Graphql::Query, :graphql do
165
+ let(:schema) { MyApp::Schema }
166
+
167
+ it "returns an entity" do
168
+ entity = create(:entity)
169
+
170
+ response = execute_graphql(<<~GRAPHQL, schema)
171
+ query {
172
+ entity(id: "#{entity.id}") {
173
+ id
174
+ }
175
+ }
176
+ GRAPHQL
177
+
178
+ expect(response).to have_graphql_data(
179
+ project: {
180
+ id: entity.id
181
+ }
182
+ )
183
+ end
184
+ end
185
+ ```
186
+
187
+ The `request_graphql` helper issues a POST request against the provided URL. This is how it can be used:
188
+
189
+ ```ruby
190
+ RSpec.describe MyApp::Graphql::Query, :graphql, type: :request do
191
+ it "returns 401 Unauthorized given an unauthenticated request" do
192
+ gql_response = request_graphql(url, <<~GRAPHQL, headers: { "HTTP_AUTHORIZATION" => nil })
193
+ query {
194
+ entities {
195
+ id
196
+ }
197
+ }
198
+ GRAPHQL
199
+
200
+ expect(response.status).to eq(401)
201
+ expect(gql_response).to have_graphql_error("Unauthorized")
202
+ end
203
+ end
204
+ ```
205
+
206
+ #### Custom matchers
207
+
208
+ These are the custom matchers available:
209
+
210
+ `have_graphql_data` for checking the response `data`
211
+
212
+ ```ruby
213
+ expect(response).to have_graphql_data(
214
+ project: {
215
+ id: entity.id
216
+ }
217
+ )
218
+ ```
219
+
220
+ `have_graphql_error` for checking the response `errors`
221
+
222
+ ```ruby
223
+ expect(response).to have_graphql_error("Error message")
224
+ ```
225
+
226
+ ## Development
227
+
228
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run rubocop and tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
229
+
230
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
231
+
232
+ ## Contributing
233
+
234
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nulogy/nulogy_graphql_api/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/nulogy/nulogy_graphql_api/blob/master/CODE_OF_CONDUCT.md).
235
+
236
+ ## License
237
+
238
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
239
+
240
+ ## Code of Conduct
241
+
242
+ Everyone interacting in the NulogyGraphqlApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nulogy/nulogy_graphql_api/blob/master/CODE_OF_CONDUCT.md).