How to connect to AuraDB from a Gatsby-based pages

How to connect to AuraDB from a Gatsby-based pages


0

I’m building a website with Gatsby. It will be fully static.
I use a Neo4J base hosted (aka an AuraDB free instance) to store data needed for the website.

I’m trying to get things working together but I end up with a 403 when trying to get some data from the DB.

Beginning of my gatsby-node.js

const neo4j = require('neo4j-driver');
const neo4jUri = 'neo4j+s://myurl.io';
const neo4jUser = 'myneo4juser';
const neo4jPassword = 'mypassword';
const driver = neo4j.driver(neo4jUri, 
neo4j.auth.basic(neo4jUser, neo4jPassword));
const session = driver.session();
session
  .run('MATCH (n:Node) RETURN n')
  .then((result) => {
    result.records.forEach((record) => {
      const nodeData = record.get('n').properties;
      console.log("DEALING WITH A NODE");
      const node = {
        ...nodeData,
        // Define required fields such as id, parent, children, etc.
        id: `${nodeData.id}`,
        parent: null,
        children: [],
        internal: {
          type: 'Neo4jNodeTEST', // Define your node type
          content: JSON.stringify(nodeData),
          contentDigest: createContentDigest(nodeData),
        },
      };
    
      // Create the Gatsby node
      createNode(node);
    });
  })
  .catch((error) => {
    console.error('Error executing Neo4j query', error);
  })
  .finally(() => {
    console.log('closing neo4j session');
    session.close();
  });
(...)

And the plugin part of gatsby-config.js if it’s helping

plugins: [
    "gatsby-plugin-sitemap",
    "gatsby-plugin-sass",
    `gatsby-transformer-yaml`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/content/`,
      },
    },
    {
      resolve: "gatsby-source-graphql",
      options: {
        // Arbitrary name for the remote schema Query type
        typeName: "allCompanyRepoYaml",
        // Field under which the remote schema will be accessible. You'll use this in your Gatsby query
        fieldName: "edges",
        // Url to query from
        url: "https://api.neo4j.io",
      },
    },
  ]

Any idea on when I should investigate to make things work?


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *