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

Feedback on Relation Inputs Plugin #2273

Open
4 of 6 tasks
litewarp opened this issue Dec 6, 2024 · 7 comments
Open
4 of 6 tasks

Feedback on Relation Inputs Plugin #2273

litewarp opened this issue Dec 6, 2024 · 7 comments

Comments

@litewarp
Copy link

litewarp commented Dec 6, 2024

Would love some feedback on efforts to port the nested-mutations-plugin form v4 to v5.

https://github.com/litewarp/graphile-relation-inputs-plugin

Thanks again for all your hard work.

  • am interested in building this feature myself
  • am interested in collaborating on building this feature
  • am willing to help testing this feature before it's released
  • am willing to write a test-driven test suite for this feature (before it exists)
  • am a Graphile sponsor ❤️
  • have an active support or consultancy contract with Graphile
@github-project-automation github-project-automation bot moved this to 🌳 Triage in V5.0.0 Dec 6, 2024
@benjie
Copy link
Member

benjie commented Dec 9, 2024

https://github.com/litewarp/graphile-relation-inputs-plugin/blob/974192646d442321a59575e0890c8751698e07f5/src/field-inputs-plugin.ts#L384

This is dangerous; instead store a reference:

const oldPlan = field.plan

then overwrite the plan explicitly:

field.plan = EXPORTABLE(...)
return field;

@benjie
Copy link
Member

benjie commented Dec 9, 2024

https://github.com/litewarp/graphile-relation-inputs-plugin/blob/974192646d442321a59575e0890c8751698e07f5/src/init-create-plugin.ts#L110-L111

This is dangerous; types/codecs/etc may appear in different orders, just picking the first and continuing can lead to an unstable schema. If there's a conflict, you should explicitly raise that fact (as an error).

@benjie
Copy link
Member

benjie commented Dec 9, 2024

The main issue that I see is that this does not perform the mutations inside a transaction, so you can get partial success. The only way to achieve the transaction approach currently is to do all of the mutations in a single step (e.g. via withPgClient()) - you can't use the pgUpdateSingle/etc steps within a transaction. We may or may not support doing so in future, via "subroutines" (I'd like to, but I don't know if or when I'll be able to do it).

@benjie benjie removed this from V5.0.0 Dec 9, 2024
@litewarp
Copy link
Author

litewarp commented Dec 9, 2024

Thanks for the feedback.

This is interesting because I assumed that using the steps would let grafast optimize things.

I had considered ejecting from the steps and handling in a single sql statement (basically what the v4 plugin does), but thought it would be preferable to do it through the grafast system.

Back to the drawing board!

@benjie
Copy link
Member

benjie commented Dec 9, 2024

In general, Grafast won't optimise steps that have sideEffects because it's hard to predict what impact those side effects might have. The payloads could be optimized, but the lack of transaction is the main concern here.

@litewarp
Copy link
Author

litewarp commented Dec 9, 2024

That's fair. And makes sense. It seems like a shame to abandon (eject from?) grafast to accomplish these embedded mutations though.

Lack of these embedded mutations has been a blocker for us, so I'm trying to get something together.
Is it fair to say that there would be no downside to writing a traditional "resolver" here? Or is there a benefit to creating a step to handle them?

@benjie
Copy link
Member

benjie commented Dec 10, 2024

If you use a true resolver the schema becomes impure and certain optimisations cannot be used; but there should be no need: pass the parent arg, fieldArgs, and context() into a sideEffect plan and you’ve got the majority of a resolver right there (all you’re missing is resolveInfo).

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