Coder Social home page Coder Social logo

lule75 / graphql-drupal-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drupal-up/graphql-drupal-example

0.0 1.0 0.0 1.95 MB

Drupal + GraphQL + React + Apollo app

License: GNU General Public License v2.0

PHP 87.51% HTML 2.22% CSS 0.60% JavaScript 9.67%

graphql-drupal-example's Introduction

About this Example.

This is an example of how to implement GraphQL in Drupal 8. For now the project just exposes it's published node content on the Drupal side and renders it in the React App. It does not do much more than that for now.

What I feel is very important to say is that this example is using the drupal/graphql module version 3. Keep it in mind if you are trying just bits of this example or you are comparing it to some other article out on the web.

Further you will find a detailed explanation of how to install and have it up and running on your local machine.

๐Ÿ’ง The Drupal Part

Drupal GraphQL

The Drupal instance that is feeding the React App is in the web folder. It's composer file thought is in the root of the porject, so you would run your composer commands from the root folder.

The project is using the GraphQL module, version 8.x-3.

The schema in the context of this version of the module is basically the reflection of the Permissions for the specified Content Types.

How to install it you could find in the Install section further on this page.

๐Ÿค– The React App

React GraphQL Drupal

The Aeact App is in the web-app folder.

All the relevant code is in the web-app/src/App.js and web-app/src/NodesView.js files.

There you could find example with ApolloClient how you could make graphql requests the same way you would do them in the GraphiQL interface inside of Drupal (with the only difference of course that there you are authorized as a Drupal user, so if you can't fetch something from here - check the Drupal Permissions ).

How to install it you could find in the Install section further on this page.

๐Ÿ›  Installing

Download this repo.

Install composer packages (from the root of the project).

composer install

Create an empty database.

Install Drupal from configuration.

cd web/
../vendor/bin/drush site:install --existing-config

If you plan to play with it - save the admin password or keep in mind that "drush uli" exists ;)

Create some riddle nodes with a drush command that I implemented. (still from the web/ folder)

../vendor/bin/drush drupalup_create_content:riddle

Clear Drupal's cache. This registers some of the graphql declarations (still from the web/ folder)

../vendor/bin/drush cr

Change the REACT_APP_DRUPAL_URL with [YOUR_DRUPAL_INSTANCE_URL] in web-app/.env (after you create it)

cd ../web-app/
cp .env.example .env
nano .env
# Change the value of REACT_APP_DRUPAL_URL

Install node packages. (still from the web-app/ folder)

npm install

Start the React application. (still from the web-app/ folder)

npm start

Reward your self with a cup of coffee while you are enjoying some riddles โ˜•

graphql-drupal-example's People

Contributors

flesheater avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.