Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

GraphQL-129: Retrieve Customer token #180

Merged

Conversation

pfantini
Copy link
Contributor

@pfantini pfantini commented Sep 11, 2018

Description

Create new mutation to retrive customer token by email and password

Manual testing scenarios

  1. Run the following request in GraphiQL:
mutation {
    generateCustomerToken(
        email: "customer@example.com"
        password: "password"
    ) {
        token
    }
}

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Sep 11, 2018

CLA assistant check
All committers have signed the CLA.

@pfantini pfantini force-pushed the 129-retrive-customer-token branch from 57c9fd1 to c0d1b7b Compare September 12, 2018 15:16
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class GenerateCustomerToken implements ResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, provide dockblock for class


class GenerateCustomerToken implements ResolverInterface
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

ResolveInfo $info,
array $value = null,
array $args = null
): Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls, merge mainline
Magento\Framework\GraphQl\Query\ResolverInterface was changed
In this case we need to return string value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change returned value to string or array the test Magento\GraphQl\IntrospectionQueryTest::testIntrospectionQueryWithFieldArgs fails


class GenerateCustomerTokenTest extends GraphQlAbstract
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

@magento-engcom-team
Copy link
Contributor

@pfantini thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

try {
$token = $this->customerTokenService->createCustomerAccessToken($args['email'], $args['password']);
$result = function () use ($token) {
return !empty($token) ? $token : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to
return !empty($token) ? ['token' => $token] : '';

or Cannot return null for non-nullable field GenerateCustomerTokenOutput.token. error will appear

generateCustomerToken(
email: "{$userName}"
password: "{$password}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add token to subselection.

generateCustomerToken(
email: "{$userName}"
password: "{$password}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add token to subselection.


$response = $this->graphQlQuery($mutation);
$this->assertArrayHasKey('generateCustomerToken', $response);
$this->assertInternalType('string', $response['generateCustomerToken']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change 'string' to 'array'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants