forked from strainel/granddebatnational-tdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphql-granddebat-getcount.R
57 lines (50 loc) · 1.37 KB
/
graphql-granddebat-getcount.R
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
# Grand débat, 2019
# Exemple de requête GraphQL pour récupérer le nombre d'événements organisés en France
# Modules nécessaires
require(httr)
require(jsonlite)
# Principales variables
url <- "https://granddebat.fr/graphql/internal"
query <- "query EventRefetchRefetchQuery($cursor: String, $count: Int, $theme: ID, $project: ID, $userType: ID, $search: String, $isFuture: Boolean) {
events(first: $count, after: $cursor, theme: $theme, project: $project, search: $search, userType: $userType, isFuture: $isFuture) {
totalCount
edges {
node {
id
lat
lng
url
fullAddress
createdAt
startAt
endAt
title
fullAddress
url
themes {
id
title
url
}
__typename
}
cursor
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
}
}"
query_variables <- '{"cursor": null,"count": 3000,"theme": null,"project": null,"userType": null,"search": null,"isFuture": null}'
pbody <- list(query = query, variables = query_variables)
# Appel à l'API
res <- POST(url, body = pbody, encode="json", verbose())
# Vérification de la réponse
http_type(res)
# Lecture du résultat
rparsed <- content(res, as = "parsed", encoding = "UTF-8")
# Affichage du compteur
rparsed$data$events$totalCount