Skip to content

Commit

Permalink
Merge pull request #15 from Shopify/directive-arg-helpers
Browse files Browse the repository at this point in the history
Move arg helpers to WithArgs module.
  • Loading branch information
cocoahero authored Jun 8, 2021
2 parents 794c6bc + a8db461 commit b51b66e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lib/graphql_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ module WithArgs
def args
@args ||= @hash.fetch('args').map{ |arg_hash| InputValue.new(arg_hash) }
end

def required_args
@required_args ||= args.select{ |arg| arg.type.non_null? }
end

def optional_args
@optional_args ||= args.reject{ |arg| arg.type.non_null? }
end
end

module NamedHash
Expand Down Expand Up @@ -111,14 +119,6 @@ def initialize(field_hash)
@hash = field_hash
end

def required_args
@required_args ||= args.select{ |arg| arg.type.non_null? }
end

def optional_args
@optional_args ||= args.reject{ |arg| arg.type.non_null? }
end

def type
@type ||= TypeDeclaration.new(@hash.fetch('type'))
end
Expand Down
4 changes: 3 additions & 1 deletion test/graphql_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def test_description

def test_directives
example_directive = directive("directiveExample")
assert_equal %w(input), example_directive.args.map(&:name)
assert_equal %w(input enabled), example_directive.args.map(&:name)
assert_equal %w(input), example_directive.required_args.map(&:name)
assert_equal %w(enabled), example_directive.optional_args.map(&:name)
assert_equal "A nice runtime customization", example_directive.description
assert_equal ["FIELD"], example_directive.locations
refute example_directive.builtin?
Expand Down
1 change: 1 addition & 0 deletions test/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DirectiveExample < GraphQL::Schema::Directive
description "A nice runtime customization"
locations FIELD
argument :input, !SetIntegerInput, required: true
argument :enabled, Boolean, required: false
end

ExampleSchema = GraphQL::Schema.define do
Expand Down

0 comments on commit b51b66e

Please sign in to comment.