Hey :wave: I'm using apollo to generate an introsp...
# apollo-kotlin
r
Hey πŸ‘‹ I'm using apollo to generate an introspected schema json from an SDL, but when I try to feed the json into a tool like GraphiQL or GQL voyager, I get an error
Copy code
buildClientSchema.mjs:193 Uncaught Error: Introspection result missing interfaces: { kind: "OBJECT", name: "issue__c", fields: [[Object], [Object], [Object]] }.
Does anyone know what might be going on here? as far as I can tell, the SDL is valid (can feed sdl into voyager and see visualization). I've attached the introspection blob in case that helps. Appreciate any ideas πŸ™
b
An introspection schema json is the raw result of an introspection GraphQL query. There are several possible ways to write such a query, which will result in different shapes of the response. It is possible that this json response doesn't correspond to the query made by these tools and so they can't find what they're looking for in it.
it looks like the
interfaces
field is missing
r
πŸ€” is there a way to feed that query into the
._toIntrospectionSchema_()
call? otherwise I'm not sure how to generate this
could it be that the json is treating an empty array as a null value and trimming it? not sure why there would be no interface block, other than that I haven't defined any
b
interfaces
is of a nullable type. Yes it may be something like this!
r
interesting... I see that under the hood, there is a
IntrospectionSchemaBuilder
seems like that would be the only way to get in the weeds w/ this schema generator, but it is private
oh i guess i could just use
data class IntrospectionSchema
directly
oh nice you guys use ktx serialization, i could probably just use a custom serializer
b
ah we do use
explicitNulls = false
, it's probably that?
When this flag is disabled properties with
null
values without default are not encoded;
oh nice you guys use ktx serialization, i could probably just use a custom serializer
so yes I think that should work πŸ™‚
r
Copy code
schema = schema.copy(
                    __schema = schema.__schema.copy(
                        types = schema.__schema.types.map {
                            if (it is IntrospectionSchema.Schema.Type.Object) {
                                it.copy(
                                    interfaces = emptyList()
                                )
                            } else {
                                it
                            }
                        }
                    )
                )
kinda gross but this solves it... now I get a new error πŸ˜„
b
you may still have other issues however if... ah πŸ˜„
r
ty for the help! πŸ™Œ
b
sure thing!
r
think you guys might want to consider adding
encodeDefaults = true
to the json serializer. Reason being, that if you don't things like
Field.args
which default to an empty array will not be included in the encoded result
this now works 🦜 with the schema changes above and adding using the serializer w/ encodeDefaults
b
but
args
is not nullable
oh sorry
encodeDefaults
r
yes πŸ™‚
b
indeed!
would you be interested in opening a PR for that? (no worries at all if not)
r
nothing hits like 1 line open source cred 😈
sure thing
b
it may be a bit more than 1 line because of tests πŸ˜›
r
haha no worries... will see how many things I break some time today πŸ™‚