forked from skillrecordings/egghead-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlessons.ts
More file actions
79 lines (71 loc) · 1.54 KB
/
Copy pathlessons.ts
File metadata and controls
79 lines (71 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {LessonResource} from 'types'
import {GraphQLClient} from 'graphql-request'
import config from './config'
const graphQLClient = new GraphQLClient(config.graphQLEndpoint)
export async function loadLessons(): Promise<LessonResource[]> {
const query = /* GraphQL */ `
query getLessons {
lessons(per_page: 25) {
title
slug
icon_url
instructor {
full_name
avatar_64_url
}
}
}
`
const {lessons} = await graphQLClient.request(config.graphQLEndpoint, query)
return lessons
}
export async function loadLesson(slug: string, token?: string) {
const query = /* GraphQL */ `
query getLesson($slug: String!) {
lesson(slug: $slug) {
slug
title
transcript_url
transcript
subtitles_url
next_up_url
description
hls_url
dash_url
free_forever
http_url
media_url
path
course {
title
square_cover_480_url
slug
}
tags {
name
http_url
image_url
}
instructor {
full_name
avatar_64_url
slug
twitter
}
repo_url
code_url
}
}
`
const authorizationHeader = token && {
authorization: `Bearer ${token}`,
}
const variables = {
slug: slug,
}
graphQLClient.setHeaders({
...authorizationHeader,
})
const {lesson} = await graphQLClient.request(query, variables)
return lesson as LessonResource
}