Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async await and not callback #28

Open
olavea opened this issue May 24, 2022 · 1 comment
Open

async await and not callback #28

olavea opened this issue May 24, 2022 · 1 comment
Assignees

Comments

@olavea
Copy link
Owner

olavea commented May 24, 2022

See PR with commit here

// /gatsby-node.js

// added async
const createCloudinaryNodes = async (gatsby, cloudinary, options) => {
  // added await
  await cloudinary.api.resources(options, (error, result) => {
    const hasResources = result && result.resources && result.resources.length;
    console.log("This is the result", result);
    if (error) {
      console.error(error);
      return;
    }

    if (!hasResources) {
      console.warn(
        "\n ~Yikes! No nodes created because no Cloudinary resources found. Try a different query?"
      );
      return;
    }

    result.resources.forEach((resource) => {
      const transformations = "q_auto,f_auto"; // Default CL transformations, todo: fetch base transformations from config maybe.

      resource.url = addTransformations(resource, transformations);
      resource.secure_url = addTransformations(resource, transformations, true);

      const nodeData = getNodeData(gatsby, resource);
      gatsby.actions.createNode(nodeData);
    });

    console.info(
      `Added ${hasResources} CloudinaryMedia ${
        hasResources > 1 ? "nodes" : "node"
      }`
    );
  });
};

```
Looks like it worked ⬇️ 

![gatsby-cloudinary-week_1_result await_5](https://user-images.githubusercontent.com/7642493/170055990-1a276498-11d6-4829-9d65-27e6460cc51e.png)
@olavea olavea self-assigned this May 24, 2022
olavea added a commit that referenced this issue May 24, 2022
@raae
Copy link
Contributor

raae commented May 24, 2022

Det er fortsatt callbacken som gjør arbeidet, alt som liksom er inne der skal utenfor:

const result = await cloudinary.api.resources(options)
// her kommer alt arbeidet som før skjedde inn i callbacken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants