Created
November 17, 2021 14:11
-
-
Save danstarns/aca3b54c96e52b6dc2bcde8e58db3074 to your computer and use it in GitHub Desktop.
neo4j-graphql-aggregate-with-ogm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { OGM } = require("@neo4j/graphql"); | |
| const neo4j = require("neo4j"); | |
| const typeDefs = gql` | |
| type Movie { | |
| released: BigInt! | |
| tagline: String | |
| title: String! | |
| ## Rest of the Relationships | |
| } | |
| ## Rest of the Definitions | |
| `; | |
| const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("admin", "password")); | |
| const ogm = new OGM({ | |
| typeDefs, | |
| driver, | |
| }); | |
| const Movie = ogm.model("Movie"); | |
| const aggregation = await Movie.aggregate({ | |
| aggregate: { | |
| title: { | |
| shortest: true, | |
| longest: true, | |
| }, | |
| }, | |
| }); | |
| console.log(aggregation); | |
| /* | |
| Logs: { | |
| "title": { | |
| "shortest": "Hoffa", | |
| "longest": "One Flew Over the Cuckoo's Nest" | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment