I’ve come back to this occasionally, thanks. Here are two more snippets:
To get one post
{
post(
input: {
selector: {
_id: "Here goes the id"
}
})
{
result {
_id
title
slug
pageUrl
postedAt
baseScore
voteCount
commentCount
meta
question
url
user {
username
slug
karma
maxPostCount
commentCount
}
}
}
}
or, as a JavaScript/node function:
let graphQLendpoint = 'https://forum.effectivealtruism.org/graphql′ // or https://www.lesswrong.com/graphql. Note that this is not the same as the graph*i*ql visual interface talked about in the post.
async function fetchPost(id){
// note the async
let response = await fetch(graphQLendpoint, ({
method: ‘POST’,
headers: ({ ‘Content-Type’: ‘application/json’ }),
body: JSON.stringify(({ query: `
{
post(
input: {
selector: {
_id: “${id}”
}
})
{
result {
_id
title
slug
pageUrl
postedAt
baseScore
voteCount
commentCount
meta
question
url
user {
username
slug
karma
maxPostCount
commentCount
}
}
}
}`
})),
}))
.then(res ⇒ res.json())
.then(res ⇒ res.data.post? res.data.post.result : undefined)
return response
}
let graphQLendpoint = 'https://forum.effectivealtruism.org/graphql′ // or https://www.lesswrong.com/graphql. Note that this is not the same as the graph*i*ql visual interface talked about in the post.
async function fetchAuthor(slug){
// note the async
let response = await fetch(graphQLendpoint, ({
method: ‘POST’,
headers: ({ ‘Content-Type’: ‘application/json’ }),
body: JSON.stringify(({ query: `
{
user(input: {
selector: {
slug: “${slug}”
}
}){
result{
username
pageUrl
karma
maxPostCount
commentCount
}
}
}`
})),
}))
.then(res ⇒ res.json())
.then(res ⇒ res.data.user? res.data.user.result : undefined)
return response
}
I’ve come back to this occasionally, thanks. Here are two more snippets:
To get one post
or, as a JavaScript/node function:
To get a user
Or, as a JavaScript function