Promises Callback GraphQL and fetch

Posted on September 2, 2022
Tags: codeetc

callcc

1 Callback and Promises

\[ (3^2) + (5 \times 6)\]

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)
mul(5,6,lambda x: (3**2) + x)
    %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": { ... } } }