Coder Social home page Coder Social logo

graphqlphpgenerator's Introduction

OverblogGraphQLPhpGenerator

GraphQL PHP types generator...

Code Coverage Build Status

Requirements

PHP >= 5.4

Installation

composer require overblog/graphql-php-generator

Usage

<?php
$loader = require __DIR__.'/vendor/autoload.php';

use GraphQL\Schema;
use Overblog\GraphQLGenerator\Generator\TypeGenerator;
use Symfony\Component\ExpressionLanguage\Expression;

$configs = [
    'Character' => [
        'type' => 'interface',
        'config' => [
            'description' => new Expression('\'A character\' ~ \' in the Star Wars Trilogy\''),
            'fields' => [
                'id' => ['type' => 'String!', 'description' => 'The id of the character.'],
                'name' => ['type' => 'String', 'description' => 'The name of the character.'],
                'friends' => ['type' => '[Character]', 'description' => 'The friends of the character.'],
                'appearsIn' => ['type' => '[Episode]', 'description' => 'Which movies they appear in.'],
            ],
            'resolveType' => 'Overblog\\GraphQLGenerator\\Tests\\Resolver::resolveType',
        ],
    ],
    /*...*/
    'Query' => [
        'type' => 'object',
        'config' => [
            'description' => 'A humanoid creature in the Star Wars universe or a faction in the Star Wars saga.',
            'fields' => [
                'hero' => [
                    'type' => 'Character',
                    'args' => [
                        'episode' => [
                            'type' => 'Episode',
                            'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.',
                        ],
                    ],
                    'resolve' => ['Overblog\\GraphQLGenerator\\Tests\\Resolver', 'getHero'],
                ],
            ],
        ],
        /*...*/
    ],
];

$typeGenerator = new TypeGenerator('\\My\\Schema\\NP');
$classesMap = $typeGenerator->generateClasses($configs, __DIR__ . '/cache/types');

$loader->addClassMap($classesMap);

$schema = new Schema(\My\Schema\NP\QueryType::getInstance());

graphqlphpgenerator's People

Contributors

mcg-web avatar renatomefi avatar marijnkoesen avatar ruudk avatar vincz avatar casskir avatar

Watchers

Jáchym Toušek avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.