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

Customer id doesn't match user id #90

Closed
rotexhawk opened this issue Jun 22, 2019 · 1 comment
Closed

Customer id doesn't match user id #90

rotexhawk opened this issue Jun 22, 2019 · 1 comment

Comments

@rotexhawk
Copy link

I am using this plugin and the recommended woocommerce plugin. The problem is that ids don't match so when a user logs in I save their id and when they are ready to checkout I query for customer(id: ID) but the problem is that these id's don't match. If you provide the default db id's graphql complains. Shouldn't they share the same ids?

Here is the result of the queries.

"data": {
    "customers": {
      "nodes": [
        {
          "email": "[email protected]",
          "username": "test",
          "id": "Y3VzdG9tZXI6Mg==",
          "customerId": 2
        },
"users": {
     "nodes": [
       {
         "email": "[email protected]",
         "username": "test",
         "id": "dXNlcjoy",
         "userId": 2
       },
@kidunot89
Copy link
Member

kidunot89 commented Jun 23, 2019

They don't match and this by design for both caching and object resolution. The User and Customer types are two different objects and should be used as such. Most, if not all, of the relative fields are accessible from the Customer type.

If you need more fields from the User type, you have two alternative options.

  1. Add them to the Customer type using register_graphql_types action, and registering the fields using the register_graphql_field() defined in WPGraphQL Recommended
  2. Run a second query using userBy( userId: customerId ). While the relay global IDs, a.k.a. id fields, are different on the two types, the customerId and userId are identical and can be use to query the the type using the customerBy and userBy queries.

If you have any problems you can reach out in Slack in the #woocommerce channel. I'll provide as much help as I can.

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

No branches or pull requests

2 participants