Skip to content

Commit

Permalink
add apollo, esModuleInterop, everything breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 4, 2018
1 parent 0077baf commit 8cb8cfe
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 25 deletions.
1 change: 1 addition & 0 deletions config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allowSyntheticDefaultImports": false,
"baseUrl": "../",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"importHelpers": true,
"jsx": "react",
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = {
alias: path.vendor,
onlyModule: false
}],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],
plugins: [
new TsConfigPathsPlugin({ tsconfig, compiler: 'typescript' })
]
Expand Down
4 changes: 4 additions & 0 deletions docs/listener/apollo-listener.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metadata:
kind: apollo-listener
name: test-apollo
data: {}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/cheerio": "^0.22.0",
"@types/cron": "~1.3",
"@types/escape-html": "^0.0.20",
"@types/graphql": "^14.0.3",
"@types/js-yaml": "~3.11",
"@types/jsonpath": "^0.2.0",
"@types/lodash": "~4.14",
Expand All @@ -39,6 +40,7 @@
"@types/ws": "~6.0",
"@types/yargs-parser": "~11.0",
"ajv": "^6.6.1",
"apollo-server": "^2.2.6",
"awesome-typescript-loader": "~5.2",
"aws-sdk": "~2.361.0",
"bufferutil": "~4.0",
Expand All @@ -49,6 +51,7 @@
"cron": "~1.5",
"discord.js": "~11.4",
"escape-html": "~1.0",
"graphql": "^14.0.2",
"ineeda": "^0.12.0-alpha.0",
"istanbul-instrumenter-loader": "~3.0",
"js-yaml": "~3.12",
Expand Down
2 changes: 1 addition & 1 deletion src/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from 'noicejs/logger/Logger';
import * as uuid from 'uuid/v4';
import uuid from 'uuid/v4';

import { Service, ServiceOptions } from 'src/Service';
import { dictToMap } from './utils';
Expand Down
2 changes: 1 addition & 1 deletion src/entity/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as escape from 'escape-html';
import escape from 'escape-html';
import { Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';

import { Context } from 'src/entity/Context';
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, Module } from 'noicejs';
import * as sourceMapSupport from 'source-map-support';
import * as yargs from 'yargs-parser';
import sourceMapSupport from 'source-map-support';
import yargs from 'yargs-parser';

import { Bot, BotOptions } from 'src/Bot';
import { loadConfig } from 'src/config';
Expand Down
59 changes: 59 additions & 0 deletions src/listener/ApolloListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ApolloServer, gql } from 'apollo-server';
import { BaseListener } from './BaseListener';
import { Listener, FetchOptions } from './Listener';
import { ChildServiceOptions } from 'src/ChildService';
import { Message } from 'src/entity/Message';

const books = [{
title: 'test',
author: 'test',
}];

const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;

const resolvers = {
Query: {
books: () => books,
},
};

export interface ApolloListenerData {}
export type ApolloListenerOptions = ChildServiceOptions<ApolloListenerData>;

export class ApolloListener extends BaseListener<ApolloListenerData> implements Listener {
protected server: ApolloServer;

constructor(options: ApolloListenerOptions) {
super(options);
this.server = new ApolloServer({
typeDefs,
resolvers,
});
}

public async start() {
const info = await this.server.listen();
this.logger.debug({ info }, 'started apollo server');
}

public async stop() {
return this.server.stop();
}

public async emit() {

}

public async fetch(options: FetchOptions): Promise<Array<Message>> {
return [];
}
}
2 changes: 1 addition & 1 deletion src/module/BotModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger, Module, Provides } from 'noicejs';
import { ModuleOptions } from 'noicejs/Module';
import * as request from 'request-promise';
import request from 'request-promise';
import { Connection } from 'typeorm';

import { Bot } from 'src/Bot';
Expand Down
2 changes: 2 additions & 0 deletions src/module/ListenerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { ModuleOptions } from 'noicejs/Module';

import { DiscordListener } from 'src/listener/DiscordListener';
import { SlackListener } from 'src/listener/SlackListener';
import { ApolloListener } from 'src/listener/ApolloListener';

export class ListenerModule extends Module {
public async configure(options: ModuleOptions) {
await super.configure(options);

// listeners
this.bind(kebabCase(ApolloListener.name)).toConstructor(ApolloListener);
this.bind(kebabCase(DiscordListener.name)).toConstructor(DiscordListener);
this.bind(kebabCase(SlackListener.name)).toConstructor(SlackListener);
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ArgsParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as yargs from 'yargs-parser';
import yargs from 'yargs-parser';

import { NOUN_FRAGMENT } from 'src/controller/CompletionController';
import { Command, CommandDataValue, CommandVerb } from 'src/entity/Command';
Expand Down
2 changes: 1 addition & 1 deletion src/parser/MapParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as split from 'split-string';
import split from 'split-string';

import { Command, CommandData, CommandDataType, CommandVerb } from 'src/entity/Command';
import { Message } from 'src/entity/Message';
Expand Down
2 changes: 1 addition & 1 deletion src/parser/SplitParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmpty, trim } from 'lodash';
import * as split from 'split-string';
import split from 'split-string';

import { Command } from 'src/entity/Command';
import { Message } from 'src/entity/Message';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Ajv from 'ajv';
import Ajv from 'ajv';
import { filterNil } from '.';

export interface SchemaResult {
Expand Down
10 changes: 5 additions & 5 deletions test/harness.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import {ineeda} from 'ineeda';
import * as sinonChai from 'sinon-chai';
import * as sourceMapSupport from 'source-map-support';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { ineeda } from 'ineeda';
import sinonChai from 'sinon-chai';
import sourceMapSupport from 'source-map-support';

sourceMapSupport.install({
environment: 'node',
Expand Down
Loading

0 comments on commit 8cb8cfe

Please sign in to comment.