Skip to content

Commit 8061fbe

Browse files
committedJan 14, 2020
feat: GQL query to get latest service messages
1 parent b712aa0 commit 8061fbe

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
 

‎packages/daf-cli/src/graphql.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ program
3636
context: () => ({ dataStore, core }),
3737
introspection: true,
3838
})
39+
await core.setupServices()
3940
const info = await server.listen({ port: cmd.port })
4041
console.log(`🚀 Server ready at ${info.url}`)
4142

‎packages/daf-core/src/graphql/graphql-base-type-defs.ts

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const baseTypeDefs = `
2222
}
2323
2424
type MessageMetaData {
25-
rowId: String!
2625
type: String!
2726
id: String
2827
data: String

‎packages/daf-core/src/graphql/graphql-core.ts

+42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Core } from '../core'
2+
import { LastMessageTimestampForInstance } from '../service/service-manager'
3+
24
import { Message } from '../message/message'
35

46
interface Context {
@@ -21,13 +23,53 @@ const newMessage = async (
2123
)
2224
}
2325

26+
const serviceMessagesSince = async (
27+
_: any,
28+
args: { ts: LastMessageTimestampForInstance[] },
29+
ctx: Context,
30+
) => {
31+
const res = await ctx.core.getMessagesSince(args.ts)
32+
return res.map(msg => ({
33+
...msg,
34+
data: JSON.stringify(msg.data),
35+
raw: msg.raw,
36+
metaData: msg.allMeta,
37+
}))
38+
}
39+
2440
export const resolvers = {
41+
Query: {
42+
serviceMessagesSince,
43+
},
2544
Mutation: {
2645
newMessage,
2746
},
2847
}
2948

3049
export const typeDefs = `
50+
input LastMessageTimestampForInstance {
51+
timestamp: Int!
52+
did: String!
53+
type: String!
54+
id: String!
55+
}
56+
57+
type ServiceMessage {
58+
id: String!
59+
threadId: String,
60+
timestamp: Int,
61+
sender: String,
62+
receiver: String,
63+
type: String,
64+
raw: String,
65+
data: String,
66+
metaData: [MessageMetaData]
67+
}
68+
69+
extend type Query {
70+
serviceMessagesSince(ts: [LastMessageTimestampForInstance]!): [ServiceMessage]
71+
}
72+
3173
extend type Mutation {
3274
newMessage(raw: String!, sourceType: String!, sourceId: String): Message
3375
}

0 commit comments

Comments
 (0)
Please sign in to comment.