async function createGame()

in source/functions/gamesimulator-scheduler-function/index.js [125:158]


async function createGame(game) {
  try {
    const req = new AWS.HttpRequest(url, region);
    req.method = "POST";
    req.headers.host = endpoint;
    req.headers["Content-Type"] = "application/json";
    req.body = JSON.stringify({
        query: print(createSimulatedGame),
        operationName: "CreateGame",
        variables: {
        input: game
      }
    });
    const signer = new AWS.Signers.V4(req, "appsync", true);
    signer.addAuthorization(AWS.config.credentials, AWS.util.date.getDate());
    
    const graphqlData = await new Promise((resolve, reject) => {
        const httpRequest = https.request({ ...req, host: endpoint }, (result) => {
            result.on('data', (data) => {
                resolve(JSON.parse(data.toString()));
            });
        });

        httpRequest.write(req.body);
        httpRequest.end();
    });
    console.log('received graphql errors: ', graphqlData.errors);
    console.log('items: ', graphqlData.data.createGame.id);
    return graphqlData.data.createGame.id;
  } catch (err) {
    console.log('error creating todo: ', err);
    return null;
  } 
}