Skip to content
This repository has been archived by the owner on Jun 22, 2019. It is now read-only.

Added subscriptions for todos #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,40 @@
"dev": "npm-run-all --parallel start playground",
"start": "nodemon -e ts,graphql -x ts-node -r dotenv/config src",
"playground": "graphql playground",
"deploy":
"now --public --dotenv .env.production && now alias && now rm --yes --safe fakerql.com",
"deploy": "now --public --dotenv .env.production && now alias && now rm --yes --safe fakerql.com",
"build": "rimraf dist && tsc",
"now-start": "node dist"
},
"devDependencies": {
"@types/compression": "^0.0.36",
"@types/cuid": "^1.3.0",
"@types/node": "^9.3.0",
"dotenv": "^4.0.0",
"nodemon": "^1.14.11",
"now": "^9.2.7",
"@types/express-jwt": "^0.0.40",
"@types/faker": "^4.1.2",
"@types/node": "^10.0.4",
"dotenv": "^5.0.1",
"nodemon": "^1.17.3",
"now": "^11.1.7",
"npm-run-all": "^4.1.2",
"ts-node": "^4.1.0",
"typescript": "^2.6.2"
"prettier": "^1.12.1",
"ts-node": "^6.0.2",
"tslint": "^5.10.0",
"typescript": "^2.8.3"
},
"dependencies": {
"apollo-errors": "^1.5.1",
"compression": "^1.7.1",
"express-jwt": "^5.3.0",
"apollo-errors": "^1.9.0",
"compression": "^1.7.2",
"express-jwt": "^5.3.1",
"faker": "^4.1.0",
"graphql-yoga": "^1.2.0",
"jsonwebtoken": "^8.1.0",
"scuid": "^1.0.2"
"graphql-yoga": "^1.13.1",
"jsonwebtoken": "^8.2.1",
"scuid": "^1.1.0"
},
"now": {
"alias": "fakerql.com"
},
"prettier": {
"semi": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "none"
}
}
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import resolvers from './resolvers';

const { JWT_SECRET } = process.env;

const pubsub = new PubSub();
export const pubsub = new PubSub();

const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
jwtSecret: JWT_SECRET,
faker,
pubsub
faker
})
});

Expand All @@ -40,5 +40,6 @@ const options = {
};

server.start(options, ({ port }) =>
// tslint:disable-next-line
console.log(`Server is running on PORT: ${port}`)
);
38 changes: 14 additions & 24 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as scuid from 'scuid';

import { generateAuthToken, getUserId } from '../utils';
import { pubsub } from './../index';

const DEFAULT_COUNT = 25;

Expand Down Expand Up @@ -144,36 +145,25 @@ export default {
createTodo: (parent, { title, completed }, { faker }) => {
const id = scuid();

// pubsub.publish('todoAdded', {
// todoAdded: {
// id,
// title,
// completed
// }
// });
pubsub.publish('todoAdded', {
todoAdded: {
id,
title,
completed
}
});

return {
id,
title,
completed: completed === undefined ? faker.random.boolean() : completed
};
}
}
},

// Subscription: {
// todoAdded: {
// subscribe: (parent, args, { pubsub }) => {
// // setInterval(
// // () => pubsub.publish(channel, { counter: { count: count++ } }),
// // 2000
// // );
// //
// // return pubsub.asyncIterator({
// // id: 'abc',
// // title: 'Hello',
// // completed: true
// // });
// }
// }
// }
Subscription: {
todoAdded: {
subscribe: () => pubsub.asyncIterator('todoAdded')
}
}
};
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"outDir": "dist",
"lib": ["esnext.asynciterable", "es2016", "dom"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
31 changes: 31 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"defaultSeverity": "error",
"extends": ["tslint:recommended"],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"semicolon": true,
"trailing-comma": false,
"eofline": false,
"quotemark": [true, "single"],
"indent": false,
"member-access": [false],
"ordered-imports": [false],
"max-line-length": [true, 80],
"member-ordering": [false],
"curly": true,
"interface-name": [false],
"array-type": [false],
"no-empty-interface": false,
"no-empty": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
"max-classes-per-file": [false],
"variable-name": [false],
"one-line": [false],
"one-variable-per-declaration": [false]
},
"rulesDirectory": []
}
Loading