Download the PHP package pomelchenko/yii2-graphql without Composer

On this page you can find all versions of the php package pomelchenko/yii2-graphql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-graphql

yii-graphql

Using Facebook GraphQL PHP server implementation. Extends graphql-php to apply to YII2.

Latest Stable Version CI Coverage Status Total Downloads

Languages: 中文

Originally created by tsingsun; continued development in this fork.


Features

Install

Using composer

Requires PHP ≥ 7.4 and is tested against webonyx/graphql-php 14.x and ecodev/graphql-upload 6.1.x.

Before upgrading, review the version-by-version instructions in UPGRADE.md.

Development

Run PHP_CodeSniffer and PHPStan locally before opening PRs:

Type

The type system is the core of GraphQL, which is embodied in GraphQLType. By deconstructing the GraphQL protocol and using the graph-php library to achieve fine-grained control of all elements, it is convenient to extend the class according to its own needs

The main elements of GraphQLType

The following elements can be declared in the $attributes property of the class, or as a method, unless stated otherwise. This also applies to all elements after this.

Element Type Description
name string Required Each type needs to be named, with unique names preferred to resolve potential conflicts. The property needs to be defined in the $attributes property.
description string A description of the type and its use. The property needs to be defined in the $attributes property.
fields array Required The included field content is represented by the fields() method.
resolveField callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info) For the interpretation of a field. For example: the fields definition of the user property, the corresponding method is resolveUserField(), and $value is the passed type instance defined by type.

Query

GraphQLQuery and GraphQLMutation inherit GraphQLField. The element structure is consistent, and if you would like a reusable Field, you can inherit it. Each query of Graphql needs to correspond to a GraphQLQuery object

The main elements of GraphQLField

Element Type Description
type ObjectType For the corresponding query type. The single type is specified by GraphQL::type, and a list by Type::listOf(GraphQL::type).
args array The available query parameters, each of which is defined by Field.
resolve callback function($value, $args, $context, GraphQL\Type\Definition\ResolveInfo $info) $value is the root data, $args is the query parameters, $context is the yii\web\Application object, and $info resolves the object for the query. The root object is handled in this method.

Mutation

Definition is similar to GraphQLQuery, please refer to the above.

Inline query definitions

If you prefer not to create a dedicated GraphQLQuery class, schema entries may also be declared as plain arrays using the same structure that webonyx/graphql-php expects. Provide the type, args, and resolver (closure, callable array, etc.) directly in the configuration. GraphQL::type() can be referenced even before Yii::$app is instantiated, so simply pass the resulting Type:

This is useful for simple fields or when you already have reusable resolver classes. For more complex logic you can still rely on dedicated GraphQLQuery/GraphQLMutation classes so that type(), args(), resolve() and rules() remain encapsulated.

Simplified Field Definition

Simplifies the declarations of Field, removing the need to defined as an array with the type key.

Standard Definition

Simplified Definition

Yii Implementation

General configuration

JsonParser configuration required

Module support

Can easily be implemented by extending yii\graphql\GraphQLModule (or implementing GraphQLModuleInterface and using the trait). The trait is responsible for initialization.

In your application configuration file:

Use the controller to receive requests by using yii\graphql\GraphQLAction

Component Support

also you can include the trait with your own components,then initialization yourself.

Input validation

Validation rules are supported. In addition to graphql based validation, you can also use Yii Model validation, which is currently used for the validation of input parameters. The rules method is added directly to the mutation definition.

Mutation validation helper

GraphQLMutation ships with the yii\graphql\traits\ShouldValidate trait. Whenever your mutation defines rules() (same format as a regular Yii model), the trait wraps the resolver and calls DynamicModel::validateData() before resolve() executes. If validation fails, an InvalidParamException is thrown automatically and the resolver is not executed.

Custom validators, inline callbacks, and any other Yii rule syntax are fully supported, so you can reuse existing validation logic without duplicating it inside resolvers.

Authorization verification

Since graphql queries can be combined, such as when a query merges two query, and the two query have different authorization constraints, custom authentication is required. I refer to this query as "graphql actions"; when all graphql actions conditions are configured, it passes the authorization check.

Authenticate

In the behavior method of controller, the authorization method is set as follows

If you want to support IntrospectionQuery authorization, the corresponding graphql action is __schema

Authorization

If the user has passed authentication, you may want to check the access for the resource. You can use GraphqlAction's checkAccess method in the controller. It will check all graphql actions.

When checkAccess is configured, GraphQLAction invokes it for every requested GraphQL action even when CompositeAuth is not attached. Mutation transport and access-check requirements are available as opt-in hardening so existing applications keep their current behavior:

With these options enabled, the selected mutation must use POST as both the original HTTP transport method and Yii's effective method, and must have a configured checkAccess callback. Yii's _method parameter and X-Http-Method-Override header cannot upgrade a non-POST transport or downgrade a POST transport while satisfying requirePostForMutations. Applications that intentionally trust method overrides must set this flag to false and validate the proxy and override before GraphQLAction runs.

requirePostForMutations defaults to null: a non-POST mutation keeps the legacy behavior but emits an E_USER_DEPRECATED warning. Set it explicitly to false to retain that behavior without a warning; its default will become true in the next major release. requireAccessCheckForMutations defaults to false and remains opt-in. Mutation detection follows the operation selected by operationName, so other operations in the same document do not activate these requirements.

Multipart upload support

GraphQLAction detects operations/map payloads and delegates parsing to ecodev/graphql-upload. Ensure multipart/form-data requests include those keys so uploaded files are injected into GraphQL variables.

Testing

Run the test suite locally or via Docker:

This exercises the GraphQL facade, controller action, upload middleware, and custom types to guard against regressions when dependencies are upgraded.

GitLab release pipeline

When this repository is mirrored into GitLab (Settings → Repository → Mirroring repositories) and the Trigger pipelines when updates are mirrored option is enabled, GitLab creates a pipeline after a tag is mirrored. The bundled .gitlab-ci.yml includes the publish_package job only for tags in the strict MAJOR.MINOR.PATCH format without a v prefix (for example, 0.17.1). The job uses the GitLab Packages API plus the job token to update your private Composer registry entry based on CI_COMMIT_TAG, but it must be started manually by a maintainer.

Steps to publish a release:

  1. Configure mirroring (or push from GitHub Actions) so GitLab sees every new tag.
  2. Enable the “trigger pipelines” flag on the mirror or push directly so GitLab CI starts for mirrored updates.
  3. Create and push a tag in the MAJOR.MINOR.PATCH format without a v prefix, such as 0.17.1.
  4. After GitLab receives the tag, open the resulting pipeline and manually start publish_package. The Composer package is not published until this job is approved and started.

Demo

Creating queries based on graphql protocols

Each query corresponds to a GraphQLQuery file.

Define type files based on query protocols

Query instance

Exception Handling

You can config the error formater for graph. The default handle uses yii\graphql\ErrorFormatter, which optimizes the processing of Model validation results.

Future


All versions of yii2-graphql with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
ecodev/graphql-upload Version ^6
laminas/laminas-diactoros Version ^2.17
webonyx/graphql-php Version ^14
yiisoft/yii2 Version ~2.0.10
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pomelchenko/yii2-graphql contains the following files

Loading the files please wait ...