All things Shopify and commerce
Hi!
I have scaffolded a shopify project using shopify-cli. I am trying to query dummy customers of my store using GraphQL API. I want to query customers with varying parameters - first time on page load (react front-end) and second time on a user action (when user clicks on filter button after filling out the fields acting as filters), the query is successful first time but the app gets crashed if I call the same API with different filter parameters and I don't even get back any response.
Moreover, the same query works fine in the GraphQL playground installed as a shopify application.
Here is the query:
query GetCustomers($first: Int!, $reverse: Boolean!, $query: String) {
customers(
first: $first
sortKey: TOTAL_SPENT
reverse: $reverse
query: $query
) {
edges {
node {
id
displayName
ordersCount
totalSpent
}
}
}
}
`;
I am using useLazyQuery imported from '
'
const [
getCustomers,
{
loading: customersLoading,
error: customersError,
data,
networkStatus,
refetch,
},
] = useLazyQuery(GET_CUSTOMERS, {
fetchPolicy: "no-cache",
});
Here is the first query call:
useEffect(() => {
getCustomers({
variables: {
first: 7,
reverse: reverse,
query: "",
},
});
}, [reverse]);
Here is the second query call when user clicks on the filter button:
getCustomers({
variables: {
first: 7,
reverse: reverse,
query: "orders_count: '1'",
},
});
And here is what happens on the above call:
Please do respond if anyone knows anything about this issue.
Thanks!
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023