-
Notifications
You must be signed in to change notification settings - Fork 687
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
Conversation
|
packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js
Outdated
Show resolved
Hide resolved
packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js
Outdated
Show resolved
Hide resolved
… 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 => { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 | ||
}); |
There was a problem hiding this comment.
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!
There was a problem hiding this 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( |
There was a problem hiding this comment.
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';
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left more detail below.
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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:
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 pending @jimbo 's verdict 😄
There was a problem hiding this comment.
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
andmutations
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made #1928 :D
packages/venia-ui/lib/components/CreateAccount/createAccount.js
Outdated
Show resolved
Hide resolved
] = useUserContext(); | ||
const hasError = !!createAccountError; | ||
const [{ isSignedIn }, { signIn }] = useUserContext(); | ||
const [createAccount, { error }] = useMutation(query); |
There was a problem hiding this comment.
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. 😅
Description
This change replaces the old, unused email validation function and the
createAccount
redux/rest action with usage of thecreateCustomer
mutation.Related Issue
Closes #1210.
Acceptance
Verification Steps
/create-account
and try to create an account with an email that is already used. You should see the new error.Screenshots / Screen Captures (if appropriate)
Checklist