Skip to content

This library can convert php arrays to GraphQL fields query

License

Notifications You must be signed in to change notification settings

XAKEPEHOK/ArrayGraphQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

This library can convert php arrays to GraphQL fields query

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages