
I’ve cloned the repo and created a new Drupal module called my_graphql. At first I thought to myself “why not just modify the examples”?Īfter playing with the schemas, and promptly breaking the code, I found copying the examples out to my own module is a huge help. We should copy the examples directory into our own custom module to extend the examples. Extend Drupal 8 GraphQL ModuleĪccording to the official documentation for the GraphQL module, To do this we’ll need to do a few things: create our GraphQL schema, expose the Drupal data, and create our GraphQL server. With our product content created we can expose our product data as GraphQL. Along with the default body field, we’ll add an image field with a machine name field_product_image and a decimal field price with a machine name of field_price. I’ll create a new content type called Product. To quickly get up and running with Drupal 8 and GraphQL check out these other articles:Īdditionally, it will be helpful to clone the example Drupal module I’ll use later in the article for examples. We will also need access to edit module files. I am going to assume that you have a Drupal environment available with the Drupal 8 GraphQL module installed.
#Drupal graphql how to#
This article will show how to extend the Drupal 8 GraphQL module and use its examples to build a real world example of a GraphQL server in Drupal 8 while exposing only the data we need in a meaningful way to our front end users. The Object Query service runs queries against the Sling Resource tree and returns POJOs inĪ way that's optimized for the GraphQL Core to consume.In this article I am going to setup a custom GraphQL schema that Drupal can use to export CMS data.
#Drupal graphql code#
This will allow bundles to contribute specific sets of types to a schema, along with the code that implements their retrieval and other Sling-whiteboard:sling-org-apache-sling-graphql-schemaįor a schema aggregator that allows OSGi bundles to contribute partial GraphQL schemas to an overall schema. Schema Aggregator (planned)Īn initial spec, without code so far, is available at URL selectors, so that an HTTP GET request to /content/mypage.A.full.json executes the GraphQL query previously json requests for resources which have the samples/graphql resource ProviderType public interface SchemaProvider Planned Extensions / Wishlist Selector-driven prepared queries (planned)ĭescribed in SLING-10540: prepared GraphQL queries hidden behind Here's an excerpt from an OSGi feature model file which uses the GraphQL Servlet provided by this module See also the caching section later in this file. The GraphQL requests hit a Sling resource in all cases, there's no need for path-mounted servlets which are not desirable. Server-side " prepared GraphQL queries" and the more traditional client-supplied queries.

Idea at this point but it's built into the design so doesn't require more efforts to support. Request selectors and extensions) where queries are executed in the context of that Resource.


This module is one of several which provide GraphQL support for Apache Sling.
