From 10d31cc96b293ca0c2f48fa3e39cb94612146e55 Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Wed, 8 Jul 2020 13:20:53 +0300 Subject: [PATCH] feat: GraphQL message handler --- packages/daf-graphql/src/base-type-def.ts | 25 +++++++++++ packages/daf-graphql/src/methods/index.ts | 2 + .../src/methods/message-handler.ts | 42 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 packages/daf-graphql/src/methods/message-handler.ts diff --git a/packages/daf-graphql/src/base-type-def.ts b/packages/daf-graphql/src/base-type-def.ts index b77b076b9..f60b8da44 100644 --- a/packages/daf-graphql/src/base-type-def.ts +++ b/packages/daf-graphql/src/base-type-def.ts @@ -9,5 +9,30 @@ type Identity { scalar Object scalar Date +scalar VerifiablePresentation +scalar VerifiableCredential + +type Message { + id: ID! + createdAt: Date + expiresAt: Date + threadId: String + type: String! + raw: String + data: Object + replyTo: [String] + replyUrl: String + from: String + to: String + metaData: [MetaData] + presentations: [VerifiablePresentation] + credentials: [VerifiableCredential] +} + +type MetaData { + type: String! + value: String +} + ` diff --git a/packages/daf-graphql/src/methods/index.ts b/packages/daf-graphql/src/methods/index.ts index 1baaa5ec6..ffc0dd9cc 100644 --- a/packages/daf-graphql/src/methods/index.ts +++ b/packages/daf-graphql/src/methods/index.ts @@ -1,8 +1,10 @@ import { IAgentGraphQLMethod } from '../types' import identityManager from './identity-manager' import resolver from './resolver' +import messageHandler from './message-handler' export const supportedMethods: Record = { ...identityManager, ...resolver, + ...messageHandler, } diff --git a/packages/daf-graphql/src/methods/message-handler.ts b/packages/daf-graphql/src/methods/message-handler.ts new file mode 100644 index 000000000..ec2f18df7 --- /dev/null +++ b/packages/daf-graphql/src/methods/message-handler.ts @@ -0,0 +1,42 @@ +import { IAgentGraphQLMethod } from '../types' + +export const handleMessage: IAgentGraphQLMethod = { + type: 'Mutation', + query: ` + mutation handleMessage($raw: String!, $metaData: [MetaDataInput], $save: Boolean) { + handleMessage(raw: $raw, metaData: $metaData, save: $save) { + id + createdAt + expiresAt + threadId + type + raw + data + replyTo + replyUrl + from + to + metaData { + type + value + } + } + } + `, + typeDef: ` + input MetaDataInput { + type: String! + value: String + } + + extend type Mutation { + handleMessage(raw: String!, metaData: [MetaDataInput], save: Boolean = true): Message + } + `, +} + +export const supportedMethods: Record = { + handleMessage, +} + +export default supportedMethods