Skip to content

Commit

Permalink
fix: wire up data and labels for graph/iql
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 13, 2019
1 parent 3fdf9af commit c2324bf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
37 changes: 28 additions & 9 deletions src/schema/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { Inject } from 'noicejs';

import { INJECT_CLOCK, INJECT_SERVICES } from 'src/BaseService';
import { BotService, BotServiceData, BotServiceOptions, INJECT_BOT, INJECT_STORAGE } from 'src/BotService';
import { Command, CommandOptions, GRAPH_INPUT_COMMAND, GRAPH_OUTPUT_COMMAND } from 'src/entity/Command';
import { Command, CommandVerb, GRAPH_INPUT_COMMAND, GRAPH_OUTPUT_COMMAND } from 'src/entity/Command';
import { Context, GRAPH_INPUT_CONTEXT } from 'src/entity/Context';
import { GRAPH_INPUT_MESSAGE, GRAPH_OUTPUT_MESSAGE, Message, MessageEntityOptions } from 'src/entity/Message';
import { GRAPH_INPUT_MESSAGE, GRAPH_OUTPUT_MESSAGE, Message } from 'src/entity/Message';
import { SessionRequiredError } from 'src/error/SessionRequiredError';
import { ServiceModule } from 'src/module/ServiceModule';
import { GRAPH_OUTPUT_SERVICE, ServiceMetadata } from 'src/Service';
import { Storage } from 'src/storage';
import { mustExist } from 'src/utils';
import { dictToMap } from 'src/utils/Map';
import { pairsToMap } from 'src/utils/Map';

const GRAPH_INPUT_COMMAND_LIST = new GraphQLList(GRAPH_INPUT_COMMAND);
const GRAPH_INPUT_MESSAGE_LIST = new GraphQLList(GRAPH_INPUT_MESSAGE);
Expand All @@ -26,11 +26,30 @@ interface GraphIDOptions {
}

interface GraphCommandOptions {
commands: Array<CommandOptions>;
commands: Array<{
data: Array<{
name: string;
value: Array<string>;
}>;
labels: Array<{
name: string;
value: string;
}>;
noun: string;
verb: CommandVerb;
}>;
}

interface GraphMessageOptions {
messages: Array<MessageEntityOptions>;
messages: Array<{
body: string;
labels: Array<{
name: string;
value: string;
}>;
reactions: Array<string>;
type: string;
}>;
}

export type GraphSchemaData = BotServiceData;
Expand Down Expand Up @@ -67,8 +86,8 @@ export class GraphSchema extends BotService<GraphSchemaData> {
const { noun, verb } = data;
const cmd = new Command({
context,
data: {},
labels: dictToMap(data.labels),
data: pairsToMap(data.data),
labels: pairsToMap(data.labels),
noun,
verb,
});
Expand All @@ -91,8 +110,8 @@ export class GraphSchema extends BotService<GraphSchemaData> {
const msg = new Message({
body,
context,
labels: this.labels,
reactions: [],
labels: pairsToMap(data.labels),
reactions: data.reactions,
type,
});
messages.push(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/schema/graph/input/Pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const GRAPH_INPUT_NAME_MULTI_VALUE_PAIR = new GraphQLInputObjectType({
name: {
type: GraphQLString,
},
values: {
value: {
type: new GraphQLList(GraphQLString),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/schema/graph/output/Pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const GRAPH_OUTPUT_NAME_MULTI_VALUE_PAIR = new GraphQLObjectType({
name: {
type: GraphQLString,
},
values: {
value: {
type: new GraphQLList(GraphQLString),
},
},
Expand Down
9 changes: 5 additions & 4 deletions src/utils/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ export interface NameValuePair<TVal> {
value: TVal;
}

export function pairsToDict<TVal>(pairs: Array<NameValuePair<TVal>>): Map<string, TVal> {
export function pairsToMap<TVal>(pairs: Array<NameValuePair<TVal>> | undefined): Map<string, TVal> {
const map = new Map();
for (const p of pairs) {
map.set(p.name, p.value);
if (doesExist(pairs)) {
for (const p of pairs) {
map.set(p.name, p.value);
}
}

return map;
}

Expand Down

0 comments on commit c2324bf

Please sign in to comment.