Merge pull request #7977 from blockscout/vb-graphql-extend-schema-with-new-fields-for-existing-objects

GraphQL: extend schema with new fields for existing objects
pull/8114/head
Victor Baranov 1 year ago committed by GitHub
commit e66997e048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 79
      apps/block_scout_web/lib/block_scout_web/schema/types.ex

@ -5,6 +5,7 @@
### Features ### Features
- [#6190](https://github.com/blockscout/blockscout/pull/6190) - Add EIP-1559 support to gas price oracle - [#6190](https://github.com/blockscout/blockscout/pull/6190) - Add EIP-1559 support to gas price oracle
- [#7977](https://github.com/blockscout/blockscout/pull/7977) - GraphQL: extend schema with new field for existing objects
### Fixes ### Fixes

@ -22,10 +22,14 @@ defmodule BlockScoutWeb.Schema.Types do
A stored representation of a Web3 address. A stored representation of a Web3 address.
""" """
object :address do object :address do
field(:hash, :address_hash)
field(:fetched_coin_balance, :wei) field(:fetched_coin_balance, :wei)
field(:fetched_coin_balance_block_number, :integer) field(:fetched_coin_balance_block_number, :integer)
field(:hash, :address_hash)
field(:contract_code, :data) field(:contract_code, :data)
field(:nonce, :integer)
field(:gas_used, :integer)
field(:transactions_count, :integer)
field(:token_transfers_count, :integer)
field :smart_contract, :smart_contract do field :smart_contract, :smart_contract do
resolve(dataloader(:db, :smart_contract)) resolve(dataloader(:db, :smart_contract))
@ -36,16 +40,7 @@ defmodule BlockScoutWeb.Schema.Types do
arg(:order, type: :sort_order, default_value: :desc) arg(:order, type: :sort_order, default_value: :desc)
resolve(&Transaction.get_by/3) resolve(&Transaction.get_by/3)
complexity(fn complexity(fn params, child_complexity -> process_complexity(params, child_complexity) end)
%{first: first}, child_complexity ->
first * child_complexity
%{last: last}, child_complexity ->
last * child_complexity
%{}, _child_complexity ->
0
end)
end end
end end
@ -55,18 +50,20 @@ defmodule BlockScoutWeb.Schema.Types do
structure that they form is called a "blockchain". structure that they form is called a "blockchain".
""" """
object :block do object :block do
field(:hash, :full_hash)
field(:consensus, :boolean) field(:consensus, :boolean)
field(:difficulty, :decimal) field(:difficulty, :decimal)
field(:gas_limit, :decimal) field(:gas_limit, :decimal)
field(:gas_used, :decimal) field(:gas_used, :decimal)
field(:hash, :full_hash)
field(:miner_hash, :address_hash)
field(:nonce, :nonce_hash) field(:nonce, :nonce_hash)
field(:number, :integer) field(:number, :integer)
field(:parent_hash, :full_hash)
field(:size, :integer) field(:size, :integer)
field(:timestamp, :datetime) field(:timestamp, :datetime)
field(:total_difficulty, :decimal) field(:total_difficulty, :decimal)
field(:miner_hash, :address_hash) field(:base_fee_per_gas, :wei)
field(:parent_hash, :full_hash) field(:is_empty, :boolean)
end end
@desc """ @desc """
@ -85,12 +82,14 @@ defmodule BlockScoutWeb.Schema.Types do
field(:trace_address, :json) field(:trace_address, :json)
field(:type, :type) field(:type, :type)
field(:value, :wei) field(:value, :wei)
field(:block_number, :integer)
field(:transaction_index, :integer)
field(:created_contract_address_hash, :address_hash) field(:created_contract_address_hash, :address_hash)
field(:from_address_hash, :address_hash) field(:from_address_hash, :address_hash)
field(:to_address_hash, :address_hash) field(:to_address_hash, :address_hash)
field(:transaction_hash, :full_hash) field(:transaction_hash, :full_hash)
field(:block_number, :integer)
field(:transaction_index, :integer)
field(:block_hash, :full_hash)
field(:block_index, :integer)
end end
@desc """ @desc """
@ -108,6 +107,19 @@ defmodule BlockScoutWeb.Schema.Types do
field(:contract_source_code, :string) field(:contract_source_code, :string)
field(:abi, :json) field(:abi, :json)
field(:address_hash, :address_hash) field(:address_hash, :address_hash)
field(:constructor_arguments, :string)
field(:optimization_runs, :integer)
field(:evm_version, :string)
field(:external_libraries, :json)
field(:verified_via_sourcify, :boolean)
field(:partially_verified, :boolean)
field(:file_path, :string)
field(:is_vyper_contract, :boolean)
field(:is_changed_bytecode, :boolean)
field(:implementation_name, :string)
field(:implementation_address_hash, :address_hash)
field(:compiler_settings, :json)
field(:verified_via_eth_bytecode_db, :boolean)
end end
@desc """ @desc """
@ -130,13 +142,12 @@ defmodule BlockScoutWeb.Schema.Types do
Models a Web3 transaction. Models a Web3 transaction.
""" """
node object(:transaction, id_fetcher: &transaction_id_fetcher/2) do node object(:transaction, id_fetcher: &transaction_id_fetcher/2) do
field(:hash, :full_hash)
field(:block_number, :integer)
field(:cumulative_gas_used, :decimal) field(:cumulative_gas_used, :decimal)
field(:error, :string) field(:error, :string)
field(:gas, :decimal) field(:gas, :decimal)
field(:gas_price, :wei) field(:gas_price, :wei)
field(:gas_used, :decimal) field(:gas_used, :decimal)
field(:hash, :full_hash)
field(:index, :integer) field(:index, :integer)
field(:input, :string) field(:input, :string)
field(:nonce, :nonce_hash) field(:nonce, :nonce_hash)
@ -145,24 +156,23 @@ defmodule BlockScoutWeb.Schema.Types do
field(:status, :status) field(:status, :status)
field(:v, :decimal) field(:v, :decimal)
field(:value, :wei) field(:value, :wei)
field(:block_hash, :full_hash)
field(:block_number, :integer)
field(:from_address_hash, :address_hash) field(:from_address_hash, :address_hash)
field(:to_address_hash, :address_hash) field(:to_address_hash, :address_hash)
field(:created_contract_address_hash, :address_hash) field(:created_contract_address_hash, :address_hash)
field(:earliest_processing_start, :datetime)
field(:revert_reason, :string)
field(:max_priority_fee_per_gas, :wei)
field(:max_fee_per_gas, :wei)
field(:type, :integer)
field(:has_error_in_internal_txs, :boolean)
connection field(:internal_transactions, node_type: :internal_transaction) do connection field(:internal_transactions, node_type: :internal_transaction) do
arg(:count, :integer) arg(:count, :integer)
resolve(&InternalTransaction.get_by/3) resolve(&InternalTransaction.get_by/3)
complexity(fn complexity(fn params, child_complexity -> process_complexity(params, child_complexity) end)
%{first: first}, child_complexity ->
first * child_complexity
%{last: last}, child_complexity ->
last * child_complexity
%{}, _child_complexity ->
0
end)
end end
end end
@ -175,4 +185,17 @@ defmodule BlockScoutWeb.Schema.Types do
def internal_transaction_id_fetcher(%{transaction_hash: transaction_hash, index: index}, _) do def internal_transaction_id_fetcher(%{transaction_hash: transaction_hash, index: index}, _) do
Jason.encode!(%{transaction_hash: to_string(transaction_hash), index: index}) Jason.encode!(%{transaction_hash: to_string(transaction_hash), index: index})
end end
defp process_complexity(params, child_complexity) do
case params do
%{first: first} ->
first * child_complexity
%{last: last} ->
last * child_complexity
%{} ->
0
end
end
end end

Loading…
Cancel
Save