php-graphql-oqm
php-graphql-oqm copied to clipboard
Support for generating `mutationType` objects?
Hi there. I'm curious if adding support for generating mutation objects from the schema is on the roadmap. I've been toying around and have a really quick and dirty branch, but it looks like adding this functionality would require updating to the client lib to add a AbstractMutationBuilder or something similar.
The apollo code gen does this for android and presumably for the node client. Would be real nice to have it for PHP too, but I haven't found this functionality in any other lib.
So, two questions:
- have you already gone down this road and decided against it?
- open to a PR or do you have an idea of how you'd like to see it implemented?
Hi @yanickj ,
Let me answer both your questions:
- I haven't gone this road and decided against it, I just didn't prioritize mutations as a feature in my project generally. Support for mutations arrived in late on the underlying dependency https://github.com/mghoneimy/php-graphql-client, which I wrote too.
- I am very open to a PR and have a vague idea of how I'd like this to be implemented. In fact, most of the tools needed to implement this are already in place as the
Mutationclass extends theQueryclass, so all of their structure is shared.
At this moment in time I have much much less space to work on my projects for personal reasons, but I'm very open to analyzing this during the weekend and providing you with a rough design on the best way to implement this if you're willing to put in the time to implement it.
Let me know what you think.
Thanks for getting back to me @mghoneimy. I'm a little pressed for time as well, but I'm not in a great hurry. I was able to get something "working" but I'll admit I was lazy about implementing interfaces and was just extending the query objects as mutations. This worked fine, but requires duplicating a lot of code in the schema generator if using a different object builder is required (perhaps it's not).
I'll keep an eye on this issue. I'll have a better idea of what I can commit to after seeing the rough outline. Like I said, I'm not in a huge hurry so whenever you get around to putting together a rough design works for me.
Thanks!
@yanickj If you're not in a hurry I'd rather push this by 1-2 weeks. I'll spend time looking into this in the first week September and will provide you with the rough design.
Also, could you please send me a link to the branch you worked on to develop this feature? I'd like to take a look at that.
Thanks!
@mghoneimy take as long as you need :) Here is a link to a very quick and dirty branch. https://github.com/yanickj/php-graphql-oqm/tree/mutation-copy-pasta
I wasn't really able to find a public graphql schema that allowed mutations (no surprise there), but I'll include the following snippet from a pretend hasura backend that provided a schema to generate these the mutation objects...
$mutation = new \GraphQL\SchemaObject\RootMutationObject();
$mutation->selectInsertThingOne(
(new \GraphQL\SchemaObject\RootInsertThingOneArgumentsObject())
->setObject(
(new \GraphQL\SchemaObject\thing_insert_inputInputObject())->setId('foo')
)
)->selectId();
// Would need to create an AbstractMutationBuilder instead of this bologna
$query = (string) $mutation->getQuery()->setOperationName("foo");
print preg_replace("/^query/", "mutation", $query);
One issue I encountered was that the builder instantiated here gets overridden in the schema generator since it creates it's own class builder during the recursion. There is also the business of creating the mutation builder which I think needs to live in the client package.
Is there any update to this? Something somewhere to contribute to?