
This is an example of a Next.js application using AWS Neptune Analytics for creating, reading, updating, and deleting graph nodes and edges with OpenCypher queries.
Retrieve your existing graph ID and ensure proper AWS credentials are configured. Provide the graph ID after clicking "Deploy" to automatically set the environment variable.
Execute create-next-app with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/solutions/aws-neptune-analyticsneptune-graph:ReadDataViaQuery, neptune-graph:WriteDataViaQuery and neptune-graph:DeleteDataViaQuery.env.local file and add your graph ID:
GRAPH_ID=your-graph-id-hereexport GRAPH_ID=your-graph-id-herepnpm dev to start the Next app at http://localhost:3000Deploy it to the cloud with Vercel (Documentation).
AWS credentials (e.g. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) and region configuration (e.g. AWS_REGION) can be used directly as environment variables for Vercel deployments.
The AWS SDK will automatically pick up these credentials from the environment:
const client = new NeptuneGraphClient({})The application provides a RESTful API for graph node and edge operations:
GET /api/node?id={id} - Retrieve a node by IDPOST /api/node - Create a new nodePUT /api/node - Update an existing nodeDELETE /api/node?id={id} - Delete a node and its relationshipsGET /api/edge?id={id} - Retrieve an edge by IDPOST /api/edge - Create a new edgePUT /api/edge - Update an existing edgeDELETE /api/edge?id={id} - Delete an edgecurl -X POST http://localhost:3000/api/node \ -d '{"id": "user-123", "name": "John Doe", "type": "user"}' \ -H "Content-type: application/json"curl "http://localhost:3000/api/node?id=user-123"curl -X PUT http://localhost:3000/api/node \ -d '{"id": "user-123", "name": "John Smith", "type": "user", "active": true}' \ -H "Content-type: application/json"curl -X DELETE "http://localhost:3000/api/node?id=user-123"curl -X POST http://localhost:3000/api/edge \ -d '{"fromId": "user-123", "toId": "user-456", "type": "FOLLOWS"}' \ -H "Content-type: application/json"curl "http://localhost:3000/api/edge?id=follows-001"curl -X PUT http://localhost:3000/api/edge \ -d '{"id": "follows-001", "since": "2024-01-15", "strength": "strong"}' \ -H "Content-type: application/json"curl -X DELETE "http://localhost:3000/api/edge?id=follows-001"