Skip to content

Commit 0ef7c7d

Browse files
authored
Change graphql_api helper name (#7)
Change the helper API to be `graphql_operation`. This more explicitly calls out that the Ruby heredoc can be more than just a query operation, but a mutation as well. Bumps the version to 0.4.0
1 parent 45f71dc commit 0ef7c7d

21 files changed

+85
-71
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
rspec-graphql_response (0.3.0)
4+
rspec-graphql_response (0.4.0)
55
graphql (>= 1.0)
66
rspec (>= 3.0)
77

README.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,45 @@ Or install it yourself as:
3030

3131
## Full Documentation
3232

33-
* [Release Notes](/RELEASE_NOTES.md)
34-
* [Upgrade Guide](/UPGRADE.md)
33+
- [Release Notes](/RELEASE_NOTES.md)
34+
- [Upgrade Guide](/UPGRADE.md)
3535

3636
The full documentation for RSpec::GraphQLResponse can be found in the `/docs` folder.
3737

3838
Configuration:
39-
* [RSpec::GraphQLResponse.configure](/docs/configuration.md)
40-
* [Spec Type :graphql](/docs/graphql_spec_type.md)
39+
40+
- [RSpec::GraphQLResponse.configure](/docs/configuration.md)
41+
- [Spec Type :graphql](/docs/graphql_spec_type.md)
4142

4243
Custom Matchers:
43-
* [have_errors](/docs/have_errors.md) - validates errors, or lack of, on the GraphQL response
44-
* [have_operation](/docs/have_operation.md) - validates the presence of a specified graphql operation in the graphql response
44+
45+
- [have_errors](/docs/have_errors.md) - validates errors, or lack of, on the GraphQL response
46+
- [have_operation](/docs/have_operation.md) - validates the presence of a specified graphql operation in the graphql response
4547

4648
Context / Describe Helper Methods:
47-
* [graphql_query](/docs/execute_graphql.md) - the query to execute
48-
* [graphql_variables](/docs/execute_graphql.md) - a hash of variables the query expects
49-
* [graphql_context](/docs/execute_graphql.md) - the `context` of a query or mutation's resolver
49+
50+
- [graphql_operation](/docs/execute_graphql.md) - the operation to execute (i.e query or mutation)
51+
- [graphql_variables](/docs/execute_graphql.md) - a hash of variables the query expects
52+
- [graphql_context](/docs/execute_graphql.md) - the `context` of a query or mutation's resolver
5053

5154
Spec Helper Methods:
52-
* [execute_graphql](/docs/execute_graphql.md) - executes a graphql call with the registered schema, query, variables and context
53-
* [response](/docs/response.md) - the response, as JSON, of the executed graphql query
54-
* [operation](/docs/operation.md) - retrieves the results of a named operation from the GraphQL response
55+
56+
- [execute_graphql](/docs/execute_graphql.md) - executes a graphql call with the registered schema, query, variables and context
57+
- [response](/docs/response.md) - the response, as JSON, of the executed graphql query
58+
- [operation](/docs/operation.md) - retrieves the results of a named operation from the GraphQL response
5559

5660
API / Development
57-
* [.add_matcher](/docs/add_matcher.md) - add a custom RSpec matcher to the GraphQLResponse matchers
58-
* [.add_validator](/docs/add_validator.md) - add a custom validator to be used by the custom matchers
59-
* [.add_helper](/docs/add_helper.md) - add helper methods to your specs, made avialable in `it` or `describe` / `context` blocks
61+
62+
- [.add_matcher](/docs/add_matcher.md) - add a custom RSpec matcher to the GraphQLResponse matchers
63+
- [.add_validator](/docs/add_validator.md) - add a custom validator to be used by the custom matchers
64+
- [.add_helper](/docs/add_helper.md) - add helper methods to your specs, made avialable in `it` or `describe` / `context` blocks
6065

6166
## Getting Started
6267

63-
There are only a couple of bits you need to get started:
68+
There are only a couple of bits you need to get started:
6469

65-
* configuration of a GraphQL Schema in [`RSpec::GraphQLResponse.configure`](/docs/configuration.md)
66-
* the inclusion of [`type: :graphql`](/docs/graphql_spec_type.md) in your `RSpec.describe` call
70+
- configuration of a GraphQL Schema in [`RSpec::GraphQLResponse.configure`](/docs/configuration.md)
71+
- the inclusion of [`type: :graphql`](/docs/graphql_spec_type.md) in your `RSpec.describe` call
6772

6873
```ruby
6974
RSpec::GraphQLResponse.configure do |config|
@@ -114,7 +119,7 @@ in your specs.
114119

115120
```ruby
116121
RSpec.describe Some::Thing, type: :graphql do
117-
graphql_query <<-GQL
122+
graphql_operation <<-GQL
118123
query ListCharacters{
119124
characters {
120125
id
@@ -138,7 +143,7 @@ way. The reduce this, `RSpec::GraphQLResponse` provides a built-in `response` he
138143

139144
```ruby
140145
RSpec.describe Some::Thing, type: :graphql do
141-
graphql_query <<-GQL
146+
graphql_operation <<-GQL
142147
query ListCharacters{
143148
characters {
144149
id
@@ -165,7 +170,7 @@ nested hash checking, use the built-in `operation` method to retrieve the `chara
165170

166171
```ruby
167172
RSpec.describe Some::Thing, type: :graphql do
168-
graphql_query <<-GQL
173+
graphql_operation <<-GQL
169174
query ListCharacters{
170175
characters {
171176
id
@@ -178,7 +183,7 @@ RSpec.describe Some::Thing, type: :graphql do
178183
characters = operation(:characters)
179184

180185
expect(characters).to include(
181-
# ...
186+
# ...
182187
)
183188
end
184189
end

RELEASE_NOTES.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ Release notes for various versions of RSpec::GraphQLResponse
44

55
See [the upgrade guide](/UPGRADE.md) for details on changes between versions and how to upgrade.
66

7+
## v0.4.0 - Helper API change
8+
9+
### Breaking Changes
10+
11+
The helper `graphql_query` was renamed to `graphql_operation` to better communicate the use of the helper. Naming the helper with `_query` lead to an association that its use was meant for GraphQL query operations and could not also be used for a mutation.
12+
713
## v0.2.0 - GraphQL Configuration DSL and Refactorings
814

915
Misc changes and corrections, some new features, and generally trying to create a more robust
1016
and usable experience, right out of the box.
1117

1218
### New Features
1319

14-
* Significantly improved documentation
15-
* `have_operation` matcher
16-
* GraphQL configuration DSL
17-
* `graphql_query`
18-
* `graphql_variables`
19-
* `graphql_context`
20-
* Describe/Context level RSpec helper methods via `.add_context_helper` DSL
20+
- Significantly improved documentation
21+
- `have_operation` matcher
22+
- GraphQL configuration DSL
23+
- `graphql_query`
24+
- `graphql_variables`
25+
- `graphql_context`
26+
- Describe/Context level RSpec helper methods via `.add_context_helper` DSL
2127

2228
### Breaking Changes
2329

@@ -32,8 +38,8 @@ Lots of misc bug fixes, including caching of values, ensuring things work in nes
3238

3339
Early beta work to get this out the door and begin adoption
3440

35-
* `have_errors` matcher
36-
* `operation` helper
37-
* `response` helper
38-
* `execute_graphql` helper
39-
* DSL for adding custom matchers, validators, and helpers
41+
- `have_errors` matcher
42+
- `operation` helper
43+
- `response` helper
44+
- `execute_graphql` helper
45+
- DSL for adding custom matchers, validators, and helpers

UPGRADE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Upgrade Guide
22

3+
## v0.3.0 to v0.4.0
4+
5+
There is a breaking change between v0.3.0 and v0.4.0 where the helper `graphql_query` was renamed to `graphql_operation`. In order to migrate to v0.4.0 all references to `graphql_query` can be replaced with `graphql_operation`.
6+
37
## v0.1.0 to v0.2.0
48

5-
There is a breaking change between v0.1.0 and v0.2.0 regarding the configuration of graphql queries, variables and context.
9+
There is a breaking change between v0.1.0 and v0.2.0 regarding the configuration of graphql queries, variables and context.
610
Previously, you defined these three items with `let` in rspec:
711

812
```ruby

docs/add_helper.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ it "does stuff" do
2323
end
2424
```
2525

26-
It's not a huge difference, but when you consider how well the `operation` method handles `nil` and
26+
It's not a huge difference, but when you consider how well the `operation` method handles `nil` and
2727
operation results that are not found, it's well worth the few lines of savings.
2828

2929
There are many other helpers available for your test suites, as well. Be sure to check the full
@@ -51,15 +51,14 @@ RSpec::GraphQLResponse.add_helper :operation do |operation_name|
5151
end
5252
```
5353

54-
In this example, the `response` helper is used, which guarantees the graphql has been executed and a response
54+
In this example, the `response` helper is used, which guarantees the graphql has been executed and a response
5555
is available, assuming there were no exceptions preventing that.
5656

5757
## Add a Context Helper
5858

5959
In addition to Spec level helpers, RSpec::GraphQLResponse allows you to add custom helpers at the context
6060
level. This means you can add configuration and other bits that can be called outside of an `it` block.
61-
The existing `graphql_query` and other DSL methods for configuring graphql calls are a great example of
62-
context level helpers.
61+
The existing `graphql_operation` and other DSL methods for configuring graphql calls are a great example of context level helpers.
6362

6463
To create a context helper, call `RSpec::GraphQLResponse.add_context_helper(name, &helper_block)`. The params
6564
are the same as `.add_helper`, but the resulting method will be made available in `describe` and `context`
@@ -73,7 +72,7 @@ end
7372

7473
In this simple example, a method called `my_setting` is created, and it stores a value in the instance variable
7574
`@my_setting`. This takes advantage of RSpec's native ability to handle instance variables in describe and
76-
context blocks, allowing the variable to exist withing the hierarchy of objects for a given spec.
75+
context blocks, allowing the variable to exist withing the hierarchy of objects for a given spec.
7776

7877
With that defined, it can be used within a spec:
7978

docs/execute_graphql.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ RSPec.describe Cool::Stuff, type: :graphql do
88
let(:user) { create(:graphql_user) }
99
let(:search_name) { "Pet" }
1010

11-
graphql_query <<-GQL
11+
graphql_operation <<-GQL
1212
query SomeThing($name: String) {
1313
characters(name: $name) {
1414
id
1515
name
1616
}
1717
}
1818
GQL
19-
19+
2020
graphql_variables do
2121
{
2222
name: search_name
@@ -37,7 +37,7 @@ end
3737

3838
## Available Configuration Methods
3939

40-
### `graphql_query`
40+
### `graphql_operation`
4141

4242
A string - most commonly a ruby heredoc - for the graphql query to execute
4343

docs/have_operation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ retrieving the operation's results.
77

88
```ruby
99
RSpec.describe My::Characters, type: :graphql do
10-
graphql_query <<-GQL
10+
graphql_operation <<-GQL
1111
query CharacterList {
1212
characters {
1313
id
@@ -28,7 +28,7 @@ end
2828

2929
```ruby
3030
RSpec.describe My::Characters, type: :graphql do
31-
graphql_query <<-GQL
31+
graphql_operation <<-GQL
3232
query CharacterList {
3333
characters {
3434
id

lib/rspec/graphql_response/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.add_helper(name, scope: :spec, &helper)
4040
end
4141

4242
# describe level helpers
43-
require_relative "helpers/graphql_query"
43+
require_relative "helpers/graphql_operation"
4444
require_relative "helpers/graphql_variables"
4545
require_relative "helpers/graphql_context"
4646

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
RSpec::GraphQLResponse.add_helper :execute_graphql do
22
config = RSpec::GraphQLResponse.configuration
33

4-
query = graphql_query if respond_to? :graphql_query
5-
query = self.instance_eval(&graphql_query) if query.is_a? Proc
4+
operation = graphql_operation if respond_to? :graphql_operation
5+
operation = self.instance_eval(&graphql_operation) if operation.is_a? Proc
66

7-
query_vars = graphql_variables if respond_to? :graphql_variables
8-
query_vars = self.instance_eval(&graphql_variables) if query_vars.is_a? Proc
7+
operation_vars = graphql_variables if respond_to? :graphql_variables
8+
operation_vars = self.instance_eval(&graphql_variables) if operation_vars.is_a? Proc
99

10-
query_context = graphql_context if respond_to? :graphql_context
11-
query_context = self.instance_eval(&query_context) if query_context.is_a? Proc
10+
operation_context = graphql_context if respond_to? :graphql_context
11+
operation_context = self.instance_eval(&operation_context) if operation_context.is_a? Proc
1212

13-
config.graphql_schema.execute(query, {
14-
variables: query_vars,
15-
context: query_context
13+
config.graphql_schema.execute(operation, {
14+
variables: operation_vars,
15+
context: operation_context
1616
})
1717
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RSpec::GraphQLResponse.add_context_helper :graphql_operation do |gql|
2+
self.define_method(:graphql_operation) { gql }
3+
end

0 commit comments

Comments
 (0)