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

172
Vistas
GraphQL type needs information from two APIs, don't want to make unnecessary many requests in resolver

I defined a type that relies on two different API endpoints. Let's call them A and B. For the query getObjects I want to return an array with objects of type SomeType

type SomeType{
   id: String // this comes from A
   url: String // this comes from B
  }

type Query{
       getObjects: [SomeType]
    }

I have a resolver for getObjects that retrieves data from endpoint A and feeds in SomeType to return an array. But I need to resolve the url separately, because the url comes from a endpoint B, right? Thus I write a resolver for the field url. But I don't want to make a request inside of resolver for url as it would mean that I make a request for each object from endpoint A (in my case ~ 18k). endpoint B returns an object with key-value pairs. The key is the id I get from endpoint A, and the value has the url.

const resolvers = {
        SomeType: {
            url: (parent, {}, context) => {
                console.log(parent.id); // parent.id is needed to index the 
                return someurl;
            } 
        },
        Query: {
            getObjects: async () => {
                const mainResponse = await fetch("endpoint A");
                const responseForLogo = await fetch("endpoint B")
    
                const mainData = await mainResponse.json();
                const secondaryData = await responseForLogo.json();
    
                return mainData['data'];
            },
        }
    }

But how can I efficiently get the Url for each object? One way I imagined was to make the request inside the getObjects resolver and store the response object and access it in the resolver for url.

Hope someone can help me with that.

about 4 years ago · Juan Pablo Isaza
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