Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 113 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 26 additions & 4 deletions includes/connection/class-product-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ public static function register_connections() {
]
)
);

// From RootQuery to GlobalProductAttribute.
register_graphql_connection(
self::get_connection_config(
[
'fromType' => 'RootQuery',
'toType' => 'GlobalProductAttribute',
'fromFieldName' => 'productAttributes',
'connectionArgs' => [],
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Product_Attribute_Connection_Resolver( $source, $args, $context, $info );

return $resolver->get_connection();
},
]
)
);
}

/**
Expand All @@ -73,16 +90,21 @@ public static function get_connection_config( $args = [] ): array {
'fromFieldName' => 'attributes',
'connectionArgs' => [],
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
$resolver = new Product_Attribute_Connection_Resolver();

// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
switch ( $info->fieldName ) {
case 'globalAttributes':
return $resolver->resolve( $source, $args, $context, $info, 'global' );
$resolver = new Product_Attribute_Connection_Resolver( $source, $args, $context, $info, 'global' );
break;
case 'localAttributes':
return $resolver->resolve( $source, $args, $context, $info, 'local' );
$resolver = new Product_Attribute_Connection_Resolver( $source, $args, $context, $info, 'local' );
break;
default:
return $resolver->resolve( $source, $args, $context, $info );
$resolver = new Product_Attribute_Connection_Resolver( $source, $args, $context, $info );
break;
}

return $resolver->get_connection();
},
],
$args
Expand Down
Loading