forked from MH4GF/graphql-ruby-constraint-directive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the
constraints
option available
for "GraphQL::Constraint::Directive::Constraintを毎回記述する必要があり少々冗長なため、より簡潔に記述できるAPIを検討中です。" see https://zenn.dev/mh4gf/articles/graphql-ruby-constraint-directive#fn-cee9-1
- Loading branch information
1 parent
c6d5850
commit 7d1d7ba
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/graphql/constraint/directive/constraint_argument_keyword.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module GraphQL | ||
module Constraint | ||
module Directive | ||
module ConstraintArgumentKeyword | ||
def initialize(name, type, desc = nil, **kwargs) | ||
if kwargs.key?(:constraints) | ||
constraints = kwargs.delete(:constraints) | ||
if constraints | ||
directives = kwargs.delete(:directives) || {} | ||
constraint_directive = GraphQL::Constraint::Directive::Constraint | ||
directives[constraint_directive] = constraints | ||
kwargs[:directives] = directives | ||
end | ||
end | ||
|
||
super | ||
end | ||
end | ||
end | ||
end | ||
end |