forked from DigixGlobal/dao-server
-
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.
DigixGlobal#70 JSON object scalar type
- Loading branch information
1 parent
644919e
commit 95faef8
Showing
7 changed files
with
40 additions
and
19 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
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
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
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module Scalar | ||
class JSONObject < Types::Base::BaseScalar | ||
description <<~EOS | ||
The JSONified data object | ||
EOS | ||
|
||
def self.coerce_input(input, _context) | ||
begin | ||
data = JSON.parse(input) | ||
unless data.is_a?(Hash) | ||
raise GraphQL::CoercionError, "#{input.inspect} is not a JSON object" | ||
end | ||
data | ||
rescue JSON::ParserError | ||
raise GraphQL::CoercionError, "#{input.inspect} is not a valid JSON" | ||
end | ||
end | ||
|
||
def self.coerce_result(value, _context) | ||
value | ||
end | ||
end | ||
end | ||
end |
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
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
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