Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda