Make test client's fileUploadMutation
work for more input variable shapes
#3188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In the testing package, Vendure provides a
SimpleGraphQLClient
that has a function calledfileUploadMutation
. This function works for the built-in GraphQL mutations that accept file uploads, but if you add a custom mutation that accepts file inputs, as the docs show you how to do, you will run into problems, since it assumes that it can find theUpload
inputs in the GraphQL variables just by looking at the first property of each nested object. So, for example, the existing code that creates the FormData body for the upload will go into an infinite loop if there are any string fields before the Upload fields in your GraphQL mutation input. I detailed the problem that I ran into with this in #1671.So, this PR makes the
fileUploadMutation
method work with mutation inputs with arbitrary shapes.Also, the two tests for this functionality that exist seem to be written for Jest, and there is no
test
command inside thetesting
package.json to run them. I converted the test file to Vitest and added thetest
command so that they could be run.Breaking changes
None: the
fileUploadMutation
should work the same as it always had for the mutations it previously worked with, as shown by the two existing tests passing.Checklist
📌 Always:
👍 Most of the time: