diff --git a/gqlgen.yml b/gqlgen.yml index 1bf62a60..af53e13f 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -5,8 +5,8 @@ schema: # Where should the generated server code go? exec: - filename: serve/graph/generated/generated.go - package: generated + filename: serve/graph/generated.go + package: graph # Where should any generated models go? model: @@ -16,8 +16,8 @@ model: # Where should the resolver implementations go? resolver: layout: follow-schema - dir: serve/graph/resolvers - package: resolvers + dir: serve/graph + package: graph filename_template: "{name}.resolvers.go" # Optional: turn on to not generate template comments above resolvers # omit_template_comment: false diff --git a/serve/graph/resolvers/block.resolvers.go b/serve/graph/block.resolvers.go similarity index 97% rename from serve/graph/resolvers/block.resolvers.go rename to serve/graph/block.resolvers.go index 562ce1ea..e1237921 100644 --- a/serve/graph/resolvers/block.resolvers.go +++ b/serve/graph/block.resolvers.go @@ -1,4 +1,4 @@ -package resolvers +package graph import ( "time" diff --git a/serve/graph/generated/generated.go b/serve/graph/generated.go similarity index 93% rename from serve/graph/generated/generated.go rename to serve/graph/generated.go index 2a654fda..e11c50fc 100644 --- a/serve/graph/generated/generated.go +++ b/serve/graph/generated.go @@ -1,10 +1,11 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package generated +package graph import ( "bytes" "context" + "embed" "errors" "fmt" "io" @@ -587,566 +588,25 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er return introspection.WrapTypeFromDef(ec.Schema(), ec.Schema().Types[name]), nil } +//go:embed "schema/query.graphql" "schema/schema.graphql" "schema/subscription.graphql" "schema/filter/block_filter.graphql" "schema/filter/transaction_filter.graphql" "schema/types/block.graphql" "schema/types/transaction.graphql" +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not available", filename)) + } + return string(data) +} + var sources = []*ast.Source{ - {Name: "../schema/query.graphql", Input: `""" -Root Query type to fetch data about Blocks and Transactions based on filters or retrieve the latest block height. -""" -type Query { - """ - Retrieves a list of Transactions that match the given filter criteria. If the result is incomplete due to errors, both partial results and errors are returned. - """ - transactions(filter: TransactionFilter!): [Transaction!] - - """ - Fetches Blocks matching the specified filter criteria. Incomplete results due to errors return both the partial Blocks and the associated errors. - """ - blocks(filter: BlockFilter!): [Block!] - - """ - Returns the height of the most recently processed Block by the blockchain indexer, indicating the current length of the blockchain. - """ - latestBlockHeight: Int! -} -`, BuiltIn: false}, - {Name: "../schema/schema.graphql", Input: `schema { - query: Query - subscription: Subscription -} - -""" -Field representing a point on time. It is following the RFC3339Nano format ("2006-01-02T15:04:05.999999999Z07:00") -""" -scalar Time -`, BuiltIn: false}, - {Name: "../schema/subscription.graphql", Input: `""" -Subscriptions provide a way for clients to receive real-time updates about Transactions and Blocks based on specified filter criteria. -Subscribers will only receive updates for events occurring after the subscription is established. -""" -type Subscription { - """ - Subscribes to real-time updates of Transactions that match the provided filter criteria. - This subscription starts immediately and only includes Transactions added to the blockchain after the subscription is active. - - This is useful for applications needing to track Transactions in real-time, such as wallets tracking incoming transactions - or analytics platforms monitoring blockchain activity. - - Returns: - - Transaction: Each received update is a Transaction object that matches the filter criteria. - """ - transactions(filter: TransactionFilter!): Transaction! - - """ - Subscribes to real-time updates of Blocks that match the provided filter criteria. Similar to the Transactions subscription, - this subscription is active immediately upon creation and only includes Blocks added after the subscription begins. - - This subscription is ideal for services that need to be notified of new Blocks for processing or analysis, such as block explorers, - data aggregators, or security monitoring tools. - - Returns: - - Block: Each update consists of a Block object that satisfies the filter criteria, allowing subscribers to process or analyze new Blocks in real time. - """ - blocks(filter: BlockFilter!): Block! -} -`, BuiltIn: false}, - {Name: "../schema/filter/block_filter.graphql", Input: `""" -Filters for querying Blocks within specified criteria related to their attributes. -""" -input BlockFilter { - """ - Minimum block height from which to start fetching Blocks, inclusive. If unspecified, there is no lower bound. - """ - from_height: Int - - """ - Maximum block height up to which Blocks should be fetched, exclusive. If unspecified, there is no upper bound. - """ - to_height: Int - - """ - Minimum timestamp from which to start fetching Blocks, inclusive. Blocks created at or after this time will be included. - """ - from_time: Time - - """ - Maximum timestamp up to which to fetch Blocks, exclusive. Only Blocks created before this time are included. - """ - to_time: Time -} -`, BuiltIn: false}, - {Name: "../schema/filter/transaction_filter.graphql", Input: `""" -Filters for querying Transactions within specified criteria related to their execution and placement within Blocks. -""" -input TransactionFilter { - """ - Minimum block height from which to start fetching Transactions, inclusive. Aids in scoping the search to recent Transactions. - """ - from_block_height: Int - - """ - Maximum block height up to which Transactions should be fetched, exclusive. Helps in limiting the search to older Transactions. - """ - to_block_height: Int - - """ - Minimum Transaction index from which to start fetching, inclusive. Facilitates ordering in Transaction queries. - """ - from_index: Int - - """ - Maximum Transaction index up to which to fetch, exclusive. Ensures a limit on the ordering range for Transaction queries. - """ - to_index: Int - - """ - Minimum ` + "`" + `gas_wanted` + "`" + ` value to filter Transactions by, inclusive. Filters Transactions based on the minimum computational effort declared. - """ - from_gas_wanted: Int - - """ - Maximum ` + "`" + `gas_wanted` + "`" + ` value for filtering Transactions, exclusive. Limits Transactions based on the declared computational effort. - """ - to_gas_wanted: Int - - """ - Minimum ` + "`" + `gas_used` + "`" + ` value to filter Transactions by, inclusive. Selects Transactions based on the minimum computational effort actually used. - """ - from_gas_used: Int - - """ - Maximum ` + "`" + `gas_used` + "`" + ` value for filtering Transactions, exclusive. Refines selection based on the computational effort actually consumed. - """ - to_gas_used: Int - - """ - Hash from Transaction content in base64 encoding. If this filter is used, any other filter will be ignored. - """ - hash: String - - """ - Transaction's message to filter Transactions. - """ - message: TransactionMessageInput - - """ - ` + "`" + `memo` + "`" + ` value to filter Transaction's memo. - """ - memo: String -} - -""" -Input for filters by transaction message. -""" -input TransactionMessageInput { - """ - The type of transaction message. - """ - type_url: MessageType - - """ - The route of transaction message. - """ - route: MessageRoute - - """ - ` + "`" + `TransactionBankMessageInput` + "`" + ` represents input parameters required when the message router is ` + "`" + `bank` + "`" + `. - """ - bank_param: TransactionBankMessageInput - - """ - ` + "`" + `TransactionVmMessageInput` + "`" + ` represents input parameters required when the message router is ` + "`" + `vm` + "`" + `. - """ - vm_param: TransactionVmMessageInput -} - -""" -` + "`" + `TransactionBankMessageInput` + "`" + ` represents input parameters required when the message router is ` + "`" + `bank` + "`" + `. -""" -input TransactionBankMessageInput { - """ - send represents input parameters required when the message type is ` + "`" + `send` + "`" + `. - """ - send: BankMsgSendInput -} - -""" -` + "`" + `BankMsgSendInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `send` + "`" + `. -""" -input BankMsgSendInput { - """ - the bech32 address of the fund sender. - """ - from_address: String - - """ - the bech32 address of the fund receiver. - """ - to_address: String - - """ - the denomination and amount of fund sent (""). - """ - amount: String -} - -""" -` + "`" + `TransactionVmMessageInput` + "`" + ` represents input parameters required when the message router is ` + "`" + `vm` + "`" + `. -""" -input TransactionVmMessageInput { - """ - ` + "`" + `MsgCallInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `exec` + "`" + `. - """ - m_call: MsgCallInput - - """ - ` + "`" + `MsgAddPackageInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `add_package` + "`" + `. - """ - m_addpkg: MsgAddPackageInput - - """ - ` + "`" + `MsgRunInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `run` + "`" + `. - """ - m_run: MsgRunInput -} - -""" -` + "`" + `MsgCallInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `exec` + "`" + `. -""" -input MsgCallInput { - """ - the bech32 address of the caller. - """ - caller: String - - """ - the amount of funds to be deposited to the package, if any (""). - """ - send: String - - """ - the gno package path. - """ - pkg_path: String - - """ - the function name being invoked. - """ - func: String - - """ - ` + "`" + `args` + "`" + ` are the arguments passed to the executed function. - Arguments are checked in the order of the argument array, and arguments that are not checked are left blank. - """ - args: [String!] -} - -""" -` + "`" + `MsgAddPackageInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `add_package` + "`" + `. -""" -input MsgAddPackageInput { - """ - the package deployer. - """ - creator: String - - """ - the package being deployed. - """ - package: MemPackageInput - - """ - the amount of funds to be deposited at deployment, if any (""). - """ - deposit: String -} - -""" -` + "`" + `MsgRunInput` + "`" + ` represents input parameters required when the message type is ` + "`" + `run` + "`" + `. -""" -input MsgRunInput { - """ - the bech32 address of the caller. - """ - caller: String - - """ - the amount of funds to be deposited to the package, if any (""). - """ - send: String - - """ - the package being executed. - """ - package: MemPackageInput -} - -""" -` + "`" + `MemPackageInput` + "`" + ` represents a package stored in memory. -""" -input MemPackageInput { - """ - the name of the package. - """ - Name: String - - """ - the gno path of the package. - """ - Path: String - - """ - the associated package gno source. - """ - Files: [MemFileInput] -} - -""" -` + "`" + `MemFileInput` + "`" + ` is the metadata information tied to a single gno package / realm file. -""" -input MemFileInput { - """ - the name of the source file. - """ - Name: String - - """ - the content of the source file. - """ - Body: String -} -`, BuiltIn: false}, - {Name: "../schema/types/block.graphql", Input: `""" -Represents a blockchain block with various attributes detailing its creation and content. -""" -type Block { - """ - A unique identifier for the Block determined by its position in the blockchain. - This integer is strictly increasing with each new Block. - """ - height: Int! - - """ - The software version of the node that created this Block, indicating the specific - implementation and versioning of the blockchain protocol used. - """ - version: String! - - """ - An identifier for the specific blockchain network this Block belongs to. Helps in - distinguishing between different networks like mainnet, testnet, etc. - """ - chain_id: String! - - """ - The timestamp at which this Block was proposed and finalized in the blockchain. Represented in UTC. - """ - time: Time! - - """ - Encoded data representing the blockchain address of the proposer who submitted this Block. - It is raw and requires decoding to be human-readable. - """ - proposer_address_raw: String! -} -`, BuiltIn: false}, - {Name: "../schema/types/transaction.graphql", Input: `""" -Defines a transaction within a block, detailing its execution specifics and content. -""" -type Transaction { - """ - A sequential index representing the order of this Transaction within its Block. Unique within the context of its Block. - """ - index: Int! - - """ - Hash from Transaction content in base64 encoding. - """ - hash: String! - - """ - The height of the Block in which this Transaction is included. Links the Transaction to its containing Block. - """ - block_height: Int! - - """ - The declared amount of computational effort the sender is willing to pay for executing this Transaction. - """ - gas_wanted: Int! - - """ - The actual amount of computational effort consumed to execute this Transaction. It could be less or equal to ` + "`" + `gas_wanted` + "`" + `. - """ - gas_used: Int! - - """ - The payload of the Transaction in a raw format, typically containing the instructions and any data necessary for execution. - """ - content_raw: String! - - """ - The payload of the Transaction in a raw format, typically containing the instructions and any data necessary for execution. - """ - messages: [TransactionMessage]! - - """ - The memo of the Transaction. - """ - memo: String! -} - -enum MessageRoute { - vm - bank -} - -enum MessageType { - send - exec - add_package - run -} - -type TransactionMessage { - """ - The type of transaction message. - """ - typeUrl: MessageType! - - """ - The route of transaction message. - """ - route: MessageRoute! - - """ - MessageValue is the content of the transaction. - The content can be of type ` + "`" + `BankMsgSend` + "`" + ` or ` + "`" + `MsgCall` + "`" + ` or ` + "`" + `MsgAddPackage` + "`" + ` or ` + "`" + `MsgRun` + "`" + `. - """ - value: MessageValue! -} - -union MessageValue = BankMsgSend | MsgCall | MsgAddPackage | MsgRun - -""" -` + "`" + `BankMsgSend` + "`" + ` is a message with a message router of ` + "`" + `bank` + "`" + ` and a message type of ` + "`" + `send` + "`" + `. -` + "`" + `BankMsgSend` + "`" + ` is the fund transfer tx message. -""" -type BankMsgSend { - """ - the bech32 address of the fund sender. - """ - from_address: String! - - """ - the bech32 address of the fund receiver. - """ - to_address: String! - - """ - the denomination and amount of fund sent (""). - """ - amount: String! -} - -""" -` + "`" + `MsgCall` + "`" + ` is a message with a message router of ` + "`" + `vm` + "`" + ` and a message type of ` + "`" + `exec` + "`" + `. -` + "`" + `MsgCall` + "`" + ` is the method invocation tx message. -""" -type MsgCall { - caller: String! - send: String! - pkg_path: String! - func: String! - args: [String!] -} - -""" -` + "`" + `MsgAddPackage` + "`" + ` is a message with a message router of ` + "`" + `vm` + "`" + ` and a message type of ` + "`" + `add_package` + "`" + `. -` + "`" + `MsgAddPackage` + "`" + ` is the package deployment tx message. -""" -type MsgAddPackage { - """ - the package deployer. - """ - creator: String! - - """ - the package being deployed. - """ - package: MemPackage! - - """ - the amount of funds to be deposited at deployment, if any (""). - """ - deposit: String! -} - -""" -` + "`" + `MsgRun` + "`" + ` is a message with a message router of ` + "`" + `vm` + "`" + ` and a message type of ` + "`" + `run` + "`" + `. -` + "`" + `MsgRun is the execute arbitrary Gno code tx message` + "`" + `. -""" -type MsgRun { - """ - the bech32 address of the caller. - """ - caller: String! - - """ - the amount of funds to be deposited to the package, if any (""). - """ - send: String! - - """ - the package being executed. - """ - package: MemPackage! -} - -""" -` + "`" + `MemPackage` + "`" + ` is the metadata information tied to package / realm deployment. -""" -type MemPackage { - """ - the name of the package. - """ - Name: String! - - """ - the gno path of the package. - """ - Path: String! - - """ - the associated package gno source. - """ - Files: [MemFile!] -} - -""" -` + "`" + `MemFile` + "`" + ` is the metadata information tied to a single gno package / realm file -""" -type MemFile { - """ - the name of the source file. - """ - Name: String! - - """ - the content of the source file. - """ - Body: String! -} - -type TxFee { - """ - gas limit - """ - gas_wanted: Int! - - """ - gas fee details () - """ - gas_fee: Int! -} -`, BuiltIn: false}, + {Name: "schema/query.graphql", Input: sourceData("schema/query.graphql"), BuiltIn: false}, + {Name: "schema/schema.graphql", Input: sourceData("schema/schema.graphql"), BuiltIn: false}, + {Name: "schema/subscription.graphql", Input: sourceData("schema/subscription.graphql"), BuiltIn: false}, + {Name: "schema/filter/block_filter.graphql", Input: sourceData("schema/filter/block_filter.graphql"), BuiltIn: false}, + {Name: "schema/filter/transaction_filter.graphql", Input: sourceData("schema/filter/transaction_filter.graphql"), BuiltIn: false}, + {Name: "schema/types/block.graphql", Input: sourceData("schema/types/block.graphql"), BuiltIn: false}, + {Name: "schema/types/transaction.graphql", Input: sourceData("schema/types/transaction.graphql"), BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) diff --git a/serve/graph/resolvers/query.resolvers.go b/serve/graph/query.resolvers.go similarity index 95% rename from serve/graph/resolvers/query.resolvers.go rename to serve/graph/query.resolvers.go index 3a490964..596c3a20 100644 --- a/serve/graph/resolvers/query.resolvers.go +++ b/serve/graph/query.resolvers.go @@ -1,4 +1,4 @@ -package resolvers +package graph // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. @@ -8,7 +8,6 @@ import ( "context" "github.com/99designs/gqlgen/graphql" - "github.com/gnolang/tx-indexer/serve/graph/generated" "github.com/gnolang/tx-indexer/serve/graph/model" "github.com/vektah/gqlparser/v2/gqlerror" ) @@ -124,6 +123,6 @@ func (r *queryResolver) LatestBlockHeight(ctx context.Context) (int, error) { } // Query returns generated.QueryResolver implementation. -func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } +func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } type queryResolver struct{ *Resolver } diff --git a/serve/graph/resolvers/resolver.go b/serve/graph/resolver.go similarity index 98% rename from serve/graph/resolvers/resolver.go rename to serve/graph/resolver.go index 56dc91c5..8241fc3b 100644 --- a/serve/graph/resolvers/resolver.go +++ b/serve/graph/resolver.go @@ -1,6 +1,6 @@ //go:generate go run github.com/99designs/gqlgen generate -package resolvers +package graph import ( "context" diff --git a/serve/graph/setup.go b/serve/graph/setup.go index 79307442..682155e6 100644 --- a/serve/graph/setup.go +++ b/serve/graph/setup.go @@ -5,15 +5,13 @@ import ( "github.com/99designs/gqlgen/graphql/handler/transport" "github.com/99designs/gqlgen/graphql/playground" "github.com/gnolang/tx-indexer/events" - "github.com/gnolang/tx-indexer/serve/graph/generated" - "github.com/gnolang/tx-indexer/serve/graph/resolvers" "github.com/gnolang/tx-indexer/storage" "github.com/go-chi/chi/v5" ) func Setup(s storage.Storage, manager *events.Manager, m *chi.Mux) *chi.Mux { - srv := handler.NewDefaultServer(generated.NewExecutableSchema( - generated.Config{Resolvers: resolvers.NewResolver(s, manager)}, + srv := handler.NewDefaultServer(NewExecutableSchema( + Config{Resolvers: NewResolver(s, manager)}, )) srv.AddTransport(&transport.Websocket{}) diff --git a/serve/graph/resolvers/subscription.resolvers.go b/serve/graph/subscription.resolvers.go similarity index 88% rename from serve/graph/resolvers/subscription.resolvers.go rename to serve/graph/subscription.resolvers.go index 2505a1f0..8ab88473 100644 --- a/serve/graph/resolvers/subscription.resolvers.go +++ b/serve/graph/subscription.resolvers.go @@ -1,4 +1,4 @@ -package resolvers +package graph // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. @@ -7,7 +7,6 @@ package resolvers import ( "context" - "github.com/gnolang/tx-indexer/serve/graph/generated" "github.com/gnolang/tx-indexer/serve/graph/model" "github.com/gnolang/tx-indexer/types" ) @@ -35,6 +34,6 @@ func (r *subscriptionResolver) Blocks(ctx context.Context, filter model.BlockFil } // Subscription returns generated.SubscriptionResolver implementation. -func (r *Resolver) Subscription() generated.SubscriptionResolver { return &subscriptionResolver{r} } +func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} } type subscriptionResolver struct{ *Resolver } diff --git a/serve/graph/resolvers/transaction.resolvers.go b/serve/graph/transaction.resolvers.go similarity index 99% rename from serve/graph/resolvers/transaction.resolvers.go rename to serve/graph/transaction.resolvers.go index 115a6140..f3c1698f 100644 --- a/serve/graph/resolvers/transaction.resolvers.go +++ b/serve/graph/transaction.resolvers.go @@ -1,4 +1,4 @@ -package resolvers +package graph import ( "math"