Skip to content

Commit 4421867

Browse files
author
Robert Mosolgo
authored
Merge pull request rmosolgo#1288 from ianks/schema-as-json
Make Schema#as_json return an instance of Hash
2 parents 6e24f61 + a1b2f6a commit 4421867

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/graphql/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def to_document
554554
# @param except [<#call(member, ctx)>]
555555
# @return [Hash] GraphQL result
556556
def as_json(only: nil, except: nil, context: {})
557-
execute(Introspection::INTROSPECTION_QUERY, only: only, except: except, context: context)
557+
execute(Introspection::INTROSPECTION_QUERY, only: only, except: except, context: context).to_h
558558
end
559559

560560
# Returns the JSON response of {Introspection::INTROSPECTION_QUERY}.

spec/graphql/rake_task_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
end
3535
dumped_json = File.read("./schema.json")
3636
expected_json = JSON.pretty_generate(RakeTaskSchema.execute(GraphQL::Introspection::INTROSPECTION_QUERY))
37-
assert_equal(expected_json, dumped_json)
37+
38+
# Test that that JSON is logically equivalent, not serialized the same
39+
assert_equal(JSON.parse(expected_json), JSON.parse(dumped_json))
3840

3941
dumped_idl = File.read("./schema.graphql")
4042
expected_idl = rake_task_schema_defn.chomp

spec/graphql/schema_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ class LazyObjChild < LazyObj; end
425425
end
426426
end
427427

428+
describe "#as_json" do
429+
it "returns a hash" do
430+
result = schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
431+
assert_equal result.as_json.class, Hash
432+
end
433+
end
434+
428435
describe "#get_field" do
429436
it "returns fields by type or type name" do
430437
field = schema.get_field("Cheese", "id")

0 commit comments

Comments
 (0)