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
import * as mongoose from 'mongoose'; | |
function timestamp() { | |
return +new Date(); | |
} | |
export interface MessageDocument extends mongoose.Document { | |
sender_id: string; | |
senderName: string; | |
text: string; |
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
{ | |
[...] | |
"scripts": { | |
[...] | |
"codegen": "graphql-codegen --config codegen.yml" | |
}, | |
[...] | |
} |
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
overwrite: true | |
schema: "http://localhost:5000/graphql" | |
documents: null | |
generates: | |
src/generated/graphql.ts: | |
plugins: | |
- "typescript" | |
- "typescript-resolvers" | |
config: | |
useIndexSignature: true |
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
{ | |
"scripts": { | |
"build": "tsc -p tsconfig.json", | |
"build:watch": "tsc -w -p tsconfig.json", | |
"start:dev": "NODE_ENV=development nodemon build/server.js", | |
"start:prod": "NODE_ENV=production nodemon build/server.js", | |
"start:production": "concurrently \"yarn build:watch\" \"yarn start:prod\"", | |
"start": "concurrently \"yarn build:watch\" \"yarn start:dev\"", | |
}, | |
} |
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
import { makeExecutableSchema } from 'graphql-tools'; | |
import merge = require('lodash/merge'); | |
import Scalars from './scalars'; | |
// Modules | |
import Messages from './resolvers/Messages'; | |
const Modules = { | |
typeDefs: [ | |
Messages.typeDefs, |
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
import NEString from './NEString'; | |
import Timestamp from './Timestamp'; | |
export default { | |
declarations: [ | |
NEString.declaration, | |
Timestamp.declaration, | |
], | |
resolvers: { | |
...NEString.type, |
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
import { GraphQLScalarType } from 'graphql'; | |
import { Kind, ValueNode } from 'graphql/language'; | |
import { gql } from 'apollo-server'; | |
const parse = (v: string) => { | |
if (v === undefined || v === null) { | |
throw new Error('field should be String'); | |
} | |
return v; |
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
import { GraphQLScalarType } from 'graphql'; | |
import { Kind, ValueNode } from 'graphql/language'; | |
import { gql } from 'apollo-server'; | |
const parse = (v: string) => { | |
if (v === undefined || v === null) { | |
throw new Error('field should be String'); | |
} | |
const str = String(v); |
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
import { gql } from 'apollo-server-express'; | |
const typeDefs = gql` | |
type Message { | |
_id: ID! | |
sender_id: String! | |
senderName: String! | |
text: String! | |
date: Timestamp! | |
} |
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
[...] | |
httpServer.listen({ port: config.port }, () => { | |
console.log(`🚀 Server ready at http://localhost:${config.port}${server.graphqlPath}`) | |
console.log(`🚀 Subscriptions ready at ws://localhost:${config.port}${server.subscriptionsPath}`) | |
const connectMongoWithRetry = () => { | |
mongoose | |
.connect(config.mongoURI, { | |
useNewUrlParser: true, | |
useCreateIndex: true, |