PHP code example of toppynl / graphql-federation

1. Go to this page and download the library: Download toppynl/graphql-federation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toppynl / graphql-federation example snippets


use Toppynl\GraphQLFederation\FederatedSchemaBuilder;

$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withReferenceResolver('Product', 'id', function (array $rep): array {
        return ProductRepository::findById($rep['id']);
    })
    ->build();

// $fedSchema->schema is a standard webonyx Schema — pass it to GraphQL::executeQuery() as normal
$result = GraphQL::executeQuery($fedSchema->schema, $query, rootValue: null, contextValue: $context);

$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withReferenceResolver('Product', ['id', 'sku'], function (array $rep): array {
        return isset($rep['sku'])
            ? ProductRepository::findBySku($rep['sku'])
            : ProductRepository::findById($rep['id']);
    })
    ->build();

$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withEntityKey('Order', 'id', resolvable: false)
    ->build();