Skip to content
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

feat: productAttributes query implemented #905

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
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