Test your PHP GraphQL server in style, with Pest!

Overview

Pest GraphQL Plugin

Test your GraphQL API in style, with Pest!

Installation

Simply install through Composer!

composer require --dev miniaturebase/pest-plugin-graphql

What's Added?

  • Test your schema as code;
  • Assert PSR-7 GraphQL response data and errors;
  • Testing resolvers (Coming Soon!);

Expectations

  • schema(string|Schema $document)
  • isValidSdl()
  • toHaveDirective(string $directive)
  • toHaveEnum(string $enum)
  • toHaveInput(string $input)
  • toHaveInterface(string $interface)
  • toHaveScalar(string $scalar)
  • toHaveType(string $type)
  • toHaveUnion(string $union)
  • toBeGraphQlResponse()
  • toHavePath(string $path, $value = null)
  • toHaveData(array $data)
  • toHaveErrors(array $errors)

And more on the way!

schema(string|Schema $document)

Create a new expectation with a GraphQL\Type\Schema instance as the underlying value.

test('my schema')->schema();
it('is my schema')->schema();
Pest\GraphQl\schema();

You can also provide an alternative schema path or document contents, like so.

it('uses any schema you want')->schema(sprintf('%s/../app/schema.graphql', __DIR__));
test('inline content')->schema(<<<'GRAPHQL'
type Query {
    foo: Int
    bar: Int
}
GRAPHQL);
it('even uses your instance')->schema(AcmeSchemaBuilder::build());

isValidSdl()

Assert that the schema is valid and written to the GraphQL specification.

it('validates your schema')->schema()->isValidSdl();

toHaveDirective(string $directive)

Assert that the given directive definition exists with the schema document.

it('has a directive')->schema()->toHaveDirective('auth')
it('will also use base classnames')->schema()->toHaveDirective(Auth::class);

toHaveEnum(string $enum)

Assert that the given enum definition exists with the schema document.

it('has an enum')->schema()->toHaveEnum('Status')
it('will also use base classnames')->schema()->toHaveEnum(Status::class);

toHaveInput(string $input)

Assert that the given input definition exists with the schema document.

it('has a input')->schema()->toHaveInput('Message')
it('will also use base classnames')->schema()->toHaveInput(Message::class);

toHaveInterface(string $interface)

Assert that the given interface definition exists with the schema document.

it('has a interface')->schema()->toHaveInterface('Notification')
it('will also use base classnames')->schema()->toHaveInterface(Notification::class);

toHaveScalar(string $scalar)

Assert that the given scalar definition exists with the schema document.

it('has a scalar')->schema()->toHaveScalar('Date')
it('will also use base classnames')->schema()->toHaveScalar(Date::class);

toHaveType(string $type)

Assert that the given (object) type has been defined within the schema document.

it('has mutations')->schema()->toHaveType('Mutation');
test('user defined types too')->schema()->toHaveType('User');
it('will also use your base classnames')->schema()->toHaveType(User::class);

toHaveUnion(string $union)

Assert that the given union definition exists with the schema document.

it('has a union')->schema()->toHaveUnion('Character')
it('will also use your base classnames')->schema()->toHaveUnion(Character::class);

toBeGraphQlResponse()

Assert that an underlying (PSR-7) response value is a compliant with the GraphQL specification.

test('response validity')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toBeGraphQlResponse();

toHavePath(string $path, $value = null)

Assert that the underlying GraphQL response contains data at the given path. Optionally provide a value to be checked as well!

it('reads paths')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHavePath('foo')
    ->toHavePath('foo', 1)
    ->not()
    ->toHavePath('foo.bar')
    ->not()
    ->toHavePath('foo', 0);

toHaveData(array $data)

Assert that the underlying response GraphQL data is canonically equal to the expected data.

it('contains response data')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHaveData([
        'foo' => 1,
    ]);

toHaveErrors(array $errors)

Assert that the underlying response GraphQL errors are canonically equal to the exepected set of errors.

it('has errors')
    ->expect($response) // a Psr\Http\Message\ResponseInterface instance
    ->toHaveErrors([
        [
            'message'   => 'Oops, I did it again',
            'locations' => [['line' => 1, 'column' => 5]],
            'path'      => ['foo'],
        ],
    ]);

This repository was based off of the Pest Plugin Template.

Pest was created by Nuno Maduro under the Sponsorware license. It got open-sourced and is now licensed under the MIT license.

You might also like...
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.

API Platform is a next-generation web framework designed to easily create API-first projects without compromising extensibility and flexibility: Desig

GraphQL Bundle for Symfony 2.

Symfony 2 GraphQl Bundle Use Facebook GraphQL with Symfony 2. This library port laravel-graphql. It is based on the PHP implementation here. Installat

Laravel wrapper for Facebook's GraphQL

Laravel GraphQL Use Facebook's GraphQL with Laravel 6.0+. It is based on the PHP port of GraphQL reference implementation. You can find more informati

A framework for serving GraphQL from Laravel
A framework for serving GraphQL from Laravel

Lighthouse A framework for serving GraphQL from Laravel Lighthouse is a GraphQL framework that integrates with your Laravel application. It takes the

🍞🧑‍🍳 An on-the-fly GraphQL Schema generator from Eloquent models for Laravel.

An on-the-fly GraphQL Schema generator from Eloquent models for Laravel. Installation Quickstart Model schemas Installation This package requires PHP

GraphQL implementation with power of Laravel

Laravel GraphQL Use Facebook GraphQL with Laravel 5.2 =. It is based on the PHP implementation here. You can find more information about GraphQL in t

Add Price Including tax for Magento's "cart" GraphQl query

Comwrap_GraphQlCartPrices Add Price Including tax for Magento's "cart" GraphQl query Query will looks like following: items { id __typenam

A Statamic Pro addon that provides alternative GraphQL queries for collections, entries and global sets.

Statamic Enhanced GraphQL A Statamic CMS GraphQL Addon that provides alternative GraphQL queries for collections, entries and global sets. ⚠️ This is

Place where I record all knowledge gained for GraphQL from Laracasts & other tutorials.

Knowledge from Laracasts series: https://laracasts.com/series/graphql-with-laravel-and-vue What is GraphQL It is a query language for your API, and it

Releases(v1.0.1)
Owner
Minibase
A place for miniature and model painters to gain insight into their working habbits & statistics.
Minibase
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder

PoP PoP is a monorepo containing several projects. The GraphQL API for WordPress plugin GraphQL API for WordPress is a forward-looking and powerful Gr

Leonardo Losoviz 265 Jan 7, 2023
Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server.

Field Query Syntax to query GraphQL through URL params, which grants a GraphQL API the capability to be cached on the server. Install Via Composer com

PoP 4 Jan 7, 2022
This bundle provides tools to build a complete GraphQL server in your Symfony App.

OverblogGraphQLBundle This Symfony bundle provides integration of GraphQL using webonyx/graphql-php and GraphQL Relay. It also supports: batching with

Webedia - Overblog 720 Dec 25, 2022
Pure PHP implementation of GraphQL Server – Symfony Bundle

Symfony GraphQl Bundle This is a bundle based on the pure PHP GraphQL Server implementation This bundle provides you with: Full compatibility with the

null 283 Dec 15, 2022
GraPHPinator ⚡ 🌐 ⚡ Easy-to-use & Fast GraphQL server implementation for PHP

Easy-to-use & Fast GraphQL server implementation for modern PHP. Includes features from latest draft, middleware directives and modules with extra functionality.

Infinityloop.dev 34 Dec 14, 2022
EXPERIMENTAL plugin extending WPGraphQL to support querying (Gutenberg) Blocks as data, using Server Side Block registries to map Blocks to the GraphQL Schema.

WPGraphQL Block Editor This is an experimental plugin to work toward compatiblity between the WordPress Gutenberg Block Editor and WPGraphQL, based on

WPGraphQL 29 Nov 18, 2022
The server component of API Platform: hypermedia and GraphQL APIs in minutes

API Platform Core API Platform Core is an easy to use and powerful system to create hypermedia-driven REST and GraphQL APIs. It is a component of the

API Platform 2.2k Dec 27, 2022
Pure PHP realization of GraphQL protocol

Looking for Maintainers! Unfortunatelly, we cannot longer support this package and are looking for someone to take the ownership. Currently Only PRs w

null 714 Dec 21, 2022
A PHP port of GraphQL reference implementation

graphql-php This is a PHP implementation of the GraphQL specification based on the reference implementation in JavaScript. Installation Via composer:

Webonyx 4.4k Jan 7, 2023
A PHP implementation of the GraphQL specification based on the JavaScript reference implementation

GraphQL This is a PHP implementation of the GraphQL specification based on the JavaScript reference implementation. Related projects DateTime scalar R

Digia 219 Nov 16, 2022