Here is the code snip of my node.js service, I want to filter Brand based on node labels, like Brand_Active.
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const { Neo4jGraphQL } = require('@neo4j/graphql');
const neo4j = require('neo4j-driver');
const { OGM, cypher } = require("@neo4j/graphql-ogm");
// Connect to Neo4j database
const driver = neo4j.driver(
'neo4j+s://localhost:80',
neo4j.auth.basic('abc', 'abc')
);
// Define GraphQL schema
const typeDefs = gql`
type Brand {
name: String!
url: String
# Add fields for other node labels here
}
type Query {
brands(nodeLabels: [String!]!): [Brand!]!
}
`;
// Initialize OGM (Object-Graph Mapping) for Neo4j
const ogm = new OGM({ typeDefs, driver });
const session = driver.session();
// Create resolvers
const resolvers = {
Query: {
brands: async (_parent, { nodeLabels }) => {
await ogm.init();
const Brand = ogm.model("Brand");
const [brands] = await Brand.find({labels: { _in: nodeLabels }});
console.log([brands]);
return [brands];
}
}
};
// Create an ApolloServer instance with Neo4jGraphQL
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ req, cypher: ogm }),
});
/**
* Main program
*
* @returns {boolean} success status
*/
const main = async () => {
await server.start();
const app = express();
server.applyMiddleware({ app });
// Start the server
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}${server.graphqlPath}`);
});
};
(async () => {
await main();
})();