Module: GraphWeaver::SchemaLoader

Defined in:
lib/graph_weaver/schema_loader.rb

Overview

Load a schema for codegen from either format a remote service can hand you: an introspection dump (.json) or SDL (.graphql/.gql).

Class Method Summary collapse

Class Method Details

.load(path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/graph_weaver/schema_loader.rb', line 10

def self.load(path)
  case File.extname(path)
  when ".json"
    GraphQL::Schema.from_introspection(JSON.parse(File.read(path)))
  when ".graphql", ".gql"
    GraphQL::Schema.from_definition(File.read(path))
  else
    raise ArgumentError, "unsupported schema format: #{path}"
  end
end