Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda