xakepehok/array-graphql

This library can convert php arrays to GraphQL fields query

Installs: 130 501

Dependents: 3

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/xakepehok/array-graphql

0.0.1 2019-07-30 11:29 UTC

This package is auto-updated.

Last update: 2025-09-29 02:21:23 UTC


README

This library can convert php arrays to GraphQL fields query. It can remove duplicate fields and can thrown exceptions about incorrect array data

Installation

composer require xakepehok/array-graphql

Usage

<?php
$fields = [
    'id',
    'id',
    'registeredAt',
    'name' => [
        'firstName',
        'firstName',
        'middleName',
        'lastName',
    ],
    'history' => [
        'count',
        'count',
        'records' => [
            'id',
            'name' => [
                'firstName',
                'middleName',
                'lastName',
            ],
        ]
    ],
];

echo \XAKEPEHOK\ArrayGraphQL\ArrayGraphQL::convert($fields);

will print something like

{
    id,
    registeredAt,
    name {
        firstName,
        middleName,
        lastName
    },
    history {
        count,
        records {
            id,
            name {
                firstName,
                middleName,
                lastName
            }
        }
    }
}