From 8061fbed8fc3626b165b8c03dee79901682f60a2 Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Tue, 14 Jan 2020 13:46:14 +0200 Subject: [PATCH] feat: GQL query to get latest service messages --- packages/daf-cli/src/graphql.ts | 1 + .../src/graphql/graphql-base-type-defs.ts | 1 - packages/daf-core/src/graphql/graphql-core.ts | 42 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/daf-cli/src/graphql.ts b/packages/daf-cli/src/graphql.ts index 365fbde8c..f86597e08 100644 --- a/packages/daf-cli/src/graphql.ts +++ b/packages/daf-cli/src/graphql.ts @@ -36,6 +36,7 @@ program context: () => ({ dataStore, core }), introspection: true, }) + await core.setupServices() const info = await server.listen({ port: cmd.port }) console.log(`🚀 Server ready at ${info.url}`) diff --git a/packages/daf-core/src/graphql/graphql-base-type-defs.ts b/packages/daf-core/src/graphql/graphql-base-type-defs.ts index cca78dcf7..e9d320f9b 100644 --- a/packages/daf-core/src/graphql/graphql-base-type-defs.ts +++ b/packages/daf-core/src/graphql/graphql-base-type-defs.ts @@ -22,7 +22,6 @@ export const baseTypeDefs = ` } type MessageMetaData { - rowId: String! type: String! id: String data: String diff --git a/packages/daf-core/src/graphql/graphql-core.ts b/packages/daf-core/src/graphql/graphql-core.ts index 149a3db7e..37b7a41a0 100644 --- a/packages/daf-core/src/graphql/graphql-core.ts +++ b/packages/daf-core/src/graphql/graphql-core.ts @@ -1,4 +1,6 @@ import { Core } from '../core' +import { LastMessageTimestampForInstance } from '../service/service-manager' + import { Message } from '../message/message' interface Context { @@ -21,13 +23,53 @@ const newMessage = async ( ) } +const serviceMessagesSince = async ( + _: any, + args: { ts: LastMessageTimestampForInstance[] }, + ctx: Context, +) => { + const res = await ctx.core.getMessagesSince(args.ts) + return res.map(msg => ({ + ...msg, + data: JSON.stringify(msg.data), + raw: msg.raw, + metaData: msg.allMeta, + })) +} + export const resolvers = { + Query: { + serviceMessagesSince, + }, Mutation: { newMessage, }, } export const typeDefs = ` + input LastMessageTimestampForInstance { + timestamp: Int! + did: String! + type: String! + id: String! + } + + type ServiceMessage { + id: String! + threadId: String, + timestamp: Int, + sender: String, + receiver: String, + type: String, + raw: String, + data: String, + metaData: [MessageMetaData] + } + + extend type Query { + serviceMessagesSince(ts: [LastMessageTimestampForInstance]!): [ServiceMessage] + } + extend type Mutation { newMessage(raw: String!, sourceType: String!, sourceId: String): Message }