1

The detail of the problem is that I'm not getting the data we expected within our code. We have set up the following to see within our project folder.

Within webpack.config.js we set up resolve.alias in the webpack configuration, so we can include it in the resolve object of the webpack config file.

enter image description here

This is the file:

module.exports = {
  // other webpack config options
  resolve: {
    alias: {
      // Create an alias for the queries folder
      queries: path.resolve(__dirname, 'src/queries'),
    },
  },
};

This is what are path name will look like:

import { homeQuery } from "queries/navigation/homeLinks";
  1. Created a webpack.config.js.
  2. Console.log are data of homeData and HomeData.homelink.
  3. Tested the query within GraphQL Playground in Hygraph.

From there I checked the console in the browser.

I have found out we are not getting the query in our body that we want but we have tested the query within GraphQL Playground. We have found out that we correctly getting the correct query that we want to get into our data within console.log.

enter image description here

This is a query for the homepage:

import { gql } from "@apollo/client";

export const homeQuery = gql`
    query homeLinks {
        pages(
            where: {id: "clbzl7ovpe64d0ak5qh7o2p8f", slug: "Home"}
            stage: PUBLISHED
            locales: en
        ) {
            id
            slug
            title
        }
    }`
; 

This where we console are data for the homepage:

 console.log(homeData && homeData?.homeLink?.pages);
 console.log(homeData)
import React from 'react';
import '../assets/style/navigation.css';
import { useQuery } from '@apollo/client'; 
import { BrowserRouter as Router, Link } from 'react-router-dom';

import { homeQuery } from "../queries/navigation/homeLinks";

import { logoassetsQuery } from "../queries/navigation/logoLinks";

export default function App() {

  const { loading: logoAssetsLoading, error: logoassetsData } = useQuery(logoassetsQuery);
  
  //This is query for the pages.
  const { loading: homeLoading, error: homeError, data: homeData } = useQuery(homeQuery);
  
  //This is for front-end error message.
  if (logoAssetsLoading) return <p>Loading Logo Assets...</p>; 
  if (homeLoading) return <p>Loading... this page links.</p>
  if (homeError) return <p>Error :( this page don't work.</p>; 

  // Debugging step 1: Check the value of data.navigation
  console.log(homeData && homeData.homeLinks)
  console.log(homeData)
  
  // Debugging step 2: Check the value of data
  //console.log(data);
    

  return (
    <div className='navigation'>
      <div className='full_width_container'>
        <div className='wrapper'>
          <Router>
              <React.Fragment>
                  <nav>
                      <div className='nav_groups logo'>
                          {homeData && homeData?.homeLinks?.pages && homeData?.homeLinks?.page(link => (
                              <li key={link?.id}>
                                <Link to={`/${link?.slug}`}>
                                  <img src={logoassetsData?.logoAssets} alt='main logo'/>
                                </Link>
                              </li>
                          ))}
                      </div>
                  </nav>
              </React.Fragment>
          </Router>
      </div>
    </div>
  </div>
  );
}



  • I have tried to console.log props in the export default function App(props) but don't understand the console or DevTool that much still learning Debugging – Perceptor Dev Jan 02 '23 at 23:29
  • We get an array of pages but it's empty array don't understand why. We have done `console.log(homeData)` but don't know why this happening. – Perceptor Dev Jan 03 '23 at 17:03
  • 1
    Where the homeData is coming from and Can you share the strucutre of ```homeData``` and a neat logs of your ```console.log(homeData)``` and ```console.log(data)``` – Satyam Saurabh Jan 04 '23 at 07:51
  • 1
    and also can you in the network if the request query is being processed or not? – Satyam Saurabh Jan 04 '23 at 07:52
  • So data is not defined but the one that is defined is `console.log(homeData);` and `console.log(homeData && homeData?.homeLink?.pages);` The screenshot have show that it being processed but not display on front-end has want right now I have updated the code `homeData && homeData?.homeLinks?.pages && homeData?.homeLinks?.page` I think that changed fixed issue but now figure out why not display on front-end. – Perceptor Dev Jan 04 '23 at 09:49
  • https://gyazo.com/9fe94944d03734aac023e71406ddd49a – Perceptor Dev Jan 04 '23 at 09:49
  • https://gyazo.com/9fe94944d03734aac023e71406ddd49a – Perceptor Dev Jan 04 '23 at 09:49
  • Will post another question to let everyone now. It's fixed – Perceptor Dev Jan 04 '23 at 13:41

0 Answers0