PHP code example of mathsgod / gql-scalar-date

1. Go to this page and download the library: Download mathsgod/gql-scalar-date 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/ */

    

mathsgod / gql-scalar-date example snippets


    
    $gql = "
scalar Date
scalar DateTime
type Query{
    testDate(d:Date):Date
    testDateTime(dt:DateTime):DateTime
}      
";

   $typeConfigDecorator = function ($typeConfig) {
        $name = $typeConfig['name'];

        if ($name === 'Date') {
            $email = new Scalar\Date();

            $typeConfig["serialize"] = [$email, "serialize"];
            $typeConfig["parseLiteral"] = [$email, "parseLiteral"];
        }

            if ($name === 'DateTime') {
            $email = new Scalar\DateTime();

            $typeConfig["serialize"] = [$email, "serialize"];
            $typeConfig["parseLiteral"] = [$email, "parseLiteral"];
        }

        return $typeConfig;
    };

    $schema = BuildSchema::build($gql, $typeConfigDecorator);