https://kotlinlang.org logo
#apollo-kotlin
Title
# apollo-kotlin
w

wasyl

04/02/2024, 3:51 PM
Back with a question, I'm looking at
Apollo-AST
artifact and I can read and parse graphql executable document and schema just fine 👌 But I can't figure out what's the proper way to grab a selection type. For query variables I can see
type
field with stuff like
GQLNonNullType(GQLNamedType(name = ID))
, but for e.g. fragment selections I only see a name. I can extract a type manually via
(schema.typeDefinitions[fragmentTypeCondition.name] as GQLObjectTypeDefinition).fields[fragmentField.name]
, just wondering if I'm not unnecessarily complicating things
1
m

mbonnin

04/02/2024, 3:57 PM
Yeah, that's just the current situation. We don't have anything that "materializes" the references in the AST, you just get the plain AST
There is GQLField.definitionFromScope() that helps a little bit
(note your snippet above might fail if your fragment type condition is an interface)
w

wasyl

04/02/2024, 4:04 PM
Yeah I expect some special cases for interfaces, anonymous fragments etc., just wanted to get a general idea 👍 the extension you sent looks useful, guess I'll have to browse https://www.apollographql.com/docs/kotlin/kdoc/apollo-ast/com.apollographql.apollo3.ast/index.html 🙂 that clears things up, thanks!
btw are there any major changes in these APIs planned in 4.x?
m

mbonnin

04/02/2024, 4:05 PM
In a perfect world, we have a specialized data structure for validated operations that has all references resolved, I was discussing this with @bod recently. But we're not there yet
👍 1
btw are there any major changes in these APIs planned in 4.x?
There are a few. Most of the
GQLXYz
are basically untouched and get handy superinterfaces for stuff like
HasDirectives
,
HasDescription
,etc...
IIRC the main changes are the top level APIs and how to convert between File <-> GQLDocument <-> Schema
👍 1
IIRC there was a
File.toSchema()
and now you have to go through GQLDocument always
👍 1
w

wasyl

04/02/2024, 4:09 PM
Got it, thanks 🙂