feat: introduce common interfaces#2617
Conversation
…v1.13.0 # Conflicts: # .github/workflows/deploy-docker-image.yml
…tory instead of `/src/Registry/Connection`
… `RootQuery` and 'User' - Remove ContentRevisionUnion type - Update WPConnectionType so that all connections implement `Connection` and `Edge` Interfaces - Add Connection interfaces (Connection, Edge, SingularConnection) - Add node, DatabaseIdentifier interfaces to MenuItemLinkable - update deregister_graphql_field test to assert contentNodes returns null instead of asserting an individual node returns null
- separate registration for ConnectionInterface, Edge, SingularConnection - add early returns to WPConnectionType to prevent duplicate registration of connection types - rename file/class for CommenterInterface to be Commenter to be consistent with the other Interface naming conventions - Introduce `ContentNodeConnection` Interface, apply it to all connections with toType 'ContentNode`
- revert composer.lock - rename SingularConnectionEdge to SingularConnection
- Add `CommentConnection` Interface to connections to the `Comment` type - deprecate PostObjectUnion class - deprecate TermObjectUnion class - add ConnectionInterfaceTest.php to test connections (breaking tests now as we implement the rest of the planned Interfaces)
- Apply SingularCommenterConnection on the Comment->Commenter connection - Update test for CommenterConnection to properly test for one-to-one connection instead of plural connection
- Apply HierarchicalNode Interface to HierarchicalTermNode and HierarchicalContentNode
- apply MenuConnection interface to connections to the `Menu` type
- apply MenuItemConnection interface to connections to the `MenuItem` type
…nEdge` - Rename `SingularContentTypeConnection` to `SingularContentTypeConnectionEdge` - Update connection interfaces referencing them -
- apply MenuItemLinkableConnection interface to connections to the `MenuItem` type
- Apply Previewable Interface to public post types - Introduce TaxonomyConnection - Apply TaxonomyConnection Interface to connections to the Taxonomy type
- apply TermNodeConnection interface to connections to the `MenuItem` type
- apply UserConnection interface to connections to the `User` type
…tentTypeConnectionEdge in favor of simplifying with `edge` - composer run fix-cs
…Singular` terminology already has meaning in WordPress (singular Post, Page, etc) and we _might_ see that terminology in the Graph in the future. Trying to avoid possible conflict with existing terminology
|
Code Climate has analyzed commit e96a0c5 and detected 58 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
|
Really cool stuff. Do we want to keep the old (admittedly poorly-named) |
Ya, perhaps we keep the Thoughts on a new name for the field? |
|
There's only 2 places the I'm thinking we can deprecate these and introduce: |
|
Not sure about |
|
@justlevine ah! I remember why I had to make this change. With the introduction of the This is because all connections now expect to connect to a Node type, and a Union can't be a node type, because unions can't implement interfaces. I think the best way forward is to make this "technically" breaking change. For most use (99%+?) cases, it won't actually be a breaking change. Because the previous connection returned a Union instead of an Interface, the only way to query was like so (using the Since the new connection is an Interface, the same queries will still work. v1.12.2Here's the same query on WPGraphQL v1.12.2 (ContentRevisionUnion) Current PRAnd here's the same query with the changes from this PR applied The only way it would cause a break would be if someone were querying like so: {
viewer {
revisions {
... on UserToContentRevisionUnionConnection {
nodes {
__typename
... on Post {
id
uri
isRevision
}
... on Page {
id
uri
isRevision
}
}
}
}
}
revisions {
... on RootQueryToContentRevisionUnionConnection {
nodes {
__typename
... on Post {
id
uri
isRevision
}
... on Page {
id
uri
isRevision
}
}
}
}
}Which seems highly unlikely, but something we can call out in the release notes. |
|
fwiw, on a different note, working on this makes me want to re-visit #2355. I still don't quite now how to resolve that "problem" but it keeps haunting me. I have several one-off utility post types that I don't want to be lumped together as "content" but they keep showing up in my |
|
@justlevine we could potentially add something to the connection config for exluding the like: register_graphql_connection( [
'fromType' => 'RootQuery',
'toType' => 'ContentRevisionUnion',
...
'exclude_interfaces' => [ 'Connection' ],
'exclude_edge_interfces' => [ 'Edge' ],
] );🤔 I think it might be best to rip the bandaid off though, as the breaking change will likely not affect anyone, as explained above, and now we can ensure going forward that all connections properly lead to Nodes. |


What does this implement/fix? Explain your changes.
This introduces common interfaces. This PR is a fresh take on #2022
Interfaces introduced in this PR are:
Does this close any currently open issues?
closes #1738
Any other comments?
These connections add a lot of value to Schema organization, code reusability, and introspection.
One can now use GraphiQL to find all instances of Connections in the Schema like so:
One could also look for all Connections that implement a more specific Connection Interface, such as
ContentNodeConnection. This interface is applied to any node that has a connection to any type of Content Node. So a User to Post connection is aContentNodeConnectionand a User to Page connection is also a ContentNodeConnection.These shared connection interfaces allow client developers to have a better understanding of shared properties of connections and can allow for reduced code when querying similar data from the Graph.
On the server side, developers can more easily add features to specific connections or general connection interfaces.