-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Change in Mutation #4
Comments
Hey @rotexhawk - thanks for the feedback. In short: I'd love to be able to have a simple, single mutation for doing form submissions, but because Gravity Forms forms can have any number of fields in any order, and the GraphQL specification does not current support input union types, it's not currently possible without hacky workarounds. Here's some more info: I originally had a very simple mutation for submitting forms, similar to the mock one in the code snippet you provided. The problem with it is that it assumes that every form field value can be represented as a single string of text. There are many that can't, however. Examples: Address fields have an array of 6 values, Chained Select fields have an array of X number of values, Multiselect fields have an array of X number of values, Name fields have an array of 5 values, File Upload fields get submitted as multipart form data, etc. When using GraphQL, you have to define your schema so that GraphQL "knows" exactly which input fields a mutation has. This poses a problem for form builder tools like Gravity Forms -- how do you define the input fields in your schema if the Gravity Forms forms on the site can have any fields, in any order? I worked closely with @jasonbahl, the creator of WPGraphQL on this problem, and these were the solutions we came up with:
So that's why #3 was chosen as the best solution currently available. I completely agree that it would be more ideal to have a single mutation for handling form submissions, but as I stated above, until the GraphQL spec support input union types, that's not a viable option for us. Please let me know if you have any more feedback on the approach - I'd love to hear other ideas. Notes on multiple HTTP requests and resuming draft entriesIf you're concerned having to fire off multiple HTTP requests rather than one, please note that you don't even have to wait until the user hits "submit" to execute them. For example, in my decoupled frontend React app, I'm doing this:
This has the added benefit of saving the user's progress in real time. If the user were to close their browser and open your app back up later, you would be able to grab the resume token from their previous session and pass it in to the Defining your own form-specific submission mutationIf you don't want to use the form submission mutations that the plugin provides, you can totally roll your own that's specific to one form. So if you have a single contact form on your site, for example, you can register a new mutation that has the input fields it needs hardcoded, and then ultimately call Gravity Forms' |
@kellenmace Really appreciate the detailed explanation. Learned a lot reading through the RFC. The process you outlined for the form submission makes it easier to reason about the FE implementation. I will try to implement this and get back to you if I run into any issues. Thanks again! |
@rotexhawk Yeah, my pleasure! Cool - sounds great. 👍🏼 |
Update: as of v0.4.0 there is a new It's still not the ideal situation (some of the more complex fields require a field-specific |
Hi, is the workaround still necessary since the introduction of "OneOf Input Objects" variant to the GraphQL spec graphql/graphql-spec#825? Thanks, and great work! |
Hey @earwickerh As you can see from the PR your linked to, oneOf has yet to be merged into the spec. More importantly, it's yet to be added to PHP graphql-php. |
First thank you for creating this plugin. I wanted to see what's the reason behind the API change. The previous implementation was much simpler and intuitive. It doesn't make sense for a user to send a draft mutation and then send mutations for updating every field and then send a final mutation to submit the form. Unless I am not understanding the new API, this is overly complicated. I know it might make sense to keep the implementation similar to the gravity form's core API but to the end users it doesn't matter much. It might be best to add a stand-alone mutation to submit the form in one request.
This makes sense
The text was updated successfully, but these errors were encountered: