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

178
Visualizações
gatsby graphql Cannot query field "allTribeEvents" on type "Query"

I am using gatsby with wordpress to display events from the events calendar API of wordpress . I am using the plugin gatsby-source-tribe-events to access the allTribeEvents graphql field . The problem is that if I have no events posted on wordpress the field allTribeEvents is not created and then if I run my graphql query on gatsby I get

Cannot query field "allTribeEvents" on type "Query"

So my problem is how to check if the field exists in graphql and query conditionally based on it .

My code :

React component to display events :

export default function Events() {
 
const data  = useStaticQuery(graphql`
   query EventsQuery {
    allTribeEvents {
      ...
     }
    }`);

//then I return my component based on the data 
}

So the point is that if no posts exist "allTribeEvents" is not created in grapqhl and I get an error

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

0

So my problem is how to check if the field exists in graphql and query conditionally based on it .

Short answer, you can't. Essentially because when you query something, you expect some result. The problem here is that because of the defined worfklow (WordPress -> Gatsby -> GraphQL node creation), the steps are broken.

The ideal solution in this cases, is to define a Custom GraphQL Schema Definition that will help you to tell Gatsby that the allTribeEvents can be null.

Another possible workaround (far less clean) is to create an empty tribe event (maybe with empty spaces or with some kind of defined field) and treat it in the front-end to avoid printing it (let's say you have an event named "-", if you find that field in the GraphQL query, filter it).

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