To support interfaces webonyx requires a resolveType callable for every interface. We should be able to pass a type config decorator to BuildSchema::build() that appends resolveType with a custom method to find the interface resolver.
Given the following schema:
type Post {
attachment: Attachment
}
interface Attachment {
size: Int!
}
type Photo implements Attachment {
height: Int!
width: Int!
}
type Video implements Attachment {
length: Int!
}
There are a couple of methods we can use to resolve the type of attachment field for a Post:
Look for a App\Graphql\Types\Post@attachment__typename() method.
Check if the data returned from App\Graphql\Types\Post@attachment() is an array and contains a __typename key.
Check if the data returned from App\Graphql\Types\Post@attachment() is an object and has a property named __typename.
Check if the data returned from App\Graphql\Types\Post@attachment() is an Eloquent model and fallback to it's class_basename().
In theory we could also look for a App\Graphql\Types\Attachment@__typename() method but without the Post context that wouldn't be as useful.
Note: The reason for __typename is to piggyback the meta field in GraphQL named the same way.
To support interfaces webonyx requires a
resolveType
callable for every interface. We should be able to pass a type config decorator toBuildSchema::build()
that appendsresolveType
with a custom method to find the interface resolver.Given the following schema:
There are a couple of methods we can use to resolve the type of
attachment
field for aPost
:App\Graphql\Types\Post@attachment__typename()
method.App\Graphql\Types\Post@attachment()
is an array and contains a__typename
key.App\Graphql\Types\Post@attachment()
is an object and has a property named__typename
.App\Graphql\Types\Post@attachment()
is an Eloquent model and fallback to it'sclass_basename()
.In theory we could also look for a
App\Graphql\Types\Attachment@__typename()
method but without thePost
context that wouldn't be as useful.Note: The reason for
__typename
is to piggyback the meta field in GraphQL named the same way.Thoughts and ideas would be greatly appreciated.