Skip to content

Add deprecated_reason support for arguments #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PostType < GraphQL::Schema::Object
argument :filter, types.String, required: false
argument :id, types.ID, required: false
argument :isPublished, types.Boolean, required: false
argument :published, types.String, required: false, deprecation_reason: 'Use isPublished instead'
end
end
```
Expand Down Expand Up @@ -129,6 +130,9 @@ describe PostType do
expect(subject).to accept_argument(:id).of_type('ID')
end

# Check a argument is deprecated
it { is_expected.to accept_argument(:published).with_deprecation_reason }

it { is_expected.not_to accept_argument(:weirdo) }

# The gem automatically converts argument names to CamelCase, so this will
Expand Down Expand Up @@ -207,6 +211,15 @@ This project is intended to be a safe, welcoming space for collaboration, and
contributors are expected to adhere to the
[Contributor Covenant](http://contributor-covenant.org) code of conduct.

## Testing

```
gem install diff-lcs
bundle install
```

Run tests!

## License

The gem is available as open source under the terms of the
Expand Down
6 changes: 6 additions & 0 deletions lib/rspec/graphql_matchers/accept_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'base_matcher'
require_relative './have_a_field_matchers/of_type'
require_relative './have_a_field_matchers/with_deprecation_reason'

module RSpec
module GraphqlMatchers
Expand Down Expand Up @@ -43,6 +44,11 @@ def of_type(expected_field_type)
self
end

def with_deprecation_reason(expected_reason = nil)
@expectations << HaveAFieldMatchers::WithDeprecationReason.new(expected_reason)
self
end

def failure_message
base_msg = "expected #{member_name(@graph_object)} " \
"to accept argument `#{@expected_arg_name}`" \
Expand Down
12 changes: 12 additions & 0 deletions spec/rspec/accept_argument_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ module GraphqlMatchers
argument :is_test, GraphQL::Types::Boolean, required: false
argument :not_camelized, GraphQL::Types::Boolean, required: false,
camelize: false
argument :deprecated_argument, types.String, required: false,
deprecation_reason: 'deprecated'

end
end

include_examples 'accept argument'

describe '.with_deprecation_reason' do
let(:deprecated_argument) { :deprecated_argument }

it 'passes when the deprecation reasons match' do
expect(a_type).to accept_argument(deprecated_argument)
.with_deprecation_reason('deprecated')
end
end
end

context 'with legacy DSL api' do
Expand Down