|
| 1 | +import { makeAugmentedSchema } from '../../src/index'; |
| 2 | +import { ApolloServer } from 'apollo-server'; |
| 3 | +import neo4j from 'neo4j-driver'; |
| 4 | + |
| 5 | +const typeDefs = ` |
| 6 | +
|
| 7 | +type User { |
| 8 | + name: String! |
| 9 | + wrote: [Review] @relation(name: "WROTE", direction: "OUT") |
| 10 | + } |
| 11 | + type Review { |
| 12 | + date: Date! |
| 13 | + reviewId: String! |
| 14 | + stars: Float! |
| 15 | + text: String |
| 16 | + reviews: [Business] @relation(name: "REVIEWS", direction: "OUT") |
| 17 | + users: [User] @relation(name: "WROTE", direction: "IN") |
| 18 | + } |
| 19 | + type Category { |
| 20 | + name: String! |
| 21 | + business: [Business] @relation(name: "IN_CATEGORY", direction: "IN") |
| 22 | + } |
| 23 | + type Business { |
| 24 | + address: String! |
| 25 | + city: String! |
| 26 | + location: Point! |
| 27 | + name: String! |
| 28 | + state: String! |
| 29 | + in_category: [Category] @relation(name: "IN_CATEGORY", direction: "OUT") |
| 30 | + reviews: [Review] @relation(name: "REVIEWS", direction: "IN") |
| 31 | + } |
| 32 | +`; |
| 33 | + |
| 34 | +const schema = makeAugmentedSchema({ typeDefs }); |
| 35 | + |
| 36 | +const driver = neo4j.driver( |
| 37 | + 'neo4j://localhost:7687', |
| 38 | + neo4j.auth.basic('neo4j', 'letmein'), |
| 39 | + { encrypted: false } |
| 40 | +); |
| 41 | + |
| 42 | +// Create two separate servers by hardcoding value for context.neo4jDatabase |
| 43 | +// const sanmateoServer = new ApolloServer({ |
| 44 | +// schema, |
| 45 | +// context: { driver, neo4jDatabase: 'sanmateo' } |
| 46 | +// }); |
| 47 | + |
| 48 | +// sanmateoServer.listen(3003, '0.0.0.0').then(({ url }) => { |
| 49 | +// console.log(`San Mateo GraphQL API ready at ${url}`); |
| 50 | +// }); |
| 51 | + |
| 52 | +// const missoulaServer = new ApolloServer({ |
| 53 | +// schema, |
| 54 | +// context: { driver, neo4jDatabase: 'missoula' } |
| 55 | +// }); |
| 56 | + |
| 57 | +// missoulaServer.listen(3004, '0.0.0.0').then(({ url }) => { |
| 58 | +// console.log(`Missoula GraphQL API ready at ${url}`); |
| 59 | +// }); |
| 60 | + |
| 61 | +// Or we can add a header to the request |
| 62 | +const server = new ApolloServer({ |
| 63 | + schema, |
| 64 | + context: ({ req }) => { |
| 65 | + return { driver, neo4jDatabase: req.headers['x-database'] }; |
| 66 | + } |
| 67 | +}); |
| 68 | + |
| 69 | +server.listen(3003, '0.0.0.0').then(({ url }) => { |
| 70 | + console.log(`GraphQL API ready at ${url}`); |
| 71 | +}); |
0 commit comments