Overview

In the following article, I launched Strapi on Amazon Lightsail.

This time, I add GraphQL and try using it.

Installing the GraphQL Plugin

I ran the following. Please adjust paths like backend as needed.

cd /opt/bitnami/apache2/htdocs/backend
yarn add @strapi/plugin-graphql

Then, start the application.

yarn develop

Accessing /graphql displays the following screen.

I had already created a content type called services with a field called title. So by issuing the following query, I was able to retrieve the list and metadata.

# Write your query or mutation here
query getServices {
  services {
    data {
      id
      attributes {
        title
        createdAt
        updatedAt
      }
    }
  }
}

The result is as follows.

{
  "data": {
    "services": {
      "data": [
        {
          "id": "1",
          "attributes": {
            "title": "Cultural Japan",
            "createdAt": "2023-04-10T21:59:08.768Z",
            "updatedAt": "2023-04-10T21:59:12.752Z"
          }
        }
      ]
    }
  }
}

Summary

Next, I would like to try integration with Next.js and similar frameworks.