Skip to content

Commit

Permalink
feat: GQL query to get latest service messages
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Jan 14, 2020
1 parent b712aa0 commit 8061fbe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/daf-cli/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)

Expand Down
1 change: 0 additions & 1 deletion packages/daf-core/src/graphql/graphql-base-type-defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const baseTypeDefs = `
}
type MessageMetaData {
rowId: String!
type: String!
id: String
data: String
Expand Down
42 changes: 42 additions & 0 deletions packages/daf-core/src/graphql/graphql-core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Core } from '../core'
import { LastMessageTimestampForInstance } from '../service/service-manager'

import { Message } from '../message/message'

interface Context {
Expand All @@ -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
}
Expand Down

0 comments on commit 8061fbe

Please sign in to comment.