Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/dev_query_graphql.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%%% @doc A GraphQL interface for querying a node's cache. Accessible through the
%%% `[email protected]/graphql' device key.
%%% @doc A GraphQL interface for querying a node's cache.
%%% It is accessible through the `[email protected]/graphql' device key and uses the
%%% schema defined at scripts/schema.gql
%%%
-module(dev_query_graphql).
%%% AO-Core API:
-export([handle/3]).
Expand Down
35 changes: 21 additions & 14 deletions src/hb_gateway_client.erl
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
%%% @doc Implementation of Arweave's GraphQL API to gain access to specific
%%% items of data stored on the network.
%%%
%%%
%%% This module must be used to get full HyperBEAM `[email protected]' form messages
%%% from data items stored on the network, as Arweave gateways do not presently
%%% expose all necessary fields to retrieve this information outside of the
%%% GraphQL API. When gateways integrate serving in `[email protected]' form, this
%%% module will be deprecated.
-module(hb_gateway_client).
%% Raw access primitives:
-export([query/2, query/3, query/4, query/5]).
-export([read/2, data/2, result_to_message/2, item_spec/0]).
%% Application-specific data access functions:
-export([scheduler_location/2]).
-include_lib("include/hb.hrl").
-include_lib("eunit/include/eunit.hrl").

%% @doc Get a data item (including data and tags) by its ID, using the node's
%% GraphQL peers.
%% It uses the following GraphQL schema:
%%%
%%% It uses the following GraphQL schema:
%% type Transaction {
%% id: ID!
%% anchor: String!
Expand All @@ -33,6 +23,23 @@
%% winston: String!
%% ar: String!
%% }
%% type MetaData {
%% size: String!
%% type: String
%% }
%% For more please check scripts/schema.gql
%%%
-module(hb_gateway_client).
%% Raw access primitives:
-export([query/2, query/3, query/4, query/5]).
-export([read/2, data/2, result_to_message/2, item_spec/0]).
%% Application-specific data access functions:
-export([scheduler_location/2]).
-include_lib("include/hb.hrl").
-include_lib("eunit/include/eunit.hrl").

%% @doc Get a data item (including data and tags) by its ID, using the node's
%% GraphQL peers.
read(ID, Opts) ->
{Query, Variables} = case maps:is_key(<<"subindex">>, Opts) of
true ->
Expand Down Expand Up @@ -241,7 +248,7 @@ result_to_message(ExpectedID, Item, Opts) ->
% We have the headers, so we can get the data.
Data =
case hb_maps:get(<<"data">>, Item, not_found, GQLOpts) of
#{ <<"size">> := Zero } when Zero =:= <<"0">> orelse Zero =:= 0 -> <<>>;
#{ <<"size">> := <<"0">>} -> <<>>;
BinData when is_binary(BinData) -> BinData;
_ ->
{ok, Bytes} = data(ExpectedID, Opts),
Expand Down