Add support for enum to Utils::stringifyValue in order to support enum as default value of class property #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Sorry for explaining the PR by example with another project but I do not use
php-code-generatordirectly.)EDIT: Check my comment #21 (comment) below for much simpler example.
I am using
graphql:compilecommand fromoverblog/graphql-bundle(https://github.com/overblog/GraphQLBundle/blob/master/docs/index.md) which internally usesphp-code-generator.When I ran
composer graphql:compileI got the following error:I had GraphQL types defined as follows:
The CompileCommand tried to generate a PHP file that looks like this:
however, without the changes in this PR it was failing when generating the line:
because
\Murtukov\PHPCodeGenerator\Utils::stringifyValuewas trying to call__toStringmethod on the enum instance\MyApp\LinkType::INSTAGRAMwhich is not possible because enums do not have (and cannot have)__toStringmethod.I realized that when calling
stringifyValuewith enum instance, we can simply return a fully-qualified reference to the enum value itself. So that is exactly what this PR does.Note
I was also thinking about returning the string value of the enum, but:
graphql:dump-schemacommand was throwing this error: