index.ts 682 B

1234567891011121314151617181920212223242526272829
  1. import { GraphQLClient } from 'graphql-request'
  2. import { getSdk } from './__generated__/sdk'
  3. export class OrionClient {
  4. private sdk: ReturnType<typeof getSdk>
  5. constructor(graphqlUrl: string) {
  6. const client = new GraphQLClient(graphqlUrl)
  7. this.sdk = getSdk(client)
  8. }
  9. async testConnection() {
  10. const { videos } = await this.sdk.TestQuery()
  11. if (!videos) {
  12. throw new Error('Could not connect to Orion')
  13. }
  14. }
  15. async getVideo(id: string) {
  16. const { videoById } = await this.sdk.GetVideo({ id })
  17. return videoById
  18. }
  19. async getChannel(id: string) {
  20. const { channelById } = await this.sdk.GetChannel({ id })
  21. return channelById
  22. }
  23. }