Skip to content

Navigation Menu

Sign in
Sign up

Convert YAML definitions to PHP #889

Answered by mcg-web
ruudk asked this question in Q&A
Discussion options

Does somebody have experience with converting YAML definitions to PHP classes?

I want to do this in an automated way as we have hundreds of them.

You must be logged in to vote

Yaml types are always converted to php classes for a performance purpose. You can use command graphql: compile to generate them on demand.

Replies: 1 comment 8 replies

Comment options

Yaml types are always converted to php classes for a performance purpose. You can use command graphql: compile to generate them on demand.

You must be logged in to vote
8 replies
Comment options

@ruudk this bundle is just a wrapper for webonyx/graphql-php and it basically just generates PHP Types for you from YAML, Annotations or GraphQL SDL. The generated classes are Symfony services. That means that you can just take the generated PHP classes and use them as your source (as you assumed). Well, technically these classes are already used as your sources, so the only thing you have to do is just to move them from the output folder somewhere alse and make them services and that's it. The GraphQLBundle will use these classes automatically. Here are some examples: #683

Comment options

@murtukov Thanks, I tried it and copied all the compiled PHP files into my src directory, but I still notice that the bundle takes all them and compiles them again (same output, except namespace) to my defined cache_dir. Why does it have to do that? I just want to reference all my code from the src directory, without compilation phase.

Comment options

I think I solved it:

 'use_classloader_listener' => false,
 'auto_compile' => false,
 'show_debug_info' => '%kernel.debug%',
 'config_validation' => false,
 'mappings' => [
 'auto_discover' => [
 'root_dir' => false,
 'bundles' => false,
 'built_in' => false,
 ],
 ],
Comment options

@ruudk when you are in dev environment it always recompiles your php types from YAML, Annotations etc. In prod mode it does it only once, until you clear the cache.

The 'auto_compile' => false option disables the autocompilation completely. You don't have to set any other options to disable it.

Comment options

Thanks for the help. I was able to convert all my YAML configs to PHP and disable auto_compile. 🚀

Answer selected by ruudk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /