Module: FragmentGraphQl

Extended by:
T::Sig
Defined in:
lib/fragment_client.rb

Overview

A support module for the client

Defined Under Namespace

Classes: CustomClient

Constant Summary collapse

VERSION =
FragmentSDK::VERSION
CustomHTTP =
Class.new(GraphQL::Client::HTTP) do
  extend T::Sig
  sig { params(context: T.untyped).returns(T::Hash[T.untyped, T.untyped]) }
  def headers(context)
    { 'Authorization' => format('Bearer %s', context[:access_token]),
      'X-Fragment-Client' => format('ruby-client@%s', FragmentGraphQl::VERSION) }
  end
end
HTTP =
T.let(CustomHTTP.new('https://api.fragment.dev/graphql'), GraphQL::Client::HTTP)
FragmentSchema =
T.let(GraphQL::Client.load_schema("#{__dir__}/fragment.schema.json"), T.untyped)
Client =

Use our custom client instead of the base GraphQL::Client

T.let(CustomClient.new(schema: FragmentSchema, execute: HTTP), CustomClient)
FragmentQueries =
T.let(parse_queries("#{__dir__}/queries.graphql"), T.untyped)

Class Method Summary collapse

Class Method Details

.parse_queries(filename) ⇒ Object



66
67
68
69
# File 'lib/fragment_client.rb', line 66

def self.parse_queries(filename)
  file_text = File.read(filename)
  Client.parse(file_text)
end