GraphQL support planned?

At my workplace we currently developing a project where we use GraphQL as opposed to traditional REST queries (the backend is not powered by Yii) for queries and mutations. I found this a very helpful technology which also speeds up the overall development process and was woundering if this is something that is considered to be supported natively in Yii 3.0.

4 Likes

are you talking about the server or the client implementation?

Server side

We will have REST API in Yii 3.0, but I don’t think Yii core team has the resources to provide GraphQL implementation. At least not in the initial release. If you have ideas on how this could be implemented feel free to propose these anyway. If we can provide a small set of tools that makes working with GraphQL easier I am for adding these.

4 Likes

I was thinking about a way to use GraphQL (by default) in SearchModels.

A PHP implementation from Crisu is here https://github.com/digiaonline/graphql-php

2 Likes

I am also working on a GraphQL module. Unfortunately I have almost no time for this. But whats already working is the GraphiQL in-browser IDE and /graphql endpoint. The idea is that the module can be configured with a list of model class names (similar to the \yii\rest\ActiveController) and automatically provide a number of GraphQL operations for CRUD.

// Edit: I am working with https://github.com/webonyx/graphql-php for server side GraphQL support. Anything special about the implementation that you linked to @schmunk?

// Edit 2: And I am refering to Yii2

Anything special about the implementation that you linked to @schmunk?

It’s written by https://github.com/crisu83 a former Yii contributor and usually known for excellent code.

1 Like

During my yii2 graphql implementation i realized that it would by very helpful to allow internal requests against \yii\rest\ActiveController. Also see Internal Requests To Restful Api?

In GraphQL there is only a single endpoint (usually /graphql) that is always requested via POST. So currently it is problematic to dispatch incoming requests via graphql to the corresponding ActiveController (e.g. via Yii::$app->runAction) because the VerbFilter will prohibit to run the IndexAction or ViewAction for example. But even if this would work, there are problems with some authentication mechanisms (like QueryParamAuth) that might be used in an ActiveController.

In order to re-use existing ActiveController's for the GraphQL endpoint it would be really helpful if there is a way to internally call the actions in it. Everything that is usually supplied in the request to the REST endpoint (like GET parameters for authentication, pagination, filtering, etc.) should be possible to be passed programmatically.

Hi All,
Currently I am working on Graphql using PHP and Yii 1.1 framework. But I am confused whether it supports Yii 1.1 or not. Could anyone suggest me?

Welcome upasanadash,

GraphQL is not natively supported by Yii (neither version). I am not aware of any 3rd party extensions for GraphQL in Yii 1.x but I also have not used Yii 1.x since GraphQL became a thing. However, this topic is about support for the upcoming Yii 3.0 version. You should better ask your question in the Yii 1.x section.

Could you send me the link for Yii 1.x section?

This post is quite old, but I do think if graphql is not on the roadmap for Yii3. This could be a deal breaker for us at-least, since our plans are to move to GraphQL and use a full js frontend like Vue + Apollo.

Hm, @samdark still no plans to support graphql in Yii3?

I’ve seen Yii 3 project with GraphQL used successfully via https://github.com/webonyx/graphql-php. Not sure if anything additional is needed for more convenience. I’m not really into GraphQL.

Do you happen to have a link to a repository so I could take a look? I’ve come to realize that it isn’t possible to integrate GraphQL and Yii 2 (at least when it comes to access permissions of specific resources). So I would like to see if Yii 3 offers the required flexiblity for this.

Hey, what libs did you tested/checked and rejected?
I also think about use graphql in Yii2.

No. That’s private commercial project.

The same one that was mentioned by samdark (webonyx/graphql-php). The library is good, but Yii is inherently not suitable to use GraphQL (IMO).