Sha256: 6801041384e298de72dece04e0540f253749c14a2abcc6bdda49073cc3310a18
Contents?: true
Size: 1.7 KB
Versions: 7
Compression:
Stored size: 1.7 KB
Contents
# typed: strict # frozen_string_literal: true module ShopifyAPI module Utils module GraphqlProxy class << self extend T::Sig sig do params( headers: T::Hash[String, T.untyped], body: String, cookies: T.nilable(T::Hash[String, String]), tries: Integer, ).returns(Clients::HttpResponse) end def proxy_query(headers:, body:, cookies: nil, tries: 1) raise Errors::PrivateAppError, "GraphQL proxing is unsupported for private apps." if Context.private? normalized_headers = HttpUtils.normalize_headers(headers) session = Utils::SessionUtils.load_current_session( auth_header: normalized_headers["authorization"], cookies: cookies, is_online: true, ) if session.nil? || !session.online? raise Errors::SessionNotFoundError, "Failed to load an online session from the provided parameters." end client = Clients::Graphql::Admin.new(session: session) case normalized_headers["content-type"] when "application/graphql" return client.query(query: body, tries: tries) when "application/json" parsed_body = JSON.parse(body) query = parsed_body["query"] raise Errors::InvalidGraphqlRequestError, "Request missing 'query' field in GraphQL proxy request." if query.nil? return client.query(query: query, variables: parsed_body["variables"], tries: tries) end raise Errors::InvalidGraphqlRequestError, "Unsupported Content-Type #{normalized_headers["content-type"]}." end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems