GraphQL API

GraphQL API

GraphQL API

GraphQL API

Overview

Cortado.js also offers a GraphQL API that provides flexible querying capabilities for image optimization and resizing. With the GraphQL API, you can specify exactly what operations you need to perform on your images and retrieve the results in a single request.

Usage

To interact with Cortado.js via GraphQL API, you can send GraphQL queries to the designated endpoint. Here's how you can use the GraphQL API to optimize and resize images:


  1. Optimize Image


mutation {
  optimizeImage(imageUrl: "URL_OF_YOUR_IMAGE") {
    optimizedImageUrl
  }
}

Send this mutation query to optimize the image specified by its URL. Cortado.js will optimize the image and return the URL of the optimized image in the response.


  1. Resize Image


mutation {
  resizeImage(imageUrl: "URL_OF_YOUR_IMAGE", width: 300, height: 200) {
    resizedImageUrl
  }
}

Send this mutation query to resize the image specified by its URL to the desired width and height. Cortado.js will resize the image and return the URL of the resized image in the response.

Example

Using Apollo Client:


import { gql } from '@apollo/client';

// Optimize Image Mutation
const OPTIMIZE_IMAGE_MUTATION = gql`
  mutation OptimizeImage($imageUrl: String!) {
    optimizeImage(imageUrl: $imageUrl) {
      optimizedImageUrl
    }
  }
`;

// Resize Image Mutation
const RESIZE_IMAGE_MUTATION = gql`
  mutation ResizeImage($imageUrl: String!, $width: Int!, $height: Int!) {
    resizeImage(imageUrl: $imageUrl, width: $width, height: $height) {
      resizedImageUrl
    }
  }
`;

// Use Apollo Client to send mutations
client.mutate({
  mutation: OPTIMIZE_IMAGE_MUTATION,
  variables: { imageUrl: 'URL_OF_YOUR_IMAGE' }
}).then(result => {
  const optimizedImageUrl = result.data.optimizeImage.optimizedImageUrl;
  // Use the optimized image URL
}).catch(error => {
  console.error('Error optimizing image:', error);
});

client.mutate({
  mutation: RESIZE_IMAGE_MUTATION,
  variables: { 
    imageUrl: 'URL_OF_YOUR_IMAGE',
    width: 300,
    height: 200
  }
}).then(result => {
  const resizedImageUrl = result.data.resizeImage.resizedImageUrl;
  // Use the resized image URL
}).catch(error => {
  console.error('Error resizing image:', error);
});

This example demonstrates how to send GraphQL mutation queries to the Cortado.js GraphQL API endpoint to optimize and resize images.

© 2024 Cortado. All rights reserved.

Designed by Ditych. Powered by Framer.

© 2024 Cortado. All rights reserved.

Designed by Ditych. Powered by Framer.