From c2324bfb300c10c22881cfab3e44a261c2a0e860 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sat, 12 Jan 2019 19:02:56 -0600 Subject: [PATCH] fix: wire up data and labels for graph/iql --- src/schema/graph/index.ts | 37 ++++++++++++++++++++++++-------- src/schema/graph/input/Pairs.ts | 2 +- src/schema/graph/output/Pairs.ts | 2 +- src/utils/Map.ts | 9 ++++---- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/schema/graph/index.ts b/src/schema/graph/index.ts index b9792ea62..7e5fde972 100644 --- a/src/schema/graph/index.ts +++ b/src/schema/graph/index.ts @@ -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); @@ -26,11 +26,30 @@ interface GraphIDOptions { } interface GraphCommandOptions { - commands: Array; + commands: Array<{ + data: Array<{ + name: string; + value: Array; + }>; + labels: Array<{ + name: string; + value: string; + }>; + noun: string; + verb: CommandVerb; + }>; } interface GraphMessageOptions { - messages: Array; + messages: Array<{ + body: string; + labels: Array<{ + name: string; + value: string; + }>; + reactions: Array; + type: string; + }>; } export type GraphSchemaData = BotServiceData; @@ -67,8 +86,8 @@ export class GraphSchema extends BotService { const { noun, verb } = data; const cmd = new Command({ context, - data: {}, - labels: dictToMap(data.labels), + data: pairsToMap(data.data), + labels: pairsToMap(data.labels), noun, verb, }); @@ -91,8 +110,8 @@ export class GraphSchema extends BotService { const msg = new Message({ body, context, - labels: this.labels, - reactions: [], + labels: pairsToMap(data.labels), + reactions: data.reactions, type, }); messages.push(msg); diff --git a/src/schema/graph/input/Pairs.ts b/src/schema/graph/input/Pairs.ts index 1abbd4f8b..ca4fb9eba 100644 --- a/src/schema/graph/input/Pairs.ts +++ b/src/schema/graph/input/Pairs.ts @@ -17,7 +17,7 @@ export const GRAPH_INPUT_NAME_MULTI_VALUE_PAIR = new GraphQLInputObjectType({ name: { type: GraphQLString, }, - values: { + value: { type: new GraphQLList(GraphQLString), }, }, diff --git a/src/schema/graph/output/Pairs.ts b/src/schema/graph/output/Pairs.ts index b717d01fe..c23647752 100644 --- a/src/schema/graph/output/Pairs.ts +++ b/src/schema/graph/output/Pairs.ts @@ -17,7 +17,7 @@ export const GRAPH_OUTPUT_NAME_MULTI_VALUE_PAIR = new GraphQLObjectType({ name: { type: GraphQLString, }, - values: { + value: { type: new GraphQLList(GraphQLString), }, }, diff --git a/src/utils/Map.ts b/src/utils/Map.ts index c9c80f7cd..d6cf17465 100644 --- a/src/utils/Map.ts +++ b/src/utils/Map.ts @@ -129,12 +129,13 @@ export interface NameValuePair { value: TVal; } -export function pairsToDict(pairs: Array>): Map { +export function pairsToMap(pairs: Array> | undefined): Map { 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; }