When registering a connection, it would be nice if the Type that the connection is coming from implemented an Interface to signify/document that the Type supports said connection.
Let's take Post Type and Taxonomy connections as an example.
We (as developers with prior WordPress experience) know that Posts have Categories and Tags, but we don't know what other Post Types (ContentNodes) have Category/Tag connections. And we also don't inherently know what other Post Types have connections with other Taxonomies. We can browse the Schema a bit to find out have to really know what we're looking for.
If each Post Type that had connections with Term Nodes implemented an Interface such as NodeWithTermNodeConnection we could search this type in a tool such as GraphiQL and find all Types that have connections with Terms.
Let's look at this in SDL to better grasp the idea:
Interface NodeWithTermNodeConnection {
terms: TermNodeConnection
}
Interface ContentNodeWithTagConnection implements NodeWithTermNodeConnection {
terms: TermNodeConnection
tags: TagConnection
}
Interface ContentNodeWithSomeOtherTaxonomyConnection implements NodeWithTermNodeConnection {
terms: TermNodeConnection
someOtherTaxonomy: SomeOtherTaxonomyConnection
}
Then the Post Types that are connected with the Taxonomies could implement Interfaces like so:
type Post implements NodeWithTagConnection
type CustomPostType implements NodeWithSomeOtherTaxonomyConnection
type CustomTypeWithNoTaxonomyConnections
Then we could query like so:
{
post: nodeByUri(uri:"/path-to-post") {
...NodeByUri
}
customType: nodeByUri(uri:"/path-to-custom-type") {
...NodeByUri
}
customTypeWithNoTaxonomyConnections: nodeByUri(uri:"/path-to-type-with-no-taxonomy-connection") {
...NodeByUri
}
}
fragment NodeByUri on UniformResourceIdentifiable {
__typename
uri
...Tags
...CustomTaxonomies
...AllTerms
}
fragment Tags on NodeWithTagConnection {
tags {
nodes {
__typename
}
}
}
fragment CustomTaxonomies on NodeWithCustomTaxonomyConnection {
customTaxonomies {
nodes {
__typename
}
}
}
fragment AllTerms on NodeWithTermsConnection {
terms {
nodes {
__typename
}
}
}
This would be a valid query. We could query nodes from the root and specify that we want the connected fields only if the node being returned had the connection we were interested in.
We would get a payload like so:
{
"post": {
"__typename": "Post",
"uri": "/path-to-post",
"tags": {
"nodes":[
{
"__typaname": "Tag"
}
]
},
"allTerms": {
"nodes":[
{
"__typaname": "Tag"
}
]
}
},
"customType": {
"__typename": "CustomType",
"uri": "/path-to-custom-type",
"customTaxonomies": {
"nodes":[
{
"__typaname": "CustomTaxonomy"
}
]
},
"allTerms": {
"nodes":[
{
"__typaname": "CustomTaxonomy"
}
]
}
},
"customTypeWithNoTaxonomyConnections": {
"__typename": "CustomTypeWithNoTaxonomyConnections",
"uri": "/path-to-type-with-no-taxonomy-connection"
}
}
When registering a connection, it would be nice if the Type that the connection is coming from implemented an Interface to signify/document that the Type supports said connection.
Let's take Post Type and Taxonomy connections as an example.
We (as developers with prior WordPress experience) know that Posts have Categories and Tags, but we don't know what other Post Types (ContentNodes) have Category/Tag connections. And we also don't inherently know what other Post Types have connections with other Taxonomies. We can browse the Schema a bit to find out have to really know what we're looking for.
If each Post Type that had connections with Term Nodes implemented an Interface such as
NodeWithTermNodeConnectionwe could search this type in a tool such as GraphiQL and find all Types that have connections with Terms.Let's look at this in SDL to better grasp the idea:
Then the Post Types that are connected with the Taxonomies could implement Interfaces like so:
Then we could query like so:
{ post: nodeByUri(uri:"/path-to-post") { ...NodeByUri } customType: nodeByUri(uri:"/path-to-custom-type") { ...NodeByUri } customTypeWithNoTaxonomyConnections: nodeByUri(uri:"/path-to-type-with-no-taxonomy-connection") { ...NodeByUri } } fragment NodeByUri on UniformResourceIdentifiable { __typename uri ...Tags ...CustomTaxonomies ...AllTerms } fragment Tags on NodeWithTagConnection { tags { nodes { __typename } } } fragment CustomTaxonomies on NodeWithCustomTaxonomyConnection { customTaxonomies { nodes { __typename } } } fragment AllTerms on NodeWithTermsConnection { terms { nodes { __typename } } }This would be a valid query. We could query nodes from the root and specify that we want the connected fields only if the node being returned had the connection we were interested in.
We would get a payload like so:
{ "post": { "__typename": "Post", "uri": "/path-to-post", "tags": { "nodes":[ { "__typaname": "Tag" } ] }, "allTerms": { "nodes":[ { "__typaname": "Tag" } ] } }, "customType": { "__typename": "CustomType", "uri": "/path-to-custom-type", "customTaxonomies": { "nodes":[ { "__typaname": "CustomTaxonomy" } ] }, "allTerms": { "nodes":[ { "__typaname": "CustomTaxonomy" } ] } }, "customTypeWithNoTaxonomyConnections": { "__typename": "CustomTypeWithNoTaxonomyConnections", "uri": "/path-to-type-with-no-taxonomy-connection" } }