Back with a question, I'm looking at `Apollo-AST` ...
# apollo-kotlin
w
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
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
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
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
Got it, thanks ๐Ÿ™‚