Please check if I have defined the schema correctly or not? Neptune schema creation failed: TypeError: g.V(...).hasLabel(...).as(...).V(...).hasLabel(...).as(...).addE(...).from is not a function
0
I am using gremlin to define schema in my nodejs project using AWS sdk and the initial connection I have established using NeptuneClient.
const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const createNodes = require('./nodes');
const createEdges = require('./edges');
const dotenv = require('dotenv');
dotenv.config();
async function createNeptuneSchema() {
const ClusterEndpoint = process.env.CLUSTER_ENDPOINT;
const Port = 8182;
const dc = new DriverRemoteConnection(`wss://${ClusterEndpoint}:${Port}/gremlin`, {});
const g = new gremlin.structure.Graph().traversal().withRemote(dc);
// Create nodes
await createNodes(g);
// Create edges
await createEdges(g);
console.log('Schema creation complete.');
dc.close();
}
module.exports = createNeptuneSchema;
nodes.js
const gremlin = require("gremlin");
async function createNodes(g) {
// Define Company node with attributes
await g
.addV("Company")
.property("companyNumber", "string")
.property("companyType", "string")
.property("registryURL", "string")
.property("incorporationDate", "date")
.property("dissolutionDate", "date")
.property("status", "string")
.property("employeeCount", "integer")
.property("annualRevenue", "decimal")
.property("taxNumber", "string")
.property("industry", "string")
.property("DUNSNumber", "string")
.property("legalEntityIdentifier", "string")
.property("aliasName", "string")
.property("reliabilityScore", "decimal")
.next();
// Define Address node with attributes
await g
.addV("Address")
.property("line1", "string")
.property("line2", "string")
.property("city", "string")
.property("state", "string")
.property("postcode", "string")
.property("reliabilityScore", "decimal")
.next();
// Define TradingAddress node with attributes
await g
.addV("TradingAddress")
.property("fromDate", "date")
.property("toDate", "date")
.next();
// Define PreviousAddress node with attributes
await g
.addV("PreviousAddress")
.property("fromDate", "date")
.property("toDate", "date")
.next();
// Define CurrentAddress node with attributes
await g
.addV("CurrentAddress")
.property("fromDate", "date")
.property("toDate", "date")
.next();
// Define Country node
await g
.addV("Country")
.property("name", "string")
.property("lat", "string")
.property("lng", "string")
.next();
// Define PEP node with attributes
await g
.addV("PEP")
.property("politicalPosition", "string")
.property("gender", "string")
.property("DOB", "date")
.property("URL", "string")
.property("chamber", "string")
.property("otherInfo", "string")
.property("institutionType", "string")
.property("function", "string")
.next();
await g.addV("PoliticalParty").next();
// Define Sanctions node with attributes
await g
.addV("Sanctions")
.property("listName", "string")
.property("listURL", "string")
.property("listDate", "date")
.property("removeDate", "date")
.property("relatedURL", "string")
.property("program", "string")
.property("remark", "string")
.next();
await g.addV("Offshore").next();
await g.addV("News").next();
await g.addV("SearchEngineMedia").next();
// Define Adverse Media node with attributes
await g
.addV("AdverseMedia")
.property("URL", "string")
.property("title", "string")
.property("snippit", "string")
.property("publicationDate", "date")
.property("source", "string")
.property("risk", "string")
.property("publisherName", "string")
.property("factivaDocumentId", "string")
.property("language", "string")
.property("imageLink", "string")
.next();
// Define Dark Web node with attributes
await g
.addV("DarkWeb")
.property("name", "string")
.property("email", "string")
.property("phone", "string")
.property("username", "string")
.next();
// Define Person node with attributes
await g
.addV("Person")
.property("firstName", "string")
.property("middleName", "string")
.property("lastName", "string")
.property("DOB", "date")
.next();
// Define Filing node with attributes
await g
.addV("Filing")
.property("filingType", "string")
.property("description", "string")
.property("date", "date")
.property("title", "string")
.property("source", "string")
.next();
// Define Email node with attributes
await g
.addV("Email")
.property("domain", "string")
.property("type", "string")
.property("reliabilityScore", "decimal")
.next();
// Define PhoneNumber node with attributes
await g
.addV("PhoneNumber")
.property("countryCode", "string")
.property("number", "string")
.property("type", "string")
.property("reliabilityScore", "decimal")
.next();
// Define URL node
await g.addV("URL").property("link", "string").next();
// Define School node with attributes
await g.addV("School").property("name", "string").next();
// Define Friend node
await g.addV("Friend").next();
// Define Website node
await g.addV("Website").property("link", "string").next();
// Define Risk node
await g.addV("Risk").next();
// Define Skill node with attributes
await g.addV("Skill").property("name", "string").next();
await g.addV("Location").next();
// Define Education node with relationships
await g.addV("Education").next();
// Define Employment node with relationships
await g.addV("Employment").next();
// Define SocialMedia node with attributes
await g
.addV("SocialMedia")
.property("platform", "string")
.property("bio", "string")
.property("profileID", "string")
.property("isBusinessAccount", "boolean")
.next();
// Define Social Post node with attributes
await g
.addV("SocialPost")
.property("risk", "string")
.property("type", "string")
.next();
// Define Lawsuit node with attributes
await g.addV("Lawsuit").property("type", "string").next();
// Define Case node
await g.addV("Case").next();
// Define Court Record node with attributes
await g
.addV("CourtRecord")
.property("courtCaseNumber", "string")
.property("sourceCaseNumber", "string")
.property("natureOfAction", "string")
.property("caseTitle", "string")
.property("filingDate", "date")
.property("status", "string")
.property("caseType", "string")
.property("isLawsuit", "boolean")
.property("courtType", "string")
.property("dockets", "string")
.next();
// Define Court node with attributes
await g
.addV("Court")
.property("courtType", "string")
.property("system", "string")
.property("name", "string")
.property("alternateName", "string")
.next();
console.log("Nodes creation complete.");
}
module.exports = createNodes;
Edges.js
const gremlin = require('gremlin');
const createNodes = require('./nodes');
async function createEdges(g) {
// Import nodes creation function
await createNodes(g);
// Define edge relationships
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Email').as('email')
.addE('hasEmail').from('person').to('email')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('PhoneNumber').as('phoneNumber')
.addE('hasPhoneNumber').from('person').to('phoneNumber')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Address').as('address')
.addE('hasAddress').from('person').to('address')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Company').as('company')
.addE('hasEmployment').from('person').to('company')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('School').as('school')
.addE('hasEducation').from('person').to('school')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Person').as('friend')
.addE('hasFriend').from('person').to('friend')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('SocialMediaAccount').as('socialMediaAccount')
.addE('hasSocialMediaAccount').from('person').to('socialMediaAccount')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Website').as('website')
.addE('hasWebsite').from('person').to('website')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Risk').as('risk')
.addE('hasRisk').from('person').to('risk')
.next();
await g.V().hasLabel('Person').as('person')
.V().hasLabel('Skill').as('skill')
.addE('hasSkill').from('person').to('skill')
.next();
await g.V().hasLabel('Company').as('company')
.V().hasLabel('Address').as('address')
.addE('hasAddress').from('company').to('address')
.next();
await g.V().hasLabel('Company').as('company')
.V().hasLabel('TradingAddress').as('tradingAddress')
.addE('hasTradingAddress').from('company').to('tradingAddress')
.next();
await g.V().hasLabel('Company').as('company')
.V().hasLabel('PreviousAddress').as('previousAddress')
.addE('hasPreviousAddress').from('company').to('previousAddress')
.next();
await g.V().hasLabel('Company').as('company')
.V().hasLabel('CurrentAddress').as('currentAddress')
.addE('hasCurrentAddress').from('company').to('currentAddress')
.next();
asked 4 months ago93 viewslg...
No Answers
- Newest
- Most votes
- Most comments
Relevant content
- asked 7 months agolg...
- Accepted Answerasked 4 months agolg...
- asked 2 years agolg...
- Accepted Answerasked 4 months agolg...
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
Do you have the full stack trace of the error that you're seeing? Which file and line number is it coming from? Nothing is really standing out as a syntactic issue here. I would reiterate my previous response on making sure you use labels and IDs correct. The way this currently reads, you're doing a lot of cross join connecting between vertex types. See my previous response: https://repost.aws/questions/QUNmDdzw2aQO-FdFDz-m9Ewg/how-to-define-schema-when-using-neptune-client-aws-javascript-sdk#ANLnk78-9uTMGl3X-tVlJ8UA