Skip to content

Latest commit

 

History

History
62 lines (58 loc) · 1.18 KB

File metadata and controls

62 lines (58 loc) · 1.18 KB

Convert php-array to GraphQL fields query Build Status

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
            }
        }
    }
}