algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
177 stars 45 forks source link

No records with gatsby-source-wordpress quering #131

Closed dan-laskowski closed 3 years ago

dan-laskowski commented 3 years ago

Hi

I was trying to configure gatsby-plugin-algolia to query posts from wordpress and I am receiving no signals from algolia plugin - no logs when building, no records in algolia dashboard. What is wrong with my code? I work on localhost ;)

gatsby-config.js

const path = require("path");

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  siteMetadata: {
    siteUrl: process.env.SITE_URL,
    title: `Navigator blog`,
    description: `This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@daniello110`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-image`,
    `gatsby-plugin-sitemap`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/assets/images`,
      },
    },
    {
      resolve: `gatsby-plugin-root-import`,
      options: {
        src: path.join(__dirname, "src"),
        components: path.join(__dirname, "src/components"),
        assets: path.join(__dirname, "src/assets"),
        images: path.join(__dirname, "src/assets/images"),
        pages: path.join(__dirname, "src/pages"),
        templates: path.join(__dirname, "src/templates"),
        atoms: path.join(__dirname, "src/components/atoms"),
        molecules: path.join(__dirname, "src/components/molecules"),
        organisms: path.join(__dirname, "src/components/organisms"),
        utils: path.join(__dirname, "src/utils"),
      },
    },
    {
      resolve: `gatsby-plugin-algolia`,
      options: {
        appId: process.env.ALGOLIA_APP_ID,
        apiKey: process.env.ALGOLIA_API_KEY,
        indexName: process.env.ALGOLIA_INDEX_NAME,
        queries: require("./src/utils/algolia-queries"),
        skipIndexing: false,
        enablePartialUpdates: true,
        matchFields: ["dateGmt"],
      },
    },
    {
      resolve: `gatsby-source-wordpress`,
      options: {
        url: process.env.WP_ENDPOINT,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    `gatsby-plugin-styled-components`,
  ],
};

algolia-queries.js

const postQuery = `
{
    posts: allWpPost {
      nodes {
        objectID:id
        categories {
          nodes {
            name
            slug
            wpChildren {
              nodes {
                name
                slug
              }
            }
          }
        }
        title
        excerpt
        slug
        dateGmt
        tags {
          nodes {
            name
            slug
          }
        }
      }
    }
  }
`;

const queries = [
  {
    query: postQuery,
    transformer: ({ data }) => data.posts.nodes,
    settings: {
      attributesToSnippet: [`excerpt:20`],
    },
    matchFields: ["dateGmt"],
  },
];

module.exports = queries;

package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "@bogachenkov/react-scrolling-progress": "^1.0.1",
    "@material-ui/lab": "^4.0.0-alpha.57",
    "@splidejs/react-splide": "^0.4.4",
    "axios": "^0.21.1",
    "babel-plugin-styled-components": "^1.12.0",
    "dotenv": "^8.2.0",
    "gatsby": "^2.32.12",
    "gatsby-awesome-pagination": "^0.3.6",
    "gatsby-cli": "^3.3.0",
    "gatsby-plugin-algolia": "^0.17.0",
    "gatsby-plugin-gatsby-cloud": "^2.1.0",
    "gatsby-plugin-image": "^1.1.2",
    "gatsby-plugin-lunr": "^1.5.2",
    "gatsby-plugin-react-helmet": "^4.1.0",
    "gatsby-plugin-sharp": "^3.1.2",
    "gatsby-plugin-sitemap": "^3.1.0",
    "gatsby-plugin-styled-components": "^4.1.0",
    "gatsby-source-filesystem": "^3.1.0",
    "gatsby-source-graphql": "^3.2.0",
    "gatsby-source-wordpress": "^5.2.2",
    "gatsby-transformer-sharp": "^3.1.0",
    "gatsby-wordpress-search": "^1.0.9",
    "infinite-react-carousel": "^1.2.11",
    "js-search": "^2.0.0",
    "lunr": "^2.3.9",
    "prop-types": "^15.7.2",
    "react": "^17.0.1",
    "react-awesome-slider": "^4.1.0",
    "react-copy-to-clipboard": "^5.0.3",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "react-html-parser": "^2.0.2",
    "react-inlinesvg": "^2.2.2",
    "react-responsive-carousel": "^3.2.18",
    "react-scroll-progress-bar": "^1.1.13",
    "styled-components": "^5.2.1",
    "styled-reset": "^4.3.4"
  },
  "devDependencies": {
    "eslint": "^7.23.0",
    "eslint-config-react-app": "^6.0.0",
    "gatsby-plugin-root-import": "^2.0.6",
    "prettier": "2.2.1"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}
Haroenv commented 3 years ago

The algolia plugin needs to be instantiated after the Wordpress plugin. Unfortunately Gatsby plugins are loaded in order

dan-laskowski commented 3 years ago

I changed the order and still there is no records in dashboard.

Haroenv commented 3 years ago

Just checking, you are running Gatsby build right? is this reproducible if you use another source in the query? if so, please create a repo that reproduces the problem that I can run

dan-laskowski commented 3 years ago

You are right. I tried it on gatsby develop instead of gatsby build. Thank you for the help! :)

Haroenv commented 3 years ago

glad you found the issue!