Promises Callback GraphQL and fetch
Posted on September 2, 2022
Tags: codeetc
1 Callback and Promises
\[ (3^2) + (5 \times 6)\]
- We compute \((5 \times 6)\) first, then pass the result
- \(\lambda k. k(30)\)
- \(\text{k is } \lambda x. (3^2) + x\)
- \(\lambda k. k(30)\)
def plus(x, y, k):
return k(x + y)
def mul(x, y, k):
return k(x * y)
def square(x,k):
return k(x^2)
5,6,lambda x: (3**2) + x) mul(
%k
|
@
/ \
k mul
/ \ 5 6
%k
|
@
/ \
k sq
| 3
%k
|
@
/ \
k plus
/ \ x y
2 Graphql
fetch("https://graphqlzero.almansi.me/api", {
"method": "POST",
"headers": { "content-type": "application/json" },
"body": JSON.stringify({
query: `{
user(id: 1) {
id
name
}
}`
}).then(res => res.json())
}).then(jsonoutput => console.log(jsonoutput))
// { "data": { "user": { ... } } }
const res = async () => {fetch("https://graphqlzero.almansi.me/api", {
"method": "POST",
"headers": { "content-type": "application/json" },
"body": JSON.stringify({
query: `{
user(id: 1) {
id
name
}
}`
})
})}const jsonoutput = async ()=>{res.json()}
console.log(jsonoutput)
// { "data": { "user": { ... } } }