Download the PHP package hsd-tech/graphql without Composer

On this page you can find all versions of the php package hsd-tech/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 graphql

GraphQL

Build Status Coverage Status Scrutinizer Code Quality License

This is a PHP implementation of the GraphQL specification based on the JavaScript reference implementation.

Related projects

Requirements

Table of contents

Installation

Run the following command to install the package through Composer:

Example

Here is a simple example that demonstrates how to build an executable schema from a GraphQL schema file that contains the Schema Definition Language (SDL) for a Star Wars-themed schema (for the schema definition itself, see below). In this example we use that SDL to build an executable schema and use it to query for the name of the hero. The result of that query is an associative array with a structure that resembles the query we ran.

The script above produces the following output:

The GraphQL schema file used in this example contains the following:

Creating a schema

In order to execute queries against your GraphQL API, you first need to define the structure of your API. This is done by creating a schema. There are two ways to do this, you can either do it using SDL or you can do it programmatically. However, we strongly encourage you to use SDL, because it is easier to work with. To make an executable schema from SDL you need to call the buildSchema function.

The buildSchema function takes three arguments:

To create the Source instance you can use the provided FileSourceBuilder or MultiFileSourceBuilder classes.

Resolver registry

The resolver registry is essentially a flat map with the type names as its keys and their corresponding resolver instances as its values. For smaller projects you can use an associative array and lambda functions to define your resolver registry. However, in larger projects we suggest that you implement your own resolvers instead. You can read more about resolvers under the Resolvers section.

Associative array example:

Resolver class example:

Resolver middleware

If you find yourself writing the same logic in multiple resolvers you should consider using middleware. Resolver middleware allow you to efficiently manage functionality across multiple resolvers.

Before middleware example:

After middleware example:

Resolver middleware can be useful for a number of things; such as logging, input sanitization, performance measurement, authorization and caching.

If you want to learn more about schemas you can refer to the specification.

Execution

Queries

To execute a query against your schema you need to call the graphql function and pass it your schema and the query you wish to execute. You can also run mutations and subscriptions by changing your query.

If you want to learn more about queries you can refer to the specification.

Resolvers

Each type in a schema has a resolver associated with it that allows for resolving the actual value. However, most types do not need a custom resolver, because they can be resolved using the default resolver. Usually these resolvers are lambda functions, but you can also define your own resolvers by extending AbstractTypeResolver or AbstractFieldResolver. Alternatively you can also implement the ResolverInterface directly.

A resolver function receives four arguments:

Lambda function example:

Type resolver example:

Field resolver example:

The N+1 problem

The resolver function can return a value, a promise or an array of promises. This resolver function below illustrates how to use promise to solve the N+1 problem, the full example can be found in this test case.

Variables

You can pass in variables when executing a query by passing them to the graphql function.

Context

In case you need to pass in some important contextual information to your queries you can use the $contextValues argument on graphql to do so. This data will be passed to all of your resolvers as the $context argument.

Scalars

The leaf nodes in a schema are called scalars and each scalar resolves to some concrete data. The built-in, or specified scalars in GraphQL are the following:

Custom scalars

In addition to the specified scalars you can also define your own custom scalars and let your schema know about them by passing them to the buildSchema function as part of its $options argument.

Custom Date scalar type example:

Every scalar has to be coerced, which is done by three different functions. The serialize function converts a PHP value into the corresponding output value. TheparseValue function converts a variable input value into the corresponding PHP value and the parseLiteral function converts an AST literal into the corresponding PHP value.

Advanced usage

If you are looking for something that isn't yet covered by this documentation your best bet is to take a look at the tests in this project. You'll be surprised how many examples you'll find there.

Integration

Laravel

Here is an example that demonstrates how you can use this library in your Laravel project. You need an application service to expose this library to your application, a service provider to register that service, a controller and a route for handling the GraphQL POST requests.

app/GraphQL/GraphQLService.php

app/GraphQL/GraphQLServiceProvider.php

app/GraphQL/GraphQLController.php

routes/api.php

Contributors

This project exists thanks to all the people who contribute. Contribute.

Backers

Thank you to all our backers! 🙏 Become a backer

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor

License

See LICENCE.


All versions of graphql with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-mbstring Version *
league/container Version ^3.2
react/promise Version ^2.5
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 hsd-tech/graphql contains the following files

Loading the files please wait ....