Skip to content
Kentico Cloud Boilerplate for development of Express application using Apollo server and GraphQL.
Branch: master
Clone or download
Latest commit b805c04 May 13, 2019

README.md

Kentico Cloud Boilerplate for Express

Boilerplate screenshot

Live demo Stack Overflow

Build Status Maintainability

This boilerplate showcases how it is possible to combine the Node.js web application framework Express with GraphQL.

The server converts the Kentico Cloud Delivery REST API to GraphQL using the Apollo framework and then renders the output using the Pug view engine.

Quick start

Prerequisites

Run locally

  1. Clone the repository.
    • git clone https://github.com/Kentico/cloud-boilerplate-express-apollo.git
  2. Navigate to the repository folder.
    • cd cloud-boilerplate-express-apollo
  3. Install the dependencies.
    • npm install
  4. Run the boilerplate.
    • npm run debug
  5. Open http://localhost:3000 in your browser.

Test queries

With your application running, open http://localhost:3000/graphql and enter following query:

{
  itemsByType(
    type: "article"
    limit: 3
    depth: 0
    order: "elements.post_date"
  ) {
    ... on ArticleContentType {
      title {
        value
      }
      summary {
        value
      }
      teaser_image {
        assets {
          name
          url
        }
      }
    }
  }
}

For more complex queries, take a look at the schema definition generated by Apollo. Shema in playground

Other commands

Debug logging

To run the application with debug logging:

npm run debug
  • It is possible to use the Debug server launch configuration if you are using Visual Studio Code for development.

Regenerate GraphQL schema

Schema is generated using the Kentico GraphQL schema generator which automatically generates GraphQL data type schema based on the Kentico Cloud Project ID.

To regenerate the schema, manually run:

npm run generate-schema

How to change Kentico Cloud Project ID

  • Change the projectId argument value in the scripts section found in package.json
    • This value is used when the schema is regenerated. Basically, when the application is starting or when the generation is triggered manually
  • Change the of projectId property in config.json
    • This value is used in the application

How to adjust the boilerplate for different projects

Architecture

GraphQL endpoints are provided by the Apollo Server. Implementation of this server requires providing data and query schema and query resolvers.

Data provided by the GraphQL endpoint is consumed in the controller using the Apollo client and rendered using the Pug view engine.

Adjusting the boilerplate to your project

  1. Point the application to your project ID.
  2. Regenerate the schema manually.
  3. Define the queries type schema in queryTypes constant.
  4. Implement the queries by the schema in Query property in resolvers constant.
  5. Use the queries to load data to render in controller.
  6. Adjust the view template to display provided data.

Analytics

You can’t perform that action at this time.