kmcaloon / gatsby-plugin-groq

Gatsby plugin for using GROQ in place of GraphQL
MIT License
36 stars 2 forks source link

Not getting any data back in production? #8

Open Twoy519 opened 3 years ago

Twoy519 commented 3 years ago

Hi! Hey this doesn't seem to be a very google-able plugin so thought I'd ask here about how to debug. I am using Sanity as my CMS.

I'm getting data back when I'm on localhost but when I deploy on netlify I'm not getting any data back on the production site?

I'm pretty new to web dev in general so don't know the right things to look for to debug this and was just looking for general advice?

gatsby-config.js

{
  resolve: `gatsby-plugin-groq`,
  options: {
    referenceMatcher: 'id',
    autoRefs: false,
  },
},

I'm using static queries on pages that are built via createPages in gatsby-node.js. So for example I have just a simple "site directory" list with like the standard "about", "contact" etc. pages. I'm then querying Sanity for the content to put on the pages.

So gatsby-node.js:

async function turnPagesIntoPages({ graphql, actions }) {
  // 1. get template for page.
  const pageTemplate = path.resolve('./src/templates/Page.js');

  // 2. query all pages
  const { data } = await graphql(`
    query {
      pages: allSanityPage {
        nodes {
          name
          slug {
            current
          }
        }
      }
    }
  `);

  // 3. Loop over each page and create a page for it
  data.pages.nodes.forEach((page) => {
    actions.createPage({
      path: `${page.slug.current}`,
      component: pageTemplate,
      context: {
        name: page.name,
      },
    });
  });
}

Then the Page.js Component:

...
import { useGroqQuery } from 'gatsby-plugin-groq';

export default function Page({ data }) {
  const pages = useGroqQuery(`
    *[_type == "page"]
  `);
  console.log({ pages });

  const page = pages.filter((i) => i.slug.current === data.page.slug.current);

  return (
    <div>
      {page[0]?.body ? (
        <PortableText blocks={page[0].body} serializers={serializers} />
      ) : (
        <p>Page coming soon 😃</p>
      )}
    </div>
  );
}

So when I see that console.log in my netlify its empty, but this works on localhost.

As I said I'm really new to this so lmk what else I can provide to help debug?

kmcaloon commented 2 years ago

Hey @Twoy519 sorry I never got back to you on this. Since starting to build this out there have been many life and work changes, and honestly I haven't been too involved in the Gatsby ecosystem as I was. I'm sure you have moved on by now but didn't want to leave this hanging. Maybe some time soon I can revisit this plugin.

Also, hope you've been progressing and are enjoying your web dev journey 💪