dadish / ProcessGraphQL

GraphQL for ProcessWire

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add template field via getQuery hook

thomasaull opened this issue · comments

I was trying to add a generic field "template" to all GraphQL fields but failed… Can you help me doing that with the getQuery hook?

getQuery hook only allows you to add top level fields. If you want to add some custom fields, the best way would be adding a field to your templates. Let's say that field is label. Then when you request that field from your GraphQL api, this module will access it as $page->label. This allows you to modify the output of that field with ProcessWire hook. Just use ProcessWire hooks (I don't remember which hook exactly), and make $page->label return anything you want.

Whatever is returned with $page->label will be returned by GraphQL api. But don't forget to respect the type of the field though. If you set label field as FieldtypeText then you should always return string.

Thanks for you reply! This sounds like a good alternative, however my pull requests #7 solves the issue as well!