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

206
Visualizações
Query relationships within Apollo/Client

I am trying to query my categories within my product. I created a table in which I want to see the categories of my product table. I am using Prisma as my typeORM and Apollo as a way to query my Postgres database. Please see the attached photo of my table. I have categories that are within my Product model.

Here is my query function using my UseQuery Hook from Apollo/Client.

const AllProductsQuery = gql`
    query {
        products {
            id
            name
            description
            img
            price
            ingredients
        
            categories {
                id
                name
            }
        }
    }
`

What I thought this would do was since I am querying the categories within the products I would be able to hit that information. However, it isn't even console logging that data.

This is what I have

<Table  striped bordered hover >
                <thead>
                <tr>
                 <th>Product</th>
                 <th>Category</th>
                 <th>Price</th>
                 
                 </tr>
                </thead>
                
               
        {data  && data.products.map((product: Product, categories: Category) => {
            return (
                
              
               <tbody>
                <tr>
                    <td>{product.name}</td>
                    <td>{product.categories.name}</td>
                    <td>{product.price}</td>
                </tr>
                </tbody>
             
               
               
              
            )
            
        })}
        
        </Table>

However this doesn't even show the categories information within my products within the console log. The Product.name and Product.price work perfectly however, I try to run the same thing with product.categories.name doesn't work. Any information would be great!

Image of my Table

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In this code that you sent you're renaming product to Product in the data.products.map.

If you received categories from server, as I asked you in the comment, try this code

      <Table striped bordered hover>
        <thead>
          <tr>
            <th>Product</th>
            <th>Category</th>
            <th>Price</th>
          </tr>
        </thead>

        {data &&
          data.products.map((product) => {
            return (
              <tbody>
                <tr>
                  <td>{product.name}</td>
                  <td>{product.categories.name}</td>
                  <td>{product.price}</td>
                </tr>
              </tbody>
            );
          })}
      </Table>
about 4 years ago · Juan Pablo Isaza Relatório
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