GraphQL checkout tutorial

Step 1. Create a customer

Customers can make purchases in two ways:

  • As a logged-in user
  • As a guest user who does not create an account

To place order as a new customer, use the createCustomer mutation to register the new customer account in the store.

Skip this step if you want to place order as a guest user.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mutation {
  createCustomer(
    input: {
      firstname: "John"
      lastname: "Doe"
      email: "john.doe@example.com"
      password: "b1b2b3l@w+"
      is_subscribed: true
    }
  ) {
    customer {
      id
      firstname
      lastname
      email
      is_subscribed
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "data": {
    "createCustomer": {
      "customer": {
        "id": 6,
        "firstname": "John",
        "lastname": "Doe",
        "email": "john.doe@example.com",
        "is_subscribed": true
      }
    }
  }
}

“Customer endpoint” describes additional createCustomer parameters.

To place an order as a new customer, you must get the customer’s authorization token. Use the generateCustomerToken mutation for that.

Request:

1
2
3
4
5
mutation {
  generateCustomerToken(email: "john.doe@example.com", password: "b1b2b3l@w+") {
    token
  }
}

Response:

1
2
3
4
5
6
7
{
  "data": {
    "generateCustomerToken": {
      "token": "zuo7zor5jfldft2nmu2gtylnm8ui7e8t"
    }
  }
}

“Get customer authorization token” describes the mutation further.

Verify this step

Sign in as a customer to the website using the email john.doe@example.com and password b1b2b3l@w+. You should be successfully logged in.