Open asfimport opened 2 years ago
@FSchumacher (migrated from Bugzilla): I can reproduce the problem with JMeter 5.5 on Linux. Thanks for the detailed bug description.
@FSchumacher (migrated from Bugzilla): Well, after trying out to replace the newlines (\n) with the string values "\n", it became clear to me, that you already found the solution yourself :)
When you are using giving the GraphQL Sampler the Query manually, JMeter knows, that this is something, that has to be encoded for usage in JSON. If you store the content in a file and include it, JMeter does not know, if it should do the encoding, or not and does not do the encoding itself.
The POST data without the escaped newlines will break the JSON stuff.
So for the moment, you will have to encode it yourself (might be done with a Pre-Processor). I am not sure, whether we can safely do the escaping automatically. Will have to think about it (not sorry, if someone else provides a good solution :))
Mateus Dadalto (migrated from Bugzilla): I see what you mean... This will happen with anything that either comes from a function or it's stored in a variable. I still hope that this behavior gets fixed in future versions (IMHO it is not a user-friendly behavior).
I just want to add that you'll have to deal with everything that might break a JSON (graphQL syntax has quotes in places that can cause this). E.G.:
mutation { createCustomerV2( input: { firstname: "Bob" lastname: "Loblaw" email: "bobloblaw2@example.com" password: "b0bl0bl@w" is_subscribed: true } ) { customer { firstname lastname email is_subscribed } } }
For now the solution I came up with was to add a JSR223 PreProcessor and just treat these cases myself. Here's the PreProcessor code in case someone needs it.
def content = new File(vars.get('fileName')).text; vars.put('queryContent', content.replaceAll(/(\r\n|\r|\n)/, /\n/).replaceAll(/"/, /\"/))
Mateus Dadalto (Bug 66122): I'm trying to set my body based on what is in a file and it fails saying the JSON is invalid. But when I set the request body manually the same content the request works. In the results tree view I can see that the only difference is that the manual request is "encoded", it has /n instead of visual newlines.
Steps to reproduce:
-1: Download and open the .jmx attached to this bug -2: Create a file with the content being the body from the first request ("With Body Set Manually") -3: change the path on the second request ("With Body From File") to your file path -4: Run and see in the View Results Tree that the first one works and the second one fails
Created attachment Jmeter%20GraphQl%20Bug.jmx: A sample project to reproduce the bug
Jmeter%20GraphQl%20Bug.jmx
````xmltrue
Severity: normal OS: Linux