astrotomic/graphql-query-builder

0.1.0 2021-08-11 14:32 UTC

This package is auto-updated.

Last update: 2024-10-11 21:56:49 UTC


README

This package is an opinionated GraphQL Query Builder not fully compatible with all GraphQL specs (yet). In case you miss a feature you can open an issue so we can discuss a solution.

Installation

composer require astrotomic/graphql-query-builder

Usage

use Astrotomic\GraphqlQueryBuilder\Graph;
use Astrotomic\GraphqlQueryBuilder\Query;

Graph::query(
    Query::from('user')
        ->with(['login' => 'Gummibeer'])
        ->select(
            Query::from('sponsorshipsAsMaintainer')
                ->with(['first' => 100, 'after' => 'ABC'])
                ->select(
                    Query::from('pageInfo')->select('hasNextPage', 'endCursor'),
                    Query::from('nodes')->select(
                        Query::from('sponsorEntity')->select(
                            '__typename',
                            Query::for('User')->select('login', 'avatarUrl', 'databaseId', 'name'),
                            Query::for('Organization')->select('login', 'avatarUrl', 'databaseId', 'name'),
                        )
                    )
                )
        )
)
query {
  user(login: "Gummibeer") {
    sponsorshipsAsMaintainer(first: 100, after: "ABC") {
      pageInfo {
        hasNextPage
        endCursor
      }
      nodes {
        sponsorEntity {
          __typename
          ... on User {
            login
            avatarUrl
            databaseId
            name
          }
          ... on Organization {
            login
            avatarUrl
            databaseId
            name
          }
        }
      }
    }
  }
}