https://kotlinlang.org logo
#kgraphql
Title
# kgraphql
p

py

01/06/2021, 5:26 AM
e.g.
Copy code
instances(className: "com.squareup.example.Foo") {
  someField
  someOtherField  
}
j

jeggy

01/06/2021, 8:43 PM
As GraphQL is strictly typed by definition, it is a bit hard to have dynamic fields like this. But I have seen other GraphQL implementations have support for JSON data type. This could be something that KGraphQL should also have support for.
But you can easily create a base class and then have something like this:
Copy code
type<Foo> {
  property<String>("someField") {
    resolver { "Value to return" }
  }
  property<String>("someOtherField") {
    resolver { "Other value to return" }
  }
}
p

py

01/06/2021, 9:46 PM
interesting, I need to think about this. I was basically thinking that the parameters provided would help locate the type and its fields. On the other hand, I might be able to work around that by registering all known classes in the heap dump on start, and do what you just suggested.
j

jeggy

01/06/2021, 10:00 PM
I'm not really sure what your "heap dump" is. But if these are some random document data structure, then it will probably be a bit hard getting them into GraphQL types. But most likely those types have some specific class structure and it's just the matter of returning them correctly
👍 1
p

py

01/08/2021, 1:02 AM
A heap dump is a copy of the java heap. Classes, instances, etc.
j

jeggy

01/08/2021, 4:23 PM
I'm not sure what structure or how you would get that information into your Kotlin code. But I guess it can be in a String format. So you could create a GraphQL scalar for it using
stringScalar
and then where ever you use your graphql service, you can deserialize it however you want.
p

py

01/08/2021, 6:53 PM
thx, I’ll play again with it when they fix the compose bug 🙂
(but yeah anyway that information presents itself in the form of the API I wrote for the heap dump parser, which is somewhat similar to Java reflection APIs)
2 Views