graphile / gatsby-source-pg

PostgreSQL source for Gatsby, powered by PostGraphile
36 stars 15 forks source link

Get nodes created by plugin by their type #26

Open snussik opened 3 years ago

snussik commented 3 years ago

If I explore data, created by plugin, I can find:

postgres (PostGraphile) {
    allElements (PostGraphile_ElementsConnection) {
      nodes (PostGraphile_Element) {
        ....
      }
    }
  }

And I even can modify these nodes like this:

exports.createResolvers = ({ createResolvers }) => {
    createResolvers({
    PostGraphile_Element: {
    internal: {
        type: `Internal`,
        resolve: object => {
            return {
                type: `pgData`,
            }
        }
    }
  },
});
}

But if I try to use this node in other places with constructions:

if (node.internal.type === `pgData`) {
       // do smth..
    }
const nodes =  getNodesByType(`pgData`)) || getNodesByType(`PostGraphile_Element`)) 

I get nothing.

So, If I want to build lunr index from nodes with lunr-plugin I try to use such syntax, as described in its rtfm for gatsby-config.js:

{
    resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
    options: {
      fields: [`name`],
      // How to resolve each field`s value for a supported node type
      resolvers: {
        PostGraphile_Element: {
        name: node => node.name,
        }, 
        // Or try to use my crated internal.type:
        pgData: {
          name: node => node.name,
        },
      },
    },
  },

The question is for I can get created child nodes by their type PostGraphile_Element or pgData