console.js 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const gql = require('graphql-tag')
  2. // Subs
  3. const channels = require('../channels')
  4. // Connectors
  5. const logs = require('../connectors/logs')
  6. exports.types = gql`
  7. extend type Query {
  8. consoleLogs: [ConsoleLog]
  9. consoleLogLast: ConsoleLog
  10. }
  11. extend type Mutation {
  12. consoleLogsClear: [ConsoleLog]
  13. }
  14. extend type Subscription {
  15. consoleLogAdded: ConsoleLog!
  16. }
  17. type ConsoleLog {
  18. id: ID!
  19. message: String!
  20. tag: String
  21. type: ConsoleLogType!
  22. date: String
  23. }
  24. enum ConsoleLogType {
  25. log
  26. warn
  27. error
  28. info
  29. done
  30. }
  31. `
  32. exports.resolvers = {
  33. Query: {
  34. consoleLogs: (root, args, context) => logs.list(context),
  35. consoleLogLast: (root, args, context) => logs.last(context)
  36. },
  37. Mutation: {
  38. consoleLogsClear: (root, args, context) => logs.clear(context)
  39. },
  40. Subscription: {
  41. consoleLogAdded: {
  42. subscribe: (parent, args, context) => context.pubsub.asyncIterator(channels.CONSOLE_LOG_ADDED)
  43. }
  44. }
  45. }