https://kotlinlang.org logo
r

Ryan Brink

06/09/2023, 12:59 PM
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

bod

06/09/2023, 1:03 PM
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

Ryan Brink

06/09/2023, 1:08 PM
🤔 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

bod

06/09/2023, 1:10 PM
interfaces
is of a nullable type. Yes it may be something like this!
r

Ryan Brink

06/09/2023, 1:11 PM
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

bod

06/09/2023, 1:13 PM
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

Ryan Brink

06/09/2023, 1:16 PM
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

bod

06/09/2023, 1:16 PM
you may still have other issues however if... ah 😄
r

Ryan Brink

06/09/2023, 1:17 PM
ty for the help! 🙌
b

bod

06/09/2023, 1:17 PM
sure thing!
r

Ryan Brink

06/09/2023, 1:40 PM
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

bod

06/09/2023, 1:42 PM
but
args
is not nullable
oh sorry
encodeDefaults
r

Ryan Brink

06/09/2023, 1:42 PM
yes 🙂
b

bod

06/09/2023, 1:43 PM
indeed!
would you be interested in opening a PR for that? (no worries at all if not)
r

Ryan Brink

06/09/2023, 1:44 PM
nothing hits like 1 line open source cred 😈
sure thing
b

bod

06/09/2023, 1:44 PM
it may be a bit more than 1 line because of tests 😛
r

Ryan Brink

06/09/2023, 1:45 PM
haha no worries... will see how many things I break some time today 🙂
5 Views