File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,12 @@ def self.load_schema(schema)
5454 when String
5555 if schema . end_with? ( ".json" ) && File . exist? ( schema )
5656 load_schema ( File . read ( schema ) )
57+ elsif ( schema . end_with? ( ".graphql" , ".graphqls" ) ) && File . exist? ( schema )
58+ GraphQL ::Schema . from_definition ( schema )
5759 elsif schema =~ /\A \s *{/
5860 load_schema ( JSON . parse ( schema , freeze : true ) )
61+ elsif schema . start_with? ( "schema" )
62+ GraphQL ::Schema . from_definition ( schema )
5963 end
6064 else
6165 if schema . respond_to? ( :execute )
Original file line number Diff line number Diff line change @@ -42,6 +42,22 @@ def test_load_schema_from_json_string
4242 assert_equal "AwesomeQuery" , schema . query . graphql_name
4343 end
4444
45+ def test_load_schema_from_definition_string
46+ definition = Schema . to_definition
47+ schema = GraphQL ::Client . load_schema ( definition )
48+ assert_equal "AwesomeQuery" , schema . query . graphql_name
49+ end
50+
51+ def test_load_schema_from_definition_file
52+ definition = Schema . to_definition
53+ Tempfile . create ( [ "schema" , ".graphql" ] ) do |file |
54+ file . write ( definition )
55+ file . close
56+ schema = GraphQL ::Client . load_schema ( file . path )
57+ assert_equal "AwesomeQuery" , schema . query . graphql_name
58+ end
59+ end
60+
4561 def test_load_schema_ignores_missing_path
4662 refute GraphQL ::Client . load_schema ( "#{ __dir__ } /missing-schema.json" )
4763 end
You can’t perform that action at this time.
0 commit comments