-
Notifications
You must be signed in to change notification settings - Fork 3
chore(examples): Allow custom queries in bindings #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e08819c
add python example
Alex6323 0027f06
add kotlin example
Alex6323 fc75209
add go example
Alex6323 196c07c
add custom query
Alex6323 2925fcd
update gradle deps
Alex6323 ba1dca1
no variables query
Alex6323 e09d820
add UncheckedQuery type
Alex6323 39f0e80
Merge branch 'sdk-bindings' into chore/custom-query-in-bindings
Alex6323 f012e7b
review
Alex6323 86e93ac
fix ci
Alex6323 88d036e
small improvements
Alex6323 b22d6c6
align examples
Alex6323 4d25380
nits
Alex6323 30f5d91
nits 2
Alex6323 a89248a
typed query variables in bindings
Alex6323 925a87d
improvements
Alex6323 9ba2589
impl all query types
Alex6323 170f195
final?
Alex6323 6f11b34
update docs
Alex6323 d469169
better text I hope
Alex6323 8c28b7d
and
Alex6323 788a07c
Merge branch 'sdk-bindings' into chore/custom-query-in-bindings
Alex6323 826d07c
udeps, clippy, docs
Alex6323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
|
|
||
| sdk "bindings/iota_sdk_ffi" | ||
| ) | ||
|
|
||
| func main() { | ||
| client := sdk.GraphQlClientNewDevnet() | ||
|
|
||
| query := ` | ||
| query CustomQuery($id: UInt53) { | ||
| epoch(id: $id) { | ||
| epochId | ||
| referenceGasPrice | ||
| totalGasFees | ||
| totalCheckpoints | ||
| totalTransactions | ||
| } | ||
| }` | ||
|
|
||
| variablesJson := `{"id": 1}` | ||
| variables := string(variablesJson) | ||
|
|
||
| payload1 := sdk.CustomQuery{ | ||
| Query: query, | ||
| Variables: &variables, | ||
| } | ||
| res1, err := client.RunCustomQuery(payload1) | ||
| if err.(*sdk.SdkFfiError) != nil { | ||
| log.Fatalf("Failed to perform a custom query: %v", err) | ||
| } | ||
| fmt.Println(res1) | ||
|
|
||
| payload2 := sdk.CustomQuery{ | ||
| Query: query, | ||
| Variables: nil, | ||
| } | ||
| res2, err := client.RunCustomQuery(payload2) | ||
| if err.(*sdk.SdkFfiError) != nil { | ||
| log.Fatalf("Failed to perform a custom query: %v", err) | ||
| } | ||
| fmt.Println(res2) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import iota_sdk.CustomQuery | ||
| import iota_sdk.GraphQlClient | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.serialization.encodeToString | ||
| import kotlinx.serialization.json.Json | ||
|
|
||
| fun main() = runBlocking { | ||
| val client = GraphQlClient.newDevnet() | ||
|
|
||
| val query = | ||
| """ | ||
| query CustomQuery(${'$'}id: UInt53) { | ||
| epoch(id: ${'$'}id) { | ||
| epochId | ||
| referenceGasPrice | ||
| totalGasFees | ||
| totalCheckpoints | ||
| totalTransactions | ||
| } | ||
| } | ||
| """.trimIndent() | ||
|
|
||
| val variables = mapOf("id" to 1) | ||
| val jsonVariables = Json.encodeToString(variables) | ||
|
|
||
| val payload1 = CustomQuery(query = query, variables = jsonVariables) | ||
| val res1 = client.runCustomQuery(payload1) | ||
| println(res1) | ||
|
|
||
| val payload2 = CustomQuery(query = query, null) | ||
| val res2 = client.runCustomQuery(payload2) | ||
| println(res2) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| import asyncio | ||
|
|
||
|
|
||
| async def main(): | ||
| client = GraphQlClient.new_devnet() | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.