GithubHelp home page GithubHelp logo

graphql's Introduction

GraphQL for Drupal

Tests

This module lets you craft and expose a GraphQL schema for Drupal 8.

It is is built around https://github.com/webonyx/graphql-php. As such, it supports the full official GraphQL specification with all its features.

Installation

This module requires composer for installation. To install, simply run composer require drupal/graphql.

Resources

graphql's People

Contributors

akhomy avatar blazeyo avatar chindris avatar chrfritsch avatar clemens-tolboom avatar clemenssahs avatar cryt1c avatar dasjo avatar dawehner avatar dbosen avatar dylan203 avatar fgm avatar fubhy avatar joaogarin avatar justinlevi avatar kingdutch avatar klausi avatar leksat avatar lennardwesterveld avatar martinfrances107 avatar ndrake0027 avatar ohthehugemanatee avatar pasqualle avatar pavlosdan avatar pmelab avatar rthideaway avatar sebas5384 avatar webflo avatar weitzman avatar xuxucode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql's Issues

Decouple graphql_views from graphql_content

graphql_views doesn't necessarily have to depend on graphql_content. We should move the generic entity interface from graphql_content to graphql_core, since it will be required for any config entity/typed data plugin derivers too.

The deriver should check if a matching plugin for the views entity type is available (data_type annotation property) and fall back to the generic entity interface.

Add a hook_requirements() check

Currently, if the installation process has not been followed correctly, users get error pages, or errors in the Graphiql explorer.

It would be better to implement a requirements check to ensure such users receive a more usable error information during install instead of these mystifying error pages.

Expose boolean fields

Boolean Drupal fields should return boolean values. By adding a new module graphql_boolean.

GraphQL public API

I couldn't find mention of this anywhere: is Drupal exposing its API somewhere, even if it would be experimental, similar to what GitHub recently did? If not, is there any plan? Something where people can explore and familiarize themselves without the need to deploy anything anywhere. That could be the main factor preventing people from experimenting with this code and therefore providing feedback.

I very much like Graph.cool's approach, a "GraphQL backend-as-a-service". No need to install anything, developers can concentrate on a front-end deployable to CDN.

Thanks ๐Ÿ˜Š

Suppport for aliases

Currently, the basis for GraphQL types is the entity system on top of TypedData. However, not everything in D8 is an entity (yet ?), notably aliases. These need to be supported.

Unify test suites

Move the GraphQLFileTestTrait to the root graphql module and somehow merge with the existing QueryTestBase.

Expose views field displays

We could generate types for field-based views displays, that work the same as types generated from entity displays. Rendering strings for all fields by default and using the same formatter based enhancers (graphql_image, graphql_entity_reference ...).

This could help with performance and exposing non-entity data (e.g. Solr results).

Update the README.md

Currently instructions in the README are not up-to-date, leading newcomers to failed installs and a first impression that the module doesn't work at all.

This needs to be addressed, and carried over to the D.O. project page.

The "" entity type does not exist

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 125 of /docroot/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

I have several custom entity types created by drupal console. My gut tells me the issue is with those custom types somewhere but I haven't been able to figure out where.

Some thoughts on EntityQuery

EntityQueryDeriver exposes many field arguments:

nodeQuery(
  offset: Int
  limit: Int
  nid: Int
  uuid: String
  vid: Int
  langcode: String
  type: String
  status: GraphQLBoo
  title: String
  uid: Int
  created: String
  changed: String
  promote: GraphQLBoo
  sticky: GraphQLBoo
  revisionLog: String
  revisionTranslationAffected: GraphQLBoo
  defaultLangcode: GraphQLBoo
): [Node]!

Maybe we could only keep offset and limit arguments for <entityType>Query, and create another query like entityPropertyQuery for properties use.

At the end, we have two queries:

nodeQuery(
  offset: Int
  limit: Int
): [Node]!
entityPropertyQuery(
  offset: Int
  limit: Int
  type: EntityType!
  properties: String!
): [Entity]!
enum EntityType {
  Node
  User
}

The properties argument is key-value pairs, like nid=1,type=page

In this way the GraphQL Schema looks more clean.

Consider adding entityTranslation() and entityLanguage fields to entity types.

We could easily add an entityLanguage field that returns the language object of the current translation of an entity. I think that is a no-brainer and should be added in any case.

In addition to that, we could make translations of an entity accessible via a entityTranslation() field with an Enum language arg.

Thoughts?

Raw field data formatter

Add a special field formatter that exposes raw field data in GraphQL.
We will require type and field derivers that generate types for all configured field types.

Enforce GraphQL view mode for entities

Instead of falling back to default view mode, only include entity types with a graphql view mode in the schema.

Also auto-add this view mode for all entities.

Is there multilangage support?

First of all thanks a lot for the really good work!

We currently try to fetch a translated content by passing language in a query "8.x-2.x-dev":

POST https://example.com/de/graphql
{
  nodeQuery (langcode: "de") {
    title
    renderedOutput
  }
}

In this case renderedOutput returns an german translation, BUT title is still in english (master language). Are multilanguage queries supported in the GraphQL module?

For any advice I would be very appreciated!

Pagination on content types ! determining length !?

Hi there , i am trying to get nodes from my article content type , i am wondering how can i use offset and limit since i can't get length of my entity !?

{
    nodeQuery(limit:2 ,offset:4) {
    ... on EntityNodeArticle {
      vid,
      articleImage {
        ... on FieldItemNodeFieldArticleImage {
          entity {
            uri
          }
        }
        alt
        title
        width
        height
      }
    }
  }
}

How can i get length of EntityNodeArticle ? so i can use it for pagination with limit and offset !


Another question is am i able to use pagination in graphql display views , i mean if i create a view and limiting pagination to show 1 node , how can i pass the offset in graphql !

{
   frontpageGraphql1 {
    ...on EntityNodeArticle {
      title
    }
  }
}

Could not parse version constraint 8.x-3.x: Invalid version string "8.x-3.x"

Using the installation instructions, my composer.json looks like this:

{
    "name": "drupal-composer/drupal-project",
    "description": "Project template for Drupal 8 projects with composer",
    "type": "project",
    "license": "GPL-2.0+",
    "authors": [
        {
            "name": "",
            "role": ""
        }
    ],
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/fubhy/graphql-drupal"
        },
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^1.2",
        "drupal-composer/drupal-scaffold": "^2.2",
        "cweagans/composer-patches": "~1.0",
        "drupal/core": "~8.0",
        "drush/drush": "~8.0",
        "drupal/console": "~1.0",
        "drupal/webform": "^5.0@beta",
        "drupal/jsonapi": "^1.0@alpha",
        "drupal/workspace": "^1.0@alpha",
        "drupal/devel": "^1.0@beta"
    },
    "require-dev": {
        "behat/mink": "~1.7",
        "behat/mink-goutte-driver": "~1.2",
        "jcalderonzumba/gastonjs": "~1.0.2",
        "jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
        "mikey179/vfsStream": "~1.2",
        "phpunit/phpunit": "~4.8",
        "symfony/css-selector": "~2.8"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ]
    },
    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        }
    }
}

When running composer require drupal/graphql:8.x-3.x, I'm getting:

[UnexpectedValueException]                                                    
  Could not parse version constraint 8.x-3.x: Invalid version string "8.x-3.x"

How can I resolve this?

Allow for aditionalTypes to be passed into Schema

When fetching nodeById we want to be able to specify an on statement that allows for doing a query like:

{
  nodeById {
    ... on EntityNodeBundleArticle {
      // fields!
    }
  }
}

So in order to do that we need to have the EntityNodeBundleArticle to be on the types list in the Schema.

{
  __schema {
    types {
      name
    }
  }
}

Update README.md file to better reflect the current status quo.

Now that we have a generated schema, the readme file does not adequately resonate the available features that you get out of the box. Instead, it still sounds like you need to write code to get a schema. Let's make the automated schema more visible.

Make root fields explicit (assign them to a root type).

Currently, root fields are defined as fields that are not explicitly attached to any type. Instead, they should be added explicitly to make them also usable within a type. A potential use case would be loading of a view with an optional contextual filter.

Attach views fields to matching types

Views displays that expose a contextual argument of a certain entity type (argument validation options), should be attached to matching types.

Example:

fragment ArticleFragment on NodeArticle {
  title
  body
  relatedArticles {
    title
  }
}

A little help please :)

I just saw this https://events.drupal.org/dublin2016/sessions/no-compromises-%E2%80%93-react-relay-and-graphql-drupal-8

And wanted to try out the module. However it seems like none of what you are demoing is working.

Is there some trick that I am missing?

Currently I can query a node like in issue #21 with a base64 string, but no fields are available. Pretty far from the demo, where both fields and entity references are available.

[EDIT]: I had a bit more time working with the module. I cant say that I have more than the most shallow knowledge yet, but it looks like I have 104 fields in the QueryRoot returning from Drupal\graphql\GraphQL\Relay\Schema. I guess there should be something related to my actual content types here?

`nodeQuery` and `menuLinkContentQuery` by `url_alias`

I'm currently working on a headless Drupal site that is using the GraphQL module to provide data to a React frontend. However I'm beginning to get a little stuck.

Basically I've managed to run a query that get's the main menu items:

fragment menuFields on EntityMenuLinkContent {
  uuid
  title
  parent
  link {
    uri
  }
}

{
  main_menu: menuLinkContentQuery(menuName: "main") {
    ...menuFields
  }
}

Which is great for bootstrapping the menu on every page... BUT because within my Drupal instance I have URL aliases attached to nodes I'd really like to be able to return an alias if it's attached to EntityMenuLinkContent AND I'd really like to be able to run a nodeQuery(urlAlias: '/example-route')?

Any help pointing me in the right direction would be greatly appreciated as I'm a little stuck

Find day and time for recurring contributor meeting.

We used to have a weekly meeting. Let's bring that back now that we've picked up traction again. We are actively working on numerous features and improvements and want to get to a stable 3.x release asap. Obviously, we are looking for additional contributors, too. Let us know when would be a good time for you.

For me, I could free up time at any week day between 2PM and 3PM UTC.

Graph Explorer not working

Updating from 8.x-2.x to 8.x-3.x I'm not able to use graphQL explorer.

given a command like this:

{
  node(id: 1) {
    id
  }
}

I get

{
  "data": {
    "node": null
  },
  "errors": [
    {
      "message": "Resoling function must return type"
    }
  ]
}

Looking at the log messages I can see:

Notice: Undefined offset: 1 in Drupal\graphql\TypeResolver\EntityTypeResolver->canResolveRelayNode() (line 100 of modules/contrib/graphql/src/TypeResolver/EntityTypeResolver.php).

node with ID 1 exists. Inside the node query, not other fields other then id are available when I press cmd+space.

Maybe I'm doing something wrong ?

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.