Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Query data with partial string match using GraphQL + Apollo client in Javascript

I have the following query:

function useAllOrders(ownerId, storeId) {
  const { data, loading, error } = useQuery(
    gql`
      query getOrders($ownerId: String!) {
        orders(query: { owner_id: $ownerId }) {
          _id
          // ... field list              
        }
      }
    `,
    { variables: { ownerId: `owner_id=${ownerId}&store_id=${storeId}` } }
  );
  if (error) {
    throw new Error(`Failed to fetch tasks: ${error.message}`);
  }
  const orders = data?.orders ?? [];
  return { orders, loading };
}

What I need to do is being able to query the order just by owner if storeId is null|undefined. That means that I should be able to do a partial find with owner_id=${ownerId}%. How can I achieve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming ownerId variable is a composite variable (odd) then

{ variables: { ownerId: `owner_id=${ownerId}&store_id=${storeId}` } }

would become

{ variables: { ownerId: `owner_id=${ownerId}${storeId ? `&store_id=${storeId}` : ''}` } }

You just need a conditional check when creating the variable's value.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!