Yii Framework Forum

GraphQL support planned?

(Schanz15) #1

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.


are you talking about the server or the client implementation?

(Schanz15) #3

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.

(Schmunk) #5

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

(Schanz15) #6

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

(Schmunk) #7

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.

(Schanz15) #8

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.