11import { neo4jgraphql } from '../../src/index' ;
2+ import { PubSub } from 'apollo-server' ;
3+
4+ export const pubsub = new PubSub ( ) ;
25
36export const typeDefs = `
47type Movie {
@@ -13,13 +16,13 @@ type Movie {
1316 poster: String
1417 imdbRating: Float
1518 ratings: [Rated]
16- genres: [Genre] @relation(name: "IN_GENRE", direction: " OUT" )
19+ genres: [Genre] @relation(name: "IN_GENRE", direction: OUT)
1720 similar(first: Int = 3, offset: Int = 0, limit: Int = 5): [Movie] @cypher(statement: "MATCH (this)--(:Genre)--(o:Movie) RETURN o LIMIT $limit")
1821 mostSimilar: Movie @cypher(statement: "RETURN this")
1922 degree: Int @cypher(statement: "RETURN SIZE((this)--())")
20- actors(first: Int = 3, offset: Int = 0): [Actor] @relation(name: "ACTED_IN", direction:"IN" )
23+ actors(first: Int = 3, offset: Int = 0): [Actor] @relation(name: "ACTED_IN", direction:IN )
2124 avgStars: Float
22- filmedIn: State @relation(name: "FILMED_IN", direction: " OUT" )
25+ filmedIn: State @relation(name: "FILMED_IN", direction: OUT)
2326 location: Point
2427 locations: [Point]
2528 scaleRating(scale: Int = 3): Float @cypher(statement: "RETURN $scale * this.imdbRating")
@@ -29,7 +32,7 @@ type Movie {
2932
3033type Genre {
3134 name: String
32- movies(first: Int = 3, offset: Int = 0): [Movie] @relation(name: "IN_GENRE", direction: "IN" )
35+ movies(first: Int = 3, offset: Int = 0): [Movie] @relation(name: "IN_GENRE", direction: IN )
3336 highestRatedMovie: Movie @cypher(statement: "MATCH (m:Movie)-[:IN_GENRE]->(this) RETURN m ORDER BY m.imdbRating DESC LIMIT 1")
3437}
3538
@@ -45,8 +48,8 @@ interface Person {
4548type Actor {
4649 id: ID!
4750 name: String
48- movies: [Movie] @relation(name: "ACTED_IN", direction: " OUT" )
49- knows: [Person] @relation(name: "KNOWS", direction: " OUT" )
51+ movies: [Movie] @relation(name: "ACTED_IN", direction: OUT)
52+ knows: [Person] @relation(name: "KNOWS", direction: OUT)
5053}
5154
5255type User implements Person {
@@ -115,10 +118,10 @@ type NewCamera implements Camera {
115118type CameraMan implements Person {
116119 userId: ID!
117120 name: String
118- favoriteCamera: Camera @relation(name: "favoriteCamera", direction: " OUT" )
121+ favoriteCamera: Camera @relation(name: "favoriteCamera", direction: OUT)
119122 heaviestCamera: [Camera] @cypher(statement: "MATCH (c: Camera)--(this) RETURN c ORDER BY c.weight DESC LIMIT 1")
120- cameras: [Camera!]! @relation(name: "cameras", direction: " OUT" )
121- cameraBuddy: Person @relation(name: "cameraBuddy", direction: " OUT" )
123+ cameras: [Camera!]! @relation(name: "cameras", direction: OUT)
124+ cameraBuddy: Person @relation(name: "cameraBuddy", direction: OUT)
122125}
123126
124127union MovieSearch = Movie | Genre | Book | User | OldCamera
@@ -135,12 +138,23 @@ type Query {
135138}
136139
137140type Mutation {
141+ CustomWithPublish: String @publish(event: "customEventName") @cypher(statement: "RETURN 'hello world'")
138142 CustomCamera: Camera @cypher(statement: "CREATE (newCamera:Camera:NewCamera {id: apoc.create.uuid(), type: 'macro'}) RETURN newCamera")
139143 CustomCameras: [Camera] @cypher(statement: "CREATE (newCamera:Camera:NewCamera {id: apoc.create.uuid(), type: 'macro', features: ['selfie', 'zoom']}) CREATE (oldCamera:Camera:OldCamera {id: apoc.create.uuid(), type: 'floating', smell: 'rusty' }) RETURN [newCamera, oldCamera]")
140144}
145+
146+ type Subscription {
147+ subscribeToCustomWithPublish: String @subscribe(to: "customEventName")
148+ }
141149` ;
142150
143151export const resolvers = {
152+ Subscription : {
153+ // normally generated
154+ subscribeToCustomWithPublish : {
155+ subscribe : ( ) => pubsub . asyncIterator ( [ 'customEventName' ] )
156+ }
157+ } ,
144158 // root entry point to GraphQL service
145159 Query : {
146160 Movie ( object , params , ctx , resolveInfo ) {
0 commit comments