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

212
Visualizações
TypeError: Cannot read properties of undefined (reading 'document')

I was using qraphql (JavaScript graphql-request library) in a project and ran into a typeError. Here's the code:

import { request, gql } from 'graphql-request'
const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT
export const getPosts = async () => {
    const query = gql`
    query MyQuery {
        postsConnection {
          edges {
            node {
              author {
                bio
                name
                id
                photo {
                  url
                }
              }
              createdAt
              slug
              title
              excerpt
              featuredImage {
                url
              }
              categories {
                name
                slug
              }
            }
          }
        }
      }
 `     
    const result = await request(graphqlAPI, query)

    return result.postsConnection.edges
}

The error said there was a problem with the document parameter of the request.

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

0

2 Errors:

  1. The method which you have used here to fetch the data is outdated.
  2. The endpoint here is missing you will find it in the graphcms in your account : settings/access/api access /endpoints

Remove the command

const graphqlAPI = process.env.NEXT_PUBLIC_GRAPHCMS_ENDPOINT

and the .env file associated with it. After that use the following code:

import { gql } from 'graphql-request';
import { GraphQLClient } from 'graphql-request';

export const getPosts = async () => {
    
    // new endpoint
    const graphQLClient = new GraphQLClient(
        endpoint // here add your endpoint
    );

    const query = gql`
    query MyQuery {
        postsConnection {
            edges {
                node {
                    author {
                        bio
                        name
                        id
                        photo {
                            url
                        }
                    }
                    createdAt
                    slug
                    title
                    excerpt
                    featuredImage {
                        url
                    }
                    categories {
                        name
                        slug
                    }
            }
        }
        }
    }
    `
    const result = await graphQLClient.request(query)
    return result.PostsConnection;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Never Mind, its because the Next_endpoint wasnt defined, all good now!

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