New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPGraphQL v2.0 (DRAFT) #1936
Closed
jasonbahl
wants to merge
20
commits into
wp-graphql:develop
from
jasonbahl:feature/#1751-update-graphql-php-to-14.5.1
Closed
WPGraphQL v2.0 (DRAFT) #1936
jasonbahl
wants to merge
20
commits into
wp-graphql:develop
from
jasonbahl:feature/#1751-update-graphql-php-to-14.5.1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ble before connections are registered
…stry when registering a new Type
…plemented by other interfaces - Update WPInterfaceType to support passing connections that the Interface can have when registering an InterfaceType
…y implement the databaseIdentifier Interface
…with the User type that implements the databaseIdentifier interface
… registrars to the Types being registered. So now, for many connections, instead of directly using `register_graphql_connection` the Type and/or Interface can define connections when being registered. - Updated several interfaces to declare other interfaces they implement - Introduced a new ConnectionInterface and Edge Interface - Introduced a new HierarchicalNode interface - Introduced a new Previewable Interface - Removed the ContentRevisionUnion and MenuItemObjectUnion Types - Updated tests to include back compat checks for users that need the MenuItemObjectUnion in their queries. They can drop in a snippet to add it back to their API if they need it.
…p-to-14.5.1 # Conflicts: # .gitignore # composer.lock # src/Type/ObjectType/PostObject.php # src/Type/ObjectType/RootQuery.php # src/Type/Union/ContentRevisionUnion.php # src/Type/Union/MenuItemObjectUnion.php # tests/wpunit/MediaItemQueriesTest.php
…p-to-14.5.1 # Conflicts: # composer.lock # src/Type/InterfaceType/ContentTemplate.php # src/Type/InterfaceType/DatabaseIdentifier.php # src/Type/WPInterfaceType.php # tests/wpunit/AccessFunctionsTest.php
- Update composer.lock - Update ContentNode.php to remove unused use statements - Update ContentTemplate to add `use Exception` statement - Update DatabaseIdentifier to add `use Exception` statement, remove extra bracket - Update TermNode.php to remove unused use statements - Update code style in RootQuery.php
…l oneToOne connections - Back out change to CLI script - Back out change to register_graphql_connection hook priority
jasonbahl
added
Architecture
Component: Connections
Issues related to connections
Component: Interfaces
Component: Query
Type: Enhancement
New feature or request
labels
Jun 2, 2021
- Update code styling
…n, ContentNodeConnection, ContentTypeConnection, MenuConnection, MenuItemConnection, MenuItemLinkableConnection, TaxonomyConnection, TermNodeConnection, UserConnection - Adds tests to ensure the interfaces exist and implement the Connection Interface and their edges implement the ConnectionEdge interface
…p-to-14.5.1 # Conflicts: # composer.lock # src/Registry/TypeRegistry.php
- Change `WpPageInfo` to `PageInfo` - Remove ContentRevisionUnion, TermObjectUnion, PostObjectUnion in favor of interfaces (ContentNode, TermNode)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Architecture
Component: Connections
Issues related to connections
Component: Interfaces
Component: Query
Type: Enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I converted this to a DRAFT PR as this is getting broken up into smaller pieces as much of this can be introduced as 1.. non-breaking releases.
This updates WPGraphQL to use GraphQL-PHP v14.5.1 which allows Interfaces to implement other Interfaces.
Along with this update, comes the implementation of Interfaces implementing other Interfaces, which moves some things around in the Schema and causes some breaking changes to the schema.
Of course, whether the changes are breaking for your applications are relative to the queries/mutations your application executes. There's a good chance that you could upgrade from 1.x.x to 2.0 with no changes needed to your client applications or WPGraphQL server extensions, but depending on your use of WPGraphQL, you may need to do some legwork to get other parts of your applications updated.
Breaking Changes
Below is a summary of breaking changes to be aware of and to look for when upgrading from 1.x.x to 2.0
WPPageInfo
type removed, replaced withPageInfo
to follow the Relay spec.WPPageInfo
type to add additional fieldsuri
field has changed fromString!
toString
. While this is technically a breaking change to the Schema, this is a bugfix as errors are thrown when querying Post / Term Nodes of non-public post types or taxonomies as they don't have a uri (because they're not public).isPreview
field was removed from theContentNode
Interface and added to thePreviewable
InterfacepreviewRevisionDatabaseId
field was removed from theContentNode
Interface and added to thePreviewable
InterfacepreviewRevisionId
field was removed from theContentNode
Interface and added to the thePreviewable
InterfaceHierarchicalContentNode
fromMediaItem
and introducesHierarchicalNode
instead.MediaItem
should not have hadchildren
fieldsisPreview
,previewRevisionDatabaseId
andpreviewRevisionId
fields fromMediaItem
type field fromMediaItem
.MediaItem.parent
field changed fromHierarchicalContentNodeToParentContentNodeConnectionEdge
toMediaItemToParentContentNodeConnectionEdge
MenuItem.connectedObject
field has been removed. UseconnectedNode
field instead.MenuItemObjectUnion
type has been removed from the Schema.RootQuery.revisions
type changed fromRootQueryToContentRevisionUnionConnection
toRootQueryToRevisionsConnection
User.revisions
field changed type fromUserToContentRevisionUnionConnection
toUserToContentNodeConnection
New Features
WPPageInfo
type removed, replaced withPageInfo
to follow the Relay specBugfixes
deregister_graphql_mutation
MenuItemObjectUnion
Type from the Schema (read more below)uri
field fromString!
toString
to support Types that do not have a uri (private taxonomy terms, private post types)ContentRevisionUnion
type from the SchemaNEW: Register Connections when Registering a Type
Prior to this, Types and Connections needed to be registered independently, like so:
Register an Object Type
Register a Connection From the Type
Now, if we wanted
TypeA
to have a connection to Posts, we'd have to register this separately:Then you would be able to query something like so:
Register the connection as part of the Type
Now, with this PR, the connection from
TypeA
toPost
can be registered whenTypeA
is registered, like so:Now the connections from
TypeA
toPost
can be defined at the time of registeringTypeA
.Of course,
register_graphql_connection()
still exists, so you can still create connections between Types your code doesn't define, but for Types you define in your codebase, this new method of registering connections can come in handy and reduce overall amount of code needed.You can see how core WPGraphQL is updating code to make use of this change here.
NEW: Interfaces Implementing Interfaces
The main reason for updating GraphQL-PHP was to enable Interfaces to implement other Interfaces, a feature that was updated in the GraphQL Spec in 2020 and brought to GraphQL-PHP in early 2021.
This now allows Interfaces to be defined more concisely. For example, WPGraphQL now has a
DatabaseIdentifier
Interface that defines thedatabaseId
field. Any Type in the Schema, including other Interfaces, that support a databaseId field, can implement this interface. For example, theContentNode
Interface, which is implemented by all Post Types, now implements theDatabaseIdentifier
Interface. So, any query for content nodes clearly documents that ContentNodes all have adatabaseId
field.Another benefit is Connections can all implement shared interfaces.
Now, there's a common
Connection
Interface that all plural connections share. So it's much easier for client developers to understand what's available in the graph via introspection. One can simply look at theConnection
interface in documentation and see all Types that implement this. Tooling can be built to aid in consuming connections, etc.For example, we can search
Connection
in the GraphiQL Docs to find allConnections
:Or we can search
SingleNodeConnection
to find all one-to-one connections in the Graph:On the server side, modifying connections, say, to add different query arguments and adjust resolver behavior, can be done by targeting connection interfaces, either broadly (
Connection
) or specifically, likeTermNodeToContentNodeConnection
or even more specifically likeCategoryToPostConnection
.This will also make it easier for extensions to re-use core features.
For example, WPGraphQL for Advanced Custom Fields will now be able to share Interfaces for Cloned Field Groups with other Field Groups, making it easier for client developers to write re-usable fragments. Super cool!
Removal of MenuItemObjectUnion
At one point in WPGraphQL, querying objects connected to Menu Items (posts, pages, etc) required querying a field named
connectedObject
. This was deprecated in favor of theconnectedNode
field that is of TypeMenuItemToMenuItemLinkableConnectionEdge
(which implementsSingleNodeConnectionEdge
Interface).This deprecated connection and the deprecated
MenuItemObjectUnion
has been removed from the codebase.If you're not ready for this removal, you can see the code that tests backward compatibility, and register the Union and Connection back in your codebase.
Removal of ContentRevisionUnion, PostObjectUnion, TermObjectUnion
These Unions have been replaced by Interfaces, but have been left to support extensions that might return these Types.
It's recommended that extensions referencing these Types upgrade to reference the equivalent Interface, as listed below:
ContentRevisionUnion
=>ContentNode
PostObjectUnion
=>ContentNode
TermObjectUnion
=>TermNode
closes #1751
closes #1923