Class: GraphqlUtil::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_util/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(http, path:) ⇒ Schema

Initialize the GraphqlUtil::Schema to generate or retrieve the GraphQL Schema dump

Parameters:

  • http (GraphqlUtil::Http)

    HTTP Client instance

  • path (String)

    Path to the client Class



13
14
15
16
# File 'lib/graphql_util/schema.rb', line 13

def initialize(http, path:)
  @http = http
  @path = path
end

Instance Method Details

#load_schemaClass

Loads the GraphQL Endpoint Introspection Schema from a dumped file if present, or dumps itself if needed

Returns:

  • (Class)

    GraphQL Schema



23
24
25
26
27
28
29
30
31
# File 'lib/graphql_util/schema.rb', line 23

def load_schema
  if !File.exist?(@path)
    schema_dir = File.dirname(@path)
    FileUtils.mkdir_p(schema_dir) unless File.directory?(schema_dir)
    GraphQL::Client.dump_schema(@http, @path)
  end

  GraphQL::Client.load_schema(@path)
end