antelopeql 2.0.0-rc.2 → 2.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/antelopeql.mjs +9 -32
  2. package/blockchain/deserialize_action_data.mjs +5 -1
  3. package/blockchain/get_abi.mjs +5 -5
  4. package/blockchain/get_account.mjs +5 -18
  5. package/blockchain/get_accounts_by_authorizers.mjs +17 -6
  6. package/blockchain/get_block.mjs +5 -5
  7. package/blockchain/get_currency_balance.mjs +6 -3
  8. package/blockchain/get_currency_stats.mjs +5 -5
  9. package/blockchain/get_info.mjs +5 -1
  10. package/blockchain/get_producers.mjs +6 -2
  11. package/blockchain/get_ram_price.mjs +6 -6
  12. package/blockchain/get_required_keys.mjs +84 -11
  13. package/blockchain/get_smart_contract.mjs +5 -5
  14. package/blockchain/get_table_by_scope.mjs +11 -2
  15. package/blockchain_query_field.mjs +10 -11
  16. package/build_graphql_fields_from_abis.mjs +20 -9
  17. package/eosio_abi_to_graphql_ast.mjs +31 -29
  18. package/eosio_types/name_type.mjs +1 -1
  19. package/eosio_types/public_key_type.mjs +19 -5
  20. package/eosio_types/signature_type.mjs +1 -3
  21. package/eosio_types/symbol_type.mjs +1 -0
  22. package/graphql_input_types/actions.mjs +2 -2
  23. package/graphql_input_types/configuration.mjs +0 -6
  24. package/graphql_object_types/packed_transaction.mjs +82 -16
  25. package/mutation_resolver.mjs +6 -8
  26. package/package.json +20 -20
  27. package/query_resolver.mjs +3 -1
  28. package/readme.md +35 -61
  29. package/{push_serialized_transaction.mjs → send_serialized_transaction.mjs} +7 -6
  30. package/{push_transaction.mjs → send_transaction.mjs} +12 -6
  31. package/{push_transaction_rpc.mjs → send_transaction_rpc.mjs} +2 -2
  32. package/{blockchain/serialize_abi.mjs → serialize_abi.mjs} +62 -73
  33. package/serialize_transaction.mjs +15 -3
  34. package/blockchain/bandwidth_quote.mjs +0 -244
package/antelopeql.mjs CHANGED
@@ -12,8 +12,8 @@ import blockchain_query_field from "./blockchain_query_field.mjs";
12
12
  import build_graphql_fields_from_abis from "./build_graphql_fields_from_abis.mjs";
13
13
  import get_abis from "./get_abis.mjs";
14
14
  import actions from "./graphql_input_types/actions.mjs";
15
- import push_serialized_transaction from "./push_serialized_transaction.mjs";
16
- import push_transaction from "./push_transaction.mjs";
15
+ import send_serialized_transaction from "./send_serialized_transaction.mjs";
16
+ import send_transaction from "./send_transaction.mjs";
17
17
  import serialize_transaction from "./serialize_transaction.mjs";
18
18
 
19
19
  /**
@@ -22,7 +22,6 @@ import serialize_transaction from "./serialize_transaction.mjs";
22
22
  * @property {String} rpc_url Chain remote proceedure call (RPC) Uniform Resource Locator (URL).
23
23
  * @property {*} [variableValues] GraphQL variables.
24
24
  * @property {String} [operationName] GraphQL operation name (query resolution).
25
- * @property {Function} [fetch] Custom fetch implementation.
26
25
  * @property {Array<String>} [contracts] List of Antelope smart contracts.
27
26
  * @property {async Function} [signTransaction] A function to sign the Antelope transaction.
28
27
  * @property {Headers} [headers] Headers to pass to the network request.
@@ -39,30 +38,12 @@ import serialize_transaction from "./serialize_transaction.mjs";
39
38
  * AntelopeQL for interacting with Antelope based blockchains.
40
39
  * @param {AntelopeQLArgument} Argument
41
40
  * @returns {AntelopeQLResult}
42
- * @example
43
- * ```js
44
- * import AntelopeQL from 'antelopeql/antelopeql.mjs'
45
- * import fetch from 'node-fetch'
46
- *
47
- * const query = `{ eosio_token { accounts(arg: { scope: "relockeblock" }){ balance } } }`
48
- *
49
- * AntelopeQL({
50
- * query,
51
- * contracts: ["eosio.token"],
52
- * fetch,
53
- * rpc_url: "https://eos.relocke.io",
54
- * headers: { "content-type": "application/json" }
55
- * }).then(console.log);
56
- * ```
57
- * > Logged output was "data": {"eosio_token": {"accounts": [{"balance": "100.0211 EOS"}]}}}
58
41
  */
59
-
60
42
  export default async function AntelopeQL({
61
43
  query,
62
44
  variableValues,
63
45
  operationName,
64
46
  signTransaction,
65
- fetch,
66
47
  contracts = [],
67
48
  ABIs = [],
68
49
  rpc_url,
@@ -70,9 +51,7 @@ export default async function AntelopeQL({
70
51
  signal
71
52
  }) {
72
53
  try {
73
- if (!fetch && !(typeof window == "undefined")) fetch = window.fetch;
74
- if (!fetch && typeof window == "undefined")
75
- throw new GraphQLError("No fetch implementation provided");
54
+ if (!fetch) throw new GraphQLError("No fetch implementation provided");
76
55
 
77
56
  const fetchOptions = {};
78
57
  if (headers) fetchOptions.headers = headers;
@@ -87,7 +66,7 @@ export default async function AntelopeQL({
87
66
  const queries = new GraphQLObjectType({
88
67
  name: "Query",
89
68
  description: "Query table data from Antelope blockchains.",
90
- fields: { blockchain: blockchain_query_field, ...query_fields }
69
+ fields: { get_blockchain: blockchain_query_field, ...query_fields }
91
70
  });
92
71
 
93
72
  let mutations;
@@ -96,19 +75,17 @@ export default async function AntelopeQL({
96
75
  const action_fields = actions(mutation_fields);
97
76
  mutations = new GraphQLObjectType({
98
77
  name: "Mutation",
99
- description: "Push transactions to the blockchain.",
100
78
  fields: {
101
- push_transaction: push_transaction(action_fields, ast_list),
79
+ send_transaction: send_transaction(action_fields, ast_list),
102
80
  serialize_transaction: serialize_transaction(action_fields, ast_list),
103
- push_serialized_transaction
81
+ send_serialized_transaction
104
82
  }
105
83
  });
106
84
  } else
107
85
  mutations = new GraphQLObjectType({
108
86
  name: "Mutation",
109
- description: "Push transactions to the blockchain.",
110
87
  fields: {
111
- push_serialized_transaction
88
+ send_serialized_transaction
112
89
  }
113
90
  });
114
91
 
@@ -125,10 +102,10 @@ export default async function AntelopeQL({
125
102
  schema,
126
103
  document,
127
104
  rootValue: "",
128
- contextValue: {
105
+ contextValue: () => ({
129
106
  network: { rpc_url, fetch, ...fetchOptions },
130
107
  signTransaction
131
- },
108
+ }),
132
109
  variableValues,
133
110
  operationName,
134
111
  fieldResolver(rootValue, args, ctx, { fieldName }) {
@@ -20,7 +20,11 @@ const deserialize_action_data = {
20
20
  type: new GraphQLNonNull(bytes_type)
21
21
  }
22
22
  },
23
- async resolve(_, args, { network: { fetch, rpc_url, ...fetchOptions } }) {
23
+ async resolve(root, args, getContext, info) {
24
+ const {
25
+ network: { fetch, rpc_url, ...fetchOptions }
26
+ } = getContext(root, args, info);
27
+
24
28
  const uri = `${rpc_url}/v1/chain/abi_bin_to_json`;
25
29
  const req = await fetch(uri, {
26
30
  method: "POST",
@@ -148,11 +148,11 @@ const get_abi = {
148
148
  type: new GraphQLNonNull(name_type)
149
149
  }
150
150
  },
151
- async resolve(
152
- _,
153
- { account_name },
154
- { network: { fetch, rpc_url, ...fetchOptions } }
155
- ) {
151
+ async resolve(root, { account_name }, getContext, info) {
152
+ const {
153
+ network: { fetch, rpc_url, ...fetchOptions }
154
+ } = getContext(root, { account_name }, info);
155
+
156
156
  const uri = `${rpc_url}/v1/chain/get_abi`;
157
157
  const req = await fetch(uri, {
158
158
  method: "POST",
@@ -54,19 +54,6 @@ const require_auth_type = new GraphQLObjectType({
54
54
  })
55
55
  })
56
56
  )
57
- },
58
- waits: {
59
- type: new GraphQLList(
60
- new GraphQLObjectType({
61
- name: "account_auth_waits_type",
62
- description:
63
- "specifies that a transaction will not be executed without a required delay",
64
- fields: () => ({
65
- wait_sec: { type: GraphQLInt },
66
- weight: { type: GraphQLInt }
67
- })
68
- })
69
- )
70
57
  }
71
58
  })
72
59
  });
@@ -207,11 +194,11 @@ const get_account = {
207
194
  type: new GraphQLNonNull(name_type)
208
195
  }
209
196
  },
210
- async resolve(
211
- _,
212
- { account_name },
213
- { network: { fetch, rpc_url, ...fetchOptions } }
214
- ) {
197
+ async resolve(root, { account_name }, getContext, info) {
198
+ const {
199
+ network: { fetch, rpc_url, ...fetchOptions }
200
+ } = getContext(root, { account_name }, info);
201
+
215
202
  const uri = `${rpc_url}/v1/chain/get_account`;
216
203
  const req = await fetch(uri, {
217
204
  method: "POST",
@@ -1,3 +1,5 @@
1
+ import legacy_from_public_key from "antelope-ecc/keys/legacy_from_public_key.mjs";
2
+ import public_key_from_wif from "antelope-ecc/keys/public_key_from_wif.mjs";
1
3
  import {
2
4
  GraphQLError,
3
5
  GraphQLList,
@@ -55,17 +57,26 @@ const accounts_by_authorizers = {
55
57
  type: new GraphQLList(new GraphQLNonNull(public_key_type))
56
58
  }
57
59
  },
58
- async resolve(
59
- _,
60
- { accounts = [], keys = [] },
61
- { network: { fetch, rpc_url, ...fetchOptions } }
62
- ) {
60
+ async resolve(root, { accounts = [], keys = [] }, getContext, info) {
61
+ const {
62
+ network: { fetch, rpc_url, symbol = "EOS", ...fetchOptions }
63
+ } = getContext(root, { accounts, keys }, info);
64
+
63
65
  const uri = `${rpc_url}/v1/chain/get_accounts_by_authorizers`;
66
+
67
+ const awaited_keys = await Promise.all(keys);
68
+
64
69
  const data = await fetch(uri, {
65
70
  method: "POST",
66
71
  ...fetchOptions,
67
72
  body: JSON.stringify({
68
- keys: await Promise.all(keys),
73
+ keys: await Promise.all(
74
+ awaited_keys.map((x) =>
75
+ x.startsWith("PUB_K1")
76
+ ? legacy_from_public_key(public_key_from_wif(x), symbol)
77
+ : x
78
+ )
79
+ ),
69
80
  accounts,
70
81
  json: true
71
82
  })
@@ -212,11 +212,11 @@ const get_block = {
212
212
  type: new GraphQLNonNull(GraphQLString)
213
213
  }
214
214
  },
215
- async resolve(
216
- _,
217
- { block_num_or_id },
218
- { network: { fetch, rpc_url, ...fetchOptions } }
219
- ) {
215
+ async resolve(root, { block_num_or_id }, getContext, info) {
216
+ const {
217
+ network: { fetch, rpc_url, ...fetchOptions }
218
+ } = getContext(root, { block_num_or_id }, info);
219
+
220
220
  const uri = `${rpc_url}/v1/chain/get_block`;
221
221
  const req = await fetch(uri, {
222
222
  method: "POST",
@@ -23,11 +23,14 @@ const currency_balance = {
23
23
  },
24
24
  symbol: {
25
25
  description: "The crytpo currency token symbol.",
26
- type: new GraphQLNonNull(symbol_code_type),
27
- defaultValue: "EOS"
26
+ type: new GraphQLNonNull(symbol_code_type)
28
27
  }
29
28
  },
30
- async resolve(_, args, { network: { fetch, rpc_url, ...fetchOptions } }) {
29
+ async resolve(root, args, getContext, info) {
30
+ const {
31
+ network: { fetch, rpc_url, ...fetchOptions }
32
+ } = getContext(root, args, info);
33
+
31
34
  const uri = `${rpc_url}/v1/chain/get_currency_balance`;
32
35
  const req = await fetch(uri, {
33
36
  method: "POST",
@@ -34,11 +34,11 @@ const get_currency_stats = {
34
34
  type: new GraphQLNonNull(symbol_code_type)
35
35
  }
36
36
  },
37
- async resolve(
38
- _,
39
- { symbol, ...args },
40
- { network: { fetch, rpc_url, ...fetchOptions } }
41
- ) {
37
+ async resolve(root, { symbol, ...args }, getContext, info) {
38
+ const {
39
+ network: { fetch, rpc_url, ...fetchOptions }
40
+ } = getContext(root, args, info);
41
+
42
42
  const uri = `${rpc_url}/v1/chain/get_currency_stats`;
43
43
  const req = await fetch(uri, {
44
44
  method: "POST",
@@ -78,7 +78,11 @@ const info = {
78
78
  description: "Return info about the operational state of the blockchain.",
79
79
  type: info_type,
80
80
  args: {},
81
- async resolve(_, __, { network: { fetch, rpc_url, ...fetchOptions } }) {
81
+ async resolve(root, args, getContext, info) {
82
+ const {
83
+ network: { fetch, rpc_url, ...fetchOptions }
84
+ } = getContext(root, args, info);
85
+
82
86
  const uri = `${rpc_url}/v1/chain/get_info`;
83
87
  const req = await fetch(uri, {
84
88
  method: "POST",
@@ -56,7 +56,7 @@ const producers = new GraphQLObjectType({
56
56
  });
57
57
 
58
58
  const get_producers = {
59
- description: "Return info about Antelope block producers.",
59
+ description: "Return info about block producers.",
60
60
  type: new GraphQLObjectType({
61
61
  name: "antelope_producers",
62
62
  fields: {
@@ -84,7 +84,11 @@ const get_producers = {
84
84
  type: GraphQLString
85
85
  }
86
86
  },
87
- async resolve(_, args, { network: { fetch, rpc_url, ...fetchOptions } }) {
87
+ async resolve(root, args, getContext, info) {
88
+ const {
89
+ network: { fetch, rpc_url, ...fetchOptions }
90
+ } = getContext(root, args, info);
91
+
88
92
  const uri = `${rpc_url}/v1/chain/get_producers`;
89
93
 
90
94
  const req = await fetch(uri, {
@@ -5,7 +5,7 @@ const RAM_quote_type = new GraphQLObjectType({
5
5
  fields: () => ({
6
6
  quote: {
7
7
  type: GraphQLString,
8
- resolve: (EOS) => EOS
8
+ resolve: (SYS) => SYS
9
9
  }
10
10
  })
11
11
  });
@@ -19,11 +19,11 @@ const get_ram_price = {
19
19
  description: "Number of bytes of RAM."
20
20
  }
21
21
  },
22
- async resolve(
23
- _,
24
- { quantity },
25
- { network: { fetch, rpc_url, ...fetchOptions } }
26
- ) {
22
+ async resolve(root, { quantity }, getContext, info) {
23
+ const {
24
+ network: { fetch, rpc_url, ...fetchOptions }
25
+ } = getContext(root, { quantity }, info);
26
+
27
27
  const data = await fetch(rpc_url + "/v1/chain/get_table_rows", {
28
28
  method: "POST",
29
29
  ...fetchOptions,
@@ -1,11 +1,84 @@
1
- // const { required_keys, ...errors } = await fetch(
2
- // `${rpc_url}/v1/chain/get_required_keys`,
3
- // {
4
- // method: "POST",
5
- // ...fetchOptions,
6
- // body: JSON.stringify({
7
- // available_keys,
8
- // transaction
9
- // })
10
- // }
11
- // ).then((res) => res.json());
1
+ import {
2
+ GraphQLError,
3
+ GraphQLInputObjectType,
4
+ GraphQLList,
5
+ GraphQLString
6
+ } from "graphql";
7
+
8
+ import bytes_type from "../eosio_types/bytes_type.mjs";
9
+ import name_type from "../eosio_types/name_type.mjs";
10
+ import public_key_type from "../eosio_types/public_key_type.mjs";
11
+ import authorization_type from "../graphql_input_types/authorization.mjs";
12
+
13
+ const action_type = new GraphQLInputObjectType({
14
+ name: "required_keys_action",
15
+ fields: {
16
+ account: {
17
+ type: name_type,
18
+ description: "The smart contract name"
19
+ },
20
+ name: { type: name_type },
21
+ authorization: { type: new GraphQLList(authorization_type) },
22
+ data: { type: GraphQLString },
23
+ hex_data: { type: bytes_type }
24
+ }
25
+ });
26
+
27
+ const transaction_type = new GraphQLInputObjectType({
28
+ name: "required_keys_transaction",
29
+ fields: {
30
+ expiration: { type: GraphQLString },
31
+ ref_block_num: { type: GraphQLString },
32
+ ref_block_prefix: { type: GraphQLString },
33
+ max_net_usage_words: { type: GraphQLString },
34
+ max_cpu_usage_ms: { type: GraphQLString },
35
+ actions: { type: new GraphQLList(action_type) },
36
+ context_free_actions: { type: GraphQLString }
37
+ }
38
+ });
39
+
40
+ const get_required_keys = {
41
+ description: "Retrieve a table from the blockchain.",
42
+ type: new GraphQLList(public_key_type),
43
+ args: {
44
+ transaction: {
45
+ type: transaction_type
46
+ },
47
+ available_keys: {
48
+ type: new GraphQLList(public_key_type)
49
+ }
50
+ },
51
+ async resolve(root, { available_keys, transaction }, getContext, info) {
52
+ const {
53
+ network: { fetch, rpc_url }
54
+ } = getContext(root, { available_keys, transaction }, info);
55
+
56
+ const uri = `${rpc_url}/v1/chain/get_required_keys`;
57
+
58
+ const { actions, ...txn } = transaction;
59
+
60
+ const data = await fetch(uri, {
61
+ method: "POST",
62
+ body: JSON.stringify({
63
+ available_keys: await Promise.all(available_keys),
64
+ transaction: {
65
+ ...txn,
66
+ actions: actions.map(({ data, ...object }) => ({
67
+ ...object,
68
+ ...(data ? { data: JSON.parse(data) } : {})
69
+ }))
70
+ }
71
+ })
72
+ });
73
+
74
+ const { required_keys, ...error } = await data.json();
75
+ if (error.error)
76
+ throw new GraphQLError(error.message, {
77
+ extensions: error.error
78
+ });
79
+
80
+ return required_keys;
81
+ }
82
+ };
83
+
84
+ export default get_required_keys;
@@ -30,11 +30,11 @@ const get_smart_contract = {
30
30
  type: new GraphQLNonNull(name_type)
31
31
  }
32
32
  },
33
- async resolve(
34
- _,
35
- { account_name },
36
- { network: { fetch, rpc_url, ...fetchOptions } }
37
- ) {
33
+ async resolve(root, { account_name }, getContext, info) {
34
+ const {
35
+ network: { fetch, rpc_url, ...fetchOptions }
36
+ } = getContext(root, { account_name }, info);
37
+
38
38
  const uri = `${rpc_url}/v1/chain/get_raw_code_and_abi`;
39
39
  const data = await fetch(uri, {
40
40
  method: "POST",
@@ -68,10 +68,19 @@ const get_table = {
68
68
  }
69
69
  },
70
70
  async resolve(
71
- _,
71
+ root,
72
72
  { account_name, table_name, limit, lower_bound, upper_bound },
73
- { network: { fetch, rpc_url, ...fetchOptions } }
73
+ getContext,
74
+ info
74
75
  ) {
76
+ const {
77
+ network: { fetch, rpc_url, ...fetchOptions }
78
+ } = getContext(
79
+ root,
80
+ { account_name, table_name, limit, lower_bound, upper_bound },
81
+ info
82
+ );
83
+
75
84
  const uri = `${rpc_url}/v1/chain/get_table_by_scope`;
76
85
  const data = await fetch(uri, {
77
86
  method: "POST",
@@ -1,6 +1,5 @@
1
1
  import { GraphQLError, GraphQLObjectType } from "graphql";
2
2
 
3
- import eos_bandwidth_price from "./blockchain/bandwidth_quote.mjs";
4
3
  import deserialize_action_data from "./blockchain/deserialize_action_data.mjs";
5
4
  import get_abi from "./blockchain/get_abi.mjs";
6
5
  import get_account from "./blockchain/get_account.mjs";
@@ -11,9 +10,9 @@ import get_currency_stats from "./blockchain/get_currency_stats.mjs";
11
10
  import get_info from "./blockchain/get_info.mjs";
12
11
  import get_producers from "./blockchain/get_producers.mjs";
13
12
  import get_ram_price from "./blockchain/get_ram_price.mjs";
13
+ import get_required_keys from "./blockchain/get_required_keys.mjs";
14
14
  import get_smart_contract from "./blockchain/get_smart_contract.mjs";
15
15
  import get_table from "./blockchain/get_table_by_scope.mjs";
16
- import serialize_abi from "./blockchain/serialize_abi.mjs";
17
16
 
18
17
  const blockchain_query_field = {
19
18
  type: new GraphQLObjectType({
@@ -24,25 +23,25 @@ const blockchain_query_field = {
24
23
  get_abi,
25
24
  get_accounts_by_authorizers,
26
25
  get_block,
27
- get_smart_contract,
28
26
  get_currency_balance,
29
27
  get_currency_stats,
28
+ get_required_keys,
29
+ get_smart_contract,
30
30
  get_info,
31
31
  get_producers,
32
- deserialize_action_data,
33
32
  get_table,
34
33
  get_ram_price,
35
- eos_bandwidth_price,
36
- serialize_abi
34
+ deserialize_action_data
37
35
  }
38
36
  }),
39
- resolve(_, __, { network: { fetch, rpc_url } }) {
40
- if (!fetch)
41
- throw new GraphQLError(
42
- "Fetch was not supplied to the `antelopeql_context`."
43
- );
37
+ resolve(root, arg, getContext, info) {
38
+ const {
39
+ network: { rpc_url }
40
+ } = getContext(root, arg, info);
41
+
44
42
  if (!rpc_url)
45
43
  throw new GraphQLError("No RPC url supplied to `antelopeql_context`");
44
+
46
45
  return {};
47
46
  }
48
47
  };
@@ -21,12 +21,13 @@ import {
21
21
  /**
22
22
  * Builds GraphQL query and mutation fields from a list of ABIs. These GraphQL fields can readily be consumed by a GraphQL Schema, enabling developers the ability to integrate a varienty of EOSIO based blockchains into their GraphQL service.
23
23
  * @param {Array<AccountABI>} abi_list Argument.
24
+ * @param {String} [typeResolution] Used for GraphQL type resolution.
24
25
  * @returns {Object} AntelopeQL fields.
25
26
  * @example <caption>`Usage` in a custom GraphQL API.</caption>
26
27
  * ```js
27
28
  * import actions_type from 'antelopeql/graphql_input_types/actions.js'
28
29
  * import serialize_transaction from 'antelopeql/graphql_input_types/actions.js'
29
- * import push_transaction from 'antelopeql/push_transaction.js'
30
+ * import send_transaction from 'antelopeql/send_transaction.js'
30
31
  *
31
32
  * const network = { fetch, rpc_url: 'https://eos.relocke.io', headers: {}, signal }
32
33
  * const ABI_list = [{ account_name: 'eosio.token', abi: … }]
@@ -45,9 +46,9 @@ import {
45
46
  * const mutations = new GraphQLObjectType({
46
47
  * name: 'Mutation',
47
48
  * fields: {
48
- * push_transaction: push_transaction(action_fields, ast_list),
49
+ * send_transaction: send_transaction(action_fields, ast_list),
49
50
  * serialize_transaction: serialize_transaction(action_fields, ast_list),
50
- * push_serialized_transaction
51
+ * send_serialized_transaction
51
52
  * }
52
53
  * })
53
54
  *
@@ -62,14 +63,17 @@ import {
62
63
  * schema,
63
64
  * document,
64
65
  * rootValue: '',
65
- * contextValue: { network },
66
+ * contextValue: () => ({ network }),
66
67
  * fieldResolver(rootValue, args, ctx, { fieldName }) {
67
68
  * return rootValue[fieldName]
68
69
  * }
69
70
  * })
70
71
  * ```
71
72
  */
72
- export default function build_graphql_fields_from_abis(abi_list) {
73
+ export default function build_graphql_fields_from_abis(
74
+ abi_list,
75
+ typeResolution = ""
76
+ ) {
73
77
  const contract_query_fields = {};
74
78
  const contract_mutation_fields = {};
75
79
  const ast_list = {};
@@ -79,20 +83,27 @@ export default function build_graphql_fields_from_abis(abi_list) {
79
83
  const AST = eosio_abi_to_graphql_ast(abi);
80
84
 
81
85
  ast_list[name] = AST; // For use in serializing data in mutation resolver.
86
+
82
87
  const { query_fields, mutation_fields } = get_graphql_fields_from_AST(
83
88
  AST,
84
89
  abi,
85
- name
90
+ name,
91
+ typeResolution
86
92
  );
87
93
 
88
94
  if (Object.keys(query_fields).length)
89
95
  contract_query_fields[name] = {
90
96
  name,
91
97
  type: new GraphQLObjectType({
92
- name: name + "_query",
98
+ name: `${name}_query${typeResolution}`,
93
99
  fields: query_fields
94
100
  }),
95
- resolve(__, _, { network: { rpc_url, fetch } = {} }, { fieldName }) {
101
+ resolve(root, arg, getContext, { fieldName, ...info }) {
102
+ const { network: { rpc_url, fetch } = {} } = getContext(root, arg, {
103
+ fieldName,
104
+ ...info
105
+ });
106
+
96
107
  if (!fetch)
97
108
  throw new GraphQLError(
98
109
  "No fetch argument found on the context of the GraphQL.execute."
@@ -110,7 +121,7 @@ export default function build_graphql_fields_from_abis(abi_list) {
110
121
  if (Object.keys(mutation_fields).length)
111
122
  contract_mutation_fields[name] = {
112
123
  type: new GraphQLInputObjectType({
113
- name,
124
+ name: name + typeResolution,
114
125
  fields: mutation_fields
115
126
  })
116
127
  };