Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[chore?]: Use createCustomer gql mutation instead of create-account REST endpoint #1898

Merged
merged 15 commits into from
Oct 22, 2019

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Oct 16, 2019

Description

This change replaces the old, unused email validation function and the createAccount redux/rest action with usage of the createCustomer mutation.

Related Issue

Closes #1210.

Acceptance

Verification Steps

  1. Go to /create-account and try to create an account with an email that is already used. You should see the new error.
  2. Go to the create account view in left nav and do the same. You should see the error.
  3. Now, in both views, try to create accounts with valid emails and it should succeed.

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@sirugh sirugh added the version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump. label Oct 16, 2019
@sirugh sirugh added the enhancement New feature or request label Oct 16, 2019
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Oct 16, 2019

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).

Generated by 🚫 dangerJS against 71b461b

… onSubmit handlers. Add local submitting state to disable button during submission
… error state better than using a specific isEmailAvailable query.
@@ -78,31 +78,6 @@ export const getUserDetails = () =>
}
};

export const createAccount = accountInfo => async dispatch => {
Copy link
Contributor Author

@sirugh sirugh Oct 17, 2019

Choose a reason for hiding this comment

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

It didn't make sense that the CreateAccount page took a callback that was just a reference to this action. In all scenarios, it was pulled off context and passed in anyways. I can't imagine a scenario where we would want to change the action passed in to the component. So now, the useCreateAccount talon uses the createCustomer mutation (no more REST!) And components that want to use the CreateAccount form can pass it a "post submit" callback.

Bye Felicia!

[createAccount, showMyAccount]
);
const handleCreateAccount = useCallback(() => {
showMyAccount();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See how this callback no longer cares about the createAccount action. So clean!

await signIn({
username: formValues.customer.email,
password: formValues.password
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic used to exist within the redux action but now lives in the talon!

@sirugh sirugh changed the title Validate email through graphql before submissission to create account endpoint [chore?]: Use createCustomer gql mutation instead of create-account REST endpoint Oct 17, 2019
Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

Dang, code looks great!

Haven't run the verification steps yet

@@ -0,0 +1,19 @@
mutation createAccount(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is the first mutation, I'm wondering if we shouldn't create a lib/mutations/ folder. It's a bit weird to read the import:

import CREATE_ACCOUNT_MUTATION from '../../queries/createAccount.graphql';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A mutation is just a type of query. I don't think we should do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Left more detail below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "a mutation is just a type of request"?

Copy link
Contributor

@supernova-at supernova-at Oct 21, 2019

Choose a reason for hiding this comment

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

Queries and Mutations are separate, special types that serve as entry points for the respective operations.

GraphQL and the Magento GraphQL schema separates Queries from Mutations, here's GraphiQL:

Screen Shot 2019-10-21 at 3 44 58 PM

Whether or not the front end splits these things up into queries and mutations directories is a discussion worth having, but GraphQL and our Magento GraphQL schema does separate them, so I assumed we would want to too, if only to reduce confusion when going back and forth.

Is it the worst thing in the world if a .graphql file in the queries/ directory contained addConfigurableProductsToCart? Probably not. 🤷‍♂


const LEAD =
'Check out faster, use multiple addresses, track orders and more by creating an account!';

const CreateAccount = props => {
const talonProps = useCreateAccount({
initialValues: props.initialValues
initialValues: props.initialValues,
query: CREATE_ACCOUNT_MUTATION,
Copy link
Contributor

Choose a reason for hiding this comment

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

Only because in GraphQL parlance "queries" and "mutations" are two distinctly separate things, this reads funny.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea -- I thought about changing the import name. I don't really think the UI needs to care about whether the query is a mutation/query/subscription.

I'd like to get @jimbo's take on naming here.

Copy link
Contributor

@supernova-at supernova-at Oct 21, 2019

Choose a reason for hiding this comment

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

👍 pending @jimbo 's verdict 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Whether or not the front end splits these things up into queries and mutations directories is a discussion worth having, but GraphQL and our Magento GraphQL schema does separate them, so I assumed we would want to too, if only to reduce confusion when going back and forth.

I'm pretty convinced by @supernova-at's argument here. As long as we have a queries folder, it makes sense have a mutations folder, since they're separate entities.

Since this is the first mutation, I'm wondering if we shouldn't create a lib/mutations/ folder.

That said, this is a reminder that there is no good reason to have a queries folder in the first place. Queries (and mutations) are supposed to be highly tailored to the component using them; it's not considered an optimization to reuse a query, so there's no value in keeping them in a shared folder.

Ideally, queries and mutations would reside in the component folder alongside .js and .css component files. If we're not going to do that, a mutations directory is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, this is a reminder that there is no good reason to have a queries folder in the first place.

I agree. I think we moved them into the queries/ folder maybe to make it easier on some tooling? I'm not sure.

How about this compromise - we merge this as is and I open an issue to move all the queries/mutations to the component folders where they are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made #1928 :D

supernova-at
supernova-at previously approved these changes Oct 21, 2019
] = useUserContext();
const hasError = !!createAccountError;
const [{ isSignedIn }, { signIn }] = useUserContext();
const [createAccount, { error }] = useMutation(query);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm so glad we didn't have mutations prior to official hooks. 😅

@dpatil-magento dpatil-magento merged commit bcfaf66 into develop Oct 22, 2019
@sirugh sirugh deleted the rugh/gql-validate-email branch March 4, 2020 18:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request pkg:peregrine pkg:venia-ui version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump.
Projects
None yet
6 participants