SnippetObjectType is implemented as a union of a project's registered snippet models. Unless the snippet classes themselves implement a field that can discriminate the specific type of a snippet instance, it can be difficult to determine which type of snippet you have in a client.
For example, if using a stream field with SnippetChooserBlock, I might query it as follows:
query MyPages {
pages(id: 28) {
title
... on MyPage {
streamFieldContent {
... on SnippetChooserBlock {
id
blockType
snippet {
... on FooSnippet {
fooField
}
... on BarSnippet {
barField
}
}
}
}
}
}
}
The issue then is determining exactly which snippet type I get in response. I could query __typename on SnippetObjectType, but this won't work in environments where introspection queries are forbidden.
To get around this in my project we've added our own snippet interface type, which has a snippetType field, which returns the snippet class name. Something similar would be a valuable addition to grapple.
SnippetObjectType
is implemented as a union of a project's registered snippet models. Unless the snippet classes themselves implement a field that can discriminate the specific type of a snippet instance, it can be difficult to determine which type of snippet you have in a client.For example, if using a stream field with
SnippetChooserBlock
, I might query it as follows:The issue then is determining exactly which snippet type I get in response. I could query
__typename
onSnippetObjectType
, but this won't work in environments where introspection queries are forbidden.To get around this in my project we've added our own snippet interface type, which has a
snippetType
field, which returns the snippet class name. Something similar would be a valuable addition tograpple
.