19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/shopify_api/utils/graphql_proxy.rb', line 19
def proxy_query(session:, headers:, body:, cookies: nil, tries: 1)
raise Errors::PrivateAppError, "GraphQL proxing is unsupported for private apps." if Context.private?
= HttpUtils.()
unless session.online?
raise Errors::SessionNotFoundError,
"Failed to load an online session from the provided parameters."
end
client = Clients::Graphql::Admin.new(session: session)
case ["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 #{["content-type"]}."
end
|