Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe + GraphQLite #288

Closed
homersimpsons opened this issue Jul 20, 2020 · 1 comment
Closed

Safe + GraphQLite #288

homersimpsons opened this issue Jul 20, 2020 · 1 comment

Comments

@homersimpsons
Copy link

On a project I am using Safe along side of GraphQLite.

As of Safe 1.0.0 DateTimeImmutable has been added to the library in order to overwrite some function that may failed "silently".

The problem is that GraphQLite do not handle this type of DateTime. It looks like the FQSen is hardcoded there:

case '\\DateTimeInterface':

Example to reproduce the bug:

namespace App\Query;

use Safe\DateTimeImmutable;
use TheCodingMachine\GraphQLite\Annotations\Query;

class MyQuery
{
    /**
     * @Query()
     */
    public function myQuery(DateTimeImmutable $dateTimeImmutable): string
    {
        return 'It does not works';
    }
}

Reported issue:

For parameter $dateTimeImmutable, in App\Query::myQuery, cannot map class "Safe\DateTimeImmutable" to a known GraphQL input type. Check your TypeMapper configuration.
@oojacoboo
Copy link
Collaborator

You need to register a type mapper. This isn't a case of being hardcoded really. What's hardcoded here, is nothing more than a convenience for the PHP core \DateTimeImmutable class.

You're trying to use a custom class. And that's okay, but you need to tell GraphQLite how to handle that. I created a rather generic type mapper that's been working well for us. I suggested having it implemented into the core with a config option to take in a mapping. If this was completed, you'd have a very easy way to map this. It looks like it's scheduled for 4.1 now.

Here is the original issue with the code if you'd like to go ahead and implement using your own custom type mapper...

#178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants