Skip to content

Commit ca4b806

Browse files
committed
fix: cleanup references to model fields
1 parent c5c58fc commit ca4b806

File tree

11 files changed

+26
-24
lines changed

11 files changed

+26
-24
lines changed

src/Data/Connection/PostObjectConnectionResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function should_execute() {
130130
}
131131

132132
// For revisions, we only want to execute the connection query if the user has access to edit the parent post.
133-
if ( $this->source instanceof Post ) {
133+
if ( $this->source instanceof Post && isset( $this->source->post_type ) ) {
134134
$parent_post_type_obj = get_post_type_object( $this->source->post_type );
135135

136136
if ( isset( $parent_post_type_obj->cap->edit_post ) && current_user_can( $parent_post_type_obj->cap->edit_post, $this->source->ID ) ) {

src/Data/Connection/UserRoleConnectionResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function should_execute() {
7676
current_user_can( 'list_users' ) ||
7777
(
7878
$this->source instanceof User &&
79-
get_current_user_id() === $this->source->userId
79+
get_current_user_id() === $this->source->databaseId
8080
)
8181
) {
8282
return true;

src/Data/DataSource.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,22 +573,25 @@ public static function resolve_node_type( $node ) {
573573
switch ( true ) {
574574
case $node instanceof Post:
575575
if ( $node->isRevision ) {
576+
/** @var ?\WP_Post */
576577
$parent_post = get_post( $node->parentDatabaseId );
578+
577579
if ( ! empty( $parent_post ) ) {
578-
$parent_post_type = $parent_post->post_type;
579580
/** @var \WP_Post_Type $post_type_object */
580-
$post_type_object = get_post_type_object( $parent_post_type );
581-
$type = $post_type_object->graphql_single_name;
581+
$post_type_object = get_post_type_object( $parent_post->post_type );
582+
$type = $post_type_object->graphql_single_name ?? null;
583+
584+
break;
582585
}
583-
} else {
584-
/** @var \WP_Post_Type $post_type_object */
585-
$post_type_object = get_post_type_object( $node->post_type );
586-
$type = $post_type_object->graphql_single_name;
587586
}
587+
588+
/** @var \WP_Post_Type $post_type_object */
589+
$post_type_object = isset( $node->post_type ) ? get_post_type_object( $node->post_type ) : null;
590+
$type = $post_type_object->graphql_single_name ?? null;
588591
break;
589592
case $node instanceof Term:
590593
/** @var \WP_Taxonomy $tax_object */
591-
$tax_object = get_taxonomy( $node->taxonomyName );
594+
$tax_object = isset( $node->taxonomyName ) ? get_taxonomy( $node->taxonomyName ) : null;
592595
$type = $tax_object->graphql_single_name;
593596
break;
594597
case $node instanceof Comment:
@@ -633,7 +636,6 @@ public static function resolve_node_type( $node ) {
633636
* @since 0.0.6
634637
*/
635638
$type = apply_filters( 'graphql_resolve_node_type', $type, $node );
636-
$type = ucfirst( $type );
637639

638640
/**
639641
* If the $type is not properly resolved, throw an exception
@@ -649,7 +651,7 @@ public static function resolve_node_type( $node ) {
649651
*
650652
* @since 0.0.5
651653
*/
652-
return $type;
654+
return ucfirst( $type );
653655
}
654656

655657
/**

src/Registry/Utils/TermObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected static function get_connections( WP_Taxonomy $tax_object ) {
171171
'description' => __( 'The ancestors of the node. Default ordered as lowest (closest to the child) to highest (closest to the root).', 'wp-graphql' ),
172172
'connectionTypeName' => ucfirst( $tax_object->graphql_single_name ) . 'ToAncestors' . ucfirst( $tax_object->graphql_single_name ) . 'Connection',
173173
'resolve' => static function ( Term $term, $args, AppContext $context, $info ) use ( $tax_object ) {
174-
$ancestor_ids = get_ancestors( absint( $term->term_id ), $term->taxonomyName, 'taxonomy' );
174+
$ancestor_ids = isset( $term->databaseId ) ? get_ancestors( $term->databaseId, (string) $term->taxonomyName, 'taxonomy' ) : null;
175175

176176
if ( empty( $ancestor_ids ) ) {
177177
return null;

src/Type/Connection/Comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function register_connections() {
4141
'resolve' => static function ( User $user, $args, $context, $info ) {
4242
$resolver = new CommentConnectionResolver( $user, $args, $context, $info );
4343

44-
return $resolver->set_query_arg( 'user_id', absint( $user->userId ) )->get_connection();
44+
return $resolver->set_query_arg( 'user_id', absint( $user->databaseId ) )->get_connection();
4545
},
4646

4747
]
@@ -76,7 +76,7 @@ public static function register_connections() {
7676
'resolve' => static function ( Comment $comment, $args, $context, $info ) {
7777
$resolver = new CommentConnectionResolver( $comment, $args, $context, $info );
7878

79-
return $resolver->set_query_arg( 'parent', absint( $comment->commentId ) )->get_connection();
79+
return $resolver->set_query_arg( 'parent', absint( $comment->databaseId ) )->get_connection();
8080
},
8181
]
8282
)

src/Type/Connection/MenuItems.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static function register_connections() {
7070
[
7171
'taxonomy' => 'nav_menu',
7272
'field' => 'term_id',
73-
'terms' => (int) $menu->menuId,
73+
'terms' => (int) $menu->databaseId,
7474
'include_children' => true,
7575
'operator' => 'IN',
7676
],

src/Type/Connection/PostObjects.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static function register_connections() {
154154
'queryClass' => 'WP_Query',
155155
'description' => __( 'Returns ancestors of the node. Default ordered as lowest (closest to the child) to highest (closest to the root).', 'wp-graphql' ),
156156
'resolve' => static function ( Post $post, $args, $context, $info ) {
157-
$ancestors = get_ancestors( $post->ID, '', 'post_type' );
157+
$ancestors = isset( $post->databaseId ) ? get_ancestors( $post->databaseId, '', 'post_type' ) : null;
158158
if ( empty( $ancestors ) || ! is_array( $ancestors ) ) {
159159
return null;
160160
}
@@ -212,7 +212,7 @@ public static function register_connections() {
212212
'fromType' => 'User',
213213
'resolve' => static function ( User $user, $args, AppContext $context, ResolveInfo $info ) use ( $post_type_object ) {
214214
$resolver = new PostObjectConnectionResolver( $user, $args, $context, $info, $post_type_object->name );
215-
$resolver->set_query_arg( 'author', $user->userId );
215+
$resolver->set_query_arg( 'author', $user->databaseId );
216216

217217
return $resolver->get_connection();
218218
},

src/Type/Connection/Users.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function register_connections() {
5252
if ( isset( $edge['source'] ) && ( $edge['source'] instanceof Post ) ) {
5353
$edit_lock = $edge['source']->editLock;
5454
$time = ( is_array( $edit_lock ) && ! empty( $edit_lock[0] ) ) ? $edit_lock[0] : null;
55-
return ! empty( $time ) ? Utils::prepare_date_response( $time, gmdate( 'Y-m-d H:i:s', $time ) ) : null;
55+
return ! empty( $time ) ? Utils::prepare_date_response( $time, gmdate( 'Y-m-d H:i:s', (int) $time ) ) : null;
5656
}
5757
return null;
5858
},

src/Type/InterfaceType/MenuItemLinkable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public static function register_type( TypeRegistry $type_registry ): void {
2424
'fields' => [],
2525
'resolveType' => static function ( $node ) use ( $type_registry ) {
2626
switch ( true ) {
27-
case $node instanceof Post:
27+
case $node instanceof Post && isset( $node->post_type ):
2828
/** @var \WP_Post_Type $post_type_object */
2929
$post_type_object = get_post_type_object( $node->post_type );
3030
$type = $type_registry->get_type( $post_type_object->graphql_single_name );
3131
break;
32-
case $node instanceof Term:
32+
case $node instanceof Term && isset( $node->taxonomyName ):
3333
/** @var \WP_Taxonomy $tax_object */
3434
$tax_object = get_taxonomy( $node->taxonomyName );
3535
$type = $type_registry->get_type( $tax_object->graphql_single_name );

src/Type/InterfaceType/UniformResourceIdentifiable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public static function register_type( TypeRegistry $type_registry ) {
7070
],
7171
'resolveType' => static function ( $node ) use ( $type_registry ) {
7272
switch ( true ) {
73-
case $node instanceof Post:
73+
case $node instanceof Post && isset( $node->post_type ):
7474
/** @var \WP_Post_Type $post_type_object */
7575
$post_type_object = get_post_type_object( $node->post_type );
7676
$type = $type_registry->get_type( $post_type_object->graphql_single_name );
7777
break;
78-
case $node instanceof Term:
78+
case $node instanceof Term && isset( $node->taxonomyName ):
7979
/** @var \WP_Taxonomy $tax_object */
8080
$tax_object = get_taxonomy( $node->taxonomyName );
8181
$type = $type_registry->get_type( $tax_object->graphql_single_name );

0 commit comments

Comments
 (0)