Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

GraphQL Support #367

Closed
benhaynes opened this issue Sep 7, 2018 · 31 comments
Closed

GraphQL Support #367

benhaynes opened this issue Sep 7, 2018 · 31 comments
Labels
enhancement New feature or request

Comments

@benhaynes
Copy link
Sponsor Member

🚨 MIGRATED FROM REQUESTS.GETDIRECTUS.COM 🚨

GraphQL support

πŸ‘ = 56

Created 1 year ago by @PierBover


@rijkvanzanten – πŸ‘ (1 year ago)

<3 this


@luminarious – (1 year ago)

As a front-end developer GraphQL feels magical every time and the performance improvements from getting only the data necessary for current view add up quickly!


@nikola66 – πŸ‘ (6 months ago)

It seems in the pipleline for Q2 / 2018 but really counting the days to get this!


@kosirm – πŸ‘ (5 months ago)

GraphQL and Microservices are most fast moving parts of the web in 2018!


@sendtogil – πŸ‘ (3 months ago)

plzzzzzz


@sendtogil – πŸ‘ (3 months ago)

plzzzzzz


@T-Specht – πŸ‘ (1 month ago)

Really looking forward to this feature for the usage with React


@bianpratama – πŸ‘ (3 weeks ago)

Can't wait!


@allanleonardjr – πŸ‘ (2 weeks ago)

Definitely need this!!!!

@benhaynes benhaynes added the enhancement New feature or request label Sep 7, 2018
@stale
Copy link

stale bot commented Dec 12, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 12, 2018
@benhaynes
Copy link
Sponsor Member Author

I think this is the most requested feature by far... and it's the one that comes up in sales conversations the most too. What would it take to add support for this? Even if just to get some of that hype-train action. πŸ˜‰

Could it really be as easy as /_/gql/...? A single endpoint with this alternate query option...

@rijkvanzanten @wellingguzman

@stale stale bot removed the stale label Dec 13, 2018
@rijkvanzanten
Copy link
Member

The problem here is authentication and permissions. Recreating directus' granular permissions system to work with graphql is a lot of work. The next best thing we can do is make the graphql endpoint admin only and give full access to everything (no permissions check whatsoever)

@benhaynes
Copy link
Sponsor Member Author

Ahh, right. I think that's a great option! So all we have to do is check that the token used is an administrator.

Do we have a sense of how long this would take? I assume there are libraries written for this already.

@rijkvanzanten
Copy link
Member

rijkvanzanten commented Dec 13, 2018

https://github.com/webonyx/graphql-php

Came across this

@benhaynes
Copy link
Sponsor Member Author

That one looks pretty good (stars, open issues, docs). @wellingguzman can you give a time estimate?

@Log1x
Copy link

Log1x commented Dec 27, 2018

Really looking forward to this. Having used graphql-php in the past, I think it will be a great fit.

@wellingguzman
Copy link
Contributor

I do not have experience working with GraphQL, and I would love if someone with experience with GraphQL help me to implement this feature. Or If they want to implement it and open a Pull Request, I would be open to help them implement it on Directus.

The idea I am looking to implement is used a GraphQL library (such as graphql-php) to translate the GraphQL query input to an array that php understand (the way it translate query string into array).

I am learning how this all works, so the sooner the help comes the sooner this feature can be implemented.

@benhaynes
Copy link
Sponsor Member Author

I'm not sure if this is the best way, but my thinking is:

This is a single Directus API endpoint where all parameters/options/responses are handled by the GraphQL library. This is an admin only feature (only works with admin tokens/users) and has direct database access with no limited permissions. After Directus checks the auth it let's the endpoint do what it needs to do.

Any community thoughts on this approach or alternatives?

@wellingguzman
Copy link
Contributor

Why remove GraphQL feature for non-admin?

Also if you are an admin you have full access. Or what do you mean by direct database access?

@benhaynes
Copy link
Sponsor Member Author

I don't think we can control or limit access to data with the way GraphQL works. I think it would have to bypass the Directus ACL if I'm not mistaken.

I imagine this endpoint having full access to data and assumed the PHP library would simply accept database credentials (easiest and fastest way to implement).

@wellingguzman
Copy link
Contributor

I don't think we can control or limit access to data with the way GraphQL works. I think it would have to bypass the Directus ACL if I'm not mistaken.

Why? I don't see any different from GraphQL and using query strings or json (in request body) in terms of querying or posting data.

What I understand is that GraphQL is just an input data type, and the library is middleman that helps us translate that request into something the API understand. Same thing we do with JSON, we translate a JSON string to something php understand.

If I am missing something how do you think GraphQL works that won't allow us to control access?

As fas as I am concern, instead of:

https://directus.example/_/items/users?fields=id,name
https://directus.example/_/items/users/1?fields=id,name

We do something like this:

query {
  user {
    id
    name
  }
}

query {
  user(id: 1) {
    id
    name
  }
}

The only different is that instead of using the query string we are using GraphQL. Now, GraphQL has vast of features, as far as I am concern. I am thinking of GraphQL as an input format for what currently works on the API side.

I imagine this endpoint having full access to data and assumed the PHP library would simply accept database credentials (easiest and fastest way to implement).

This is another thing that I don't think makes sense to implement in the core directus, this will be a (MySQL) SQL Wrapper.

@directus directus deleted a comment Jan 3, 2019
@ghost

This comment has been minimized.

@benhaynes

This comment has been minimized.

@puco
Copy link

puco commented Feb 1, 2019

From my point to view, having an admin-only endpoint does not make much sense. So the implementation would have to go through the Directus ACL. Those should be anyhow included in resolvers for the individual types.

The part where it is not like https://directus.example/_/items/users?fields=id,name,https://directus.example/_/items/users/1?fields=id,name is that I would want to query across relationships, e.g.:


query {
   blogs (slug: 'xyz') {
      title
      content
      
      pages {
          headline
          content
     }
  }
}

@benhaynes
Copy link
Sponsor Member Author

Thanks @puco β€” the main reason for starting with admin-only is that it makes it easier/faster to develop. We're a small open-source team, so while we agree that full ACL would be ideal, we're trying to get this done in stages (unless someone knows of a big corporate sponsor who needs this πŸ’Έ ). Also, we're always open to contributions is anyone wants to help out!

@hemratna is the lead for our GraphQL endpoint, and he's just getting started. Depending on how dynamic collections/fields are fetched to build the GQL schema, maybe honoring ACL won't be too difficult... but first we want to get a basic proof-of-concept working.

@benhaynes benhaynes pinned this issue Feb 1, 2019
@rijkvanzanten
Copy link
Member

@puco

The part where it is not like https://directus.example/_/items/users?fields=id,name, is that I would want to query across relationships

Except, you can! Your example would be

https://directus.example/_/items/blogs?fields=title,content,pages.headline,pages.content

@pomazanbohdan
Copy link

pomazanbohdan commented Feb 7, 2019

Maybe I didn’t really understand what you are talking about above (I don’t know enough English), but I’ll say this:
Now very relevant in terms of providing GraphQL is the product https://github.com/hasura/graphql-engine

He forms api on a ready-made database.
And adds ACL and other features on top.
But, based on what I need, and why I got here, I need an admin panel to manage this data.

My point api: https://api.emista.online/console
The implementation of the admin on the react-admin for this point https://hidden-citadel-38499.herokuapp.com/ (login / password any)

Well, I have difficulty creating the GraphQL bundle and react-admin due to the fact that I am not a programmer, but I need authorization, roles, and so on.

I see the work of directus graphql only in this way if you implement GraphQL only as a database:

  • The recommended set of tables that are needed for databases that are in directus (Users, roles, activities, etc.)
  • Or Connect existing schemes to directus basic functionality
    (the β€œusers” table is directus users and so on)
  • Analysis / reading of the point and all the schemes that are in it except the basic ones.
  • Formation according to graphl schemas of directus collections
  • Description of filters in data lists, lists, edit / add forms

@benhaynes
Copy link
Sponsor Member Author

Hey @Pomazan-Bogdan β€” I think that's how @hemratna is building this. We should have a working demo soon and then we'll post a dev link here for review.

@pomazanbohdan
Copy link

I have a question on implementation.
based on how directus now works, work with graphql should be based on the principle of the first scheme.
Based on this, directus should generate it, and there should be a database that can work this way, and this could be a dgraph for example and not a SQL database.
Then there will be no need to write a generator complex schema generator.

@RedactedProfile
Copy link

what's the good word on the status of this feature? any updates?

It's the only hard sell compared to contemporaries is the lack of a graphql endpoint, and im looking forward to telling those interested on the when and the where it may be here

Thanks!

@benhaynes
Copy link
Sponsor Member Author

@RedactedProfile β€” we're squeezing it into our other work-streams:

  • 2 days: Search
  • 2 days: Adding support for Directus built-in collections
  • 1 day: Final round of testing and code overview

As of now we're shooting for a Directus GraphQL beta the first week of April!

@RedactedProfile
Copy link

RedactedProfile commented Mar 25, 2019 via email

@u12206050
Copy link

Love the first week of April :)

@RedactedProfile
Copy link

Love the first week of April :)

why what happened?

@rijkvanzanten
Copy link
Member

@RedactedProfile

[@benhaynes]: As of now we're shooting for a Directus GraphQL beta the first week of April!

πŸ˜„

@RedactedProfile
Copy link

@RedactedProfile

[@benhaynes]: As of now we're shooting for a Directus GraphQL beta the first week of April!

smile

hahaha apologies I had special moment, I thought @u12206050 's comment was in regards to some sort of april 1st / fools day jab or something when I wrote that

@benhaynes
Copy link
Sponsor Member Author

Haha, this was our only April Fools day mis-information...

https://twitter.com/directus/status/1112759052109598725

@stereobooster
Copy link

If Directus was built on PostgreSQL it would be possible to use it with API generators, like

  • hasura - Instant Realtime GraphQL on Postgres
  • PostGraphile - Instantly spin-up a GraphQL API server by pointing PostGraphile at your existing PostgreSQL database
  • PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API

@benhaynes
Copy link
Sponsor Member Author

To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.

This issue being closed does not mean it's not being considered.

@benhaynes benhaynes added this to Proposed in Feature Requests via automation May 20, 2019
@benhaynes benhaynes moved this from Proposed to In Progress in Feature Requests May 20, 2019
@rijkvanzanten
Copy link
Member

This was added in #1005

@rijkvanzanten rijkvanzanten removed this from In Progress in Feature Requests Jun 26, 2019
@benhaynes benhaynes unpinned this issue Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants