Skip to content
Merged
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
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