-
Notifications
You must be signed in to change notification settings - Fork 47
feat(composeui): graphql interactions #4276
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi @Tbaile! 👋 |
4570144
to
5bbd084
Compare
@nicolasfara @cric96 you are the Compose experts. See if you can have a look to this one. |
alchemist-composeui/src/jvmMain/kotlin/it/unibo/alchemist/boundary/composeui/ComposeMonitor.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minors on Composable function coding style
alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/NodeDrawer.kt
Show resolved
Hide resolved
alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/App.kt
Show resolved
Hide resolved
val errors = _errors.asStateFlow() | ||
|
||
// TODO: parameterize the host and port and separate client in different file | ||
private val client = GraphQLClientFactory.subscriptionClient( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to add URL and port as configuration/parameter of NodeViewModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I've actually left this as is for a couple of reasons:
- When launching the GUI through the ComposeMonitor, the simulation file provides the fields for the connection, these fields then can be used to generate a client inside a Dependency Injection mechanism (or simply a Factory) that then provides the the dependency to every ViewModel
- This in fact is not the case for the WASM/JS build, that probably needs an additional View to allow the user to set the data.
9210dba
to
b45cc95
Compare
alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/App.kt
Show resolved
Hide resolved
alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/App.kt
Outdated
Show resolved
Hide resolved
thread( | ||
name = "ComposeMonitor", | ||
isDaemon = true, | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of launching a thread, have you considered using a different dispatcher in the launch
?
Dealing with dispatchers is the usual way to go if you do not have strong reasons to spawn platform threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already tried, my first attempt was to use the compose-provided method of spawning the UI, however this forked the main process and halted all the other processes (simulation included). This is the only way I've found that don't fork processes and still manages all the UI on it's own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me the attempt you performed. Could you paste here an MRE?
AFAIK spawning a coroutine does not fork the main process, instead, it schedules the coroutine into a different thread pool (if used a dispatcher)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was aware of this too. However it seems that issue resides on how the Monitors get spawned.
class ComposeMonitor : OutputMonitor<Any, Nothing> {
override fun initialized(environment: Environment<Any, Nothing>) {
application {
Window(onCloseRequest = ::exitApplication, title = "Alchemist") { App() }
}
}
}
Launching this snippet, the simulation freezes, haven't been able to figure out why.
f0ff956
to
3994856
Compare
22322e6
to
3b697c7
Compare
|
Hi @Tbaile! 👋 |
Using graphql client provided in the project,
subscriptions
,mutations
andqueries
works through ComposeUI.For each node inside the simulation a subscriptor is being instantiated so that data can be followed for each node, however the node to pos entry returns a pretty long list of empty nodes, backend API might need to be adjusted.
Found with @AngeloFilaseta a non-reproducible issue while subscripting to the simulation data, sometimes the returned value is nullable where it isn't and that throws GraphQL completely mad, an alert has been provided that restarts the subscription. We might have a workaround, I'll leave the word to him tho.
As the video shows, the issue where data is being still processed is there, the backend keeps sending too many events.
Screencast.From.2025-05-11.23-12-20.mp4