Skip to content

Commit

Permalink
feat(core): add get customer query (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurytut1993 committed Apr 16, 2024
1 parent 30c7624 commit 39feb4a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-adults-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

add get customer query
60 changes: 60 additions & 0 deletions apps/core/client/queries/get-customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { cache } from 'react';

import { client } from '..';
import { graphql } from '../graphql';

const GET_CUSTOMER_QUERY = graphql(`
query getCustomer {
customer {
entityId
company
email
firstName
lastName
phone
formFields {
entityId
name
__typename
... on CheckboxesFormFieldValue {
valueEntityIds
values
}
... on DateFormFieldValue {
date {
utc
}
}
... on MultipleChoiceFormFieldValue {
valueEntityId
value
}
... on NumberFormFieldValue {
number
}
... on PasswordFormFieldValue {
password
}
... on TextFormFieldValue {
text
}
}
}
}
`);

export const getCustomer = cache(async (customerId: string) => {
const response = await client.fetch({
document: GET_CUSTOMER_QUERY,
fetchOptions: { cache: 'no-store' },
customerId,
});

const customer = response.data.customer;

if (!customer) {
return null;
}

return customer;
});

0 comments on commit 39feb4a

Please sign in to comment.