FROM CACHE - en_header

Shopify GraphQL API to filter customers

Nabeel-iz
New Member
1 0 0

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 '

react-apollo

'

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:

response.png

 

Please do respond if anyone knows anything about this issue.

Thanks!

Replies 0 (0)