Skip to content

Instantly share code, notes, and snippets.

View bogoslavskiy's full-sized avatar

Artem Bogoslavskiy bogoslavskiy

View GitHub Profile
import * as mongoose from 'mongoose';
function timestamp() {
return +new Date();
}
export interface MessageDocument extends mongoose.Document {
sender_id: string;
senderName: string;
text: string;
{
[...]
"scripts": {
[...]
"codegen": "graphql-codegen --config codegen.yml"
},
[...]
}
overwrite: true
schema: "http://localhost:5000/graphql"
documents: null
generates:
src/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-resolvers"
config:
useIndexSignature: true
{
"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\"",
},
}
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,
import NEString from './NEString';
import Timestamp from './Timestamp';
export default {
declarations: [
NEString.declaration,
Timestamp.declaration,
],
resolvers: {
...NEString.type,
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;
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);
import { gql } from 'apollo-server-express';
const typeDefs = gql`
type Message {
_id: ID!
sender_id: String!
senderName: String!
text: String!
date: Timestamp!
}
[...]
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,