chrismitchellonline

Drupal 8 GraphQL Module

2019-07-23

In this article I’ll show how to install the latest GraphQL Drupal module which you can use to expose Drupal content that can be queried using the Graph Query Language.

Prerequisits

You should have access to a local Drupal code base with Composer available to install Drupal modules and dependencies. For this article I am using Drupal 8.7.5.

In a previous article I wrote about local Drupal and Docker which can be used as a basis for this article. Read more here.

Installing GraphQL Drupal Module

Using Composer we are going install the latest version of the GraphQL module for Drupal. Composer will install all required libraries as well. This method of installing the GraphQL module is the recommended method because of the requirement of the webonyx/graphql-php module. Attempting to install the module through the admin panel gives this error:

GraphQL Module Drupal

Instead of the admin console we’ll use the terminal to install this module using Composer. Run the following Composer command from the root of the Drupal install (from my Docker container this is /var/www/html):

composer require 'drupal/graphql:^4.0'

This will download the GraphQL Drupal module and all of its dependencies. Along with dependencies there is a GraphQL example module that is also available. I would suggest enabling that as well, it contains some sample schemas to get started. More on schemas later. You can install the module either from the admin console or directly from the CLI using Drush:

drush pm-enable graphql

Which will enable the GraphQL module:

root@6e2436f506f0:/var/www/html# drush pm-enable graphql
The following module(s) will be enabled: graphql, graphql_examples, typed_data

 Do you want to continue? (yes/no) [yes]:
 > y

 [success] Successfully enabled: graphql, graphql_examples typed_data

Updated Module

Ensure that you install at minimum GraphQL module version 4.0-alpha02 as this version has some bugs worked out. The module is still in alpha so we should be prepared to thoroughly test and submit bugs as needed, but 4.0-alpha02 seems like a big improvement.

To get started view the admin page at /admin/config/graphql to setup new GraphQL schemas.

Next step, Actual GraphQL

At this time, you should ensure that you do not have any issues with accessing the GraphQL module within your Drupal install, and that your site is free of errors. Next we are going to look at GraphQL in action.

Continue to GraphQL in Action

Closing

In closing I would like to ask the community what are you doing with GraphQL? Leave a comment or Email Me. And if your interested in continuing to use GraphQL in Drupal, check out my arcticle Drupal 8 GraphQL in Action

comments powered by Disqus
Social Media
Sponsor