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

Text content type override ignored and defaults to json anyway #1569

Open
toomzzz opened this issue Jun 9, 2022 · 6 comments
Open

Text content type override ignored and defaults to json anyway #1569

toomzzz opened this issue Jun 9, 2022 · 6 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@toomzzz
Copy link

toomzzz commented Jun 9, 2022

Hey, I'm using below to override content type of application/graphql to text:
System.setProperty("pact.content_type.override.application.graphql", "text")

I can see the property being recognised, but I keep getting:
au.com.dius.pact.core.support.json.JsonException: Invalid JSON (1:3), found unexpected character 'd'

'd' is the beginning of the graphql query which is not a valid JSON and why I want to treat it like a text. I've narrowed down the problem to the below line in ContentType.kt where it somehow matches the application/graphql to the json via superType.subtype which it gets from MediaTypeRegistry.

https://github.com/pact-foundation/pact-jvm/blob/d3580fccd1254e87263656133bf96bbcd15b0b0e/core/model/src/main/kotlin/au/com/dius/pact/core/model/ContentType.kt#L28

is there anything I can do to stop this from being treated as json? i'm using the 4.3.8 version of pact-jvm

@toomzzz
Copy link
Author

toomzzz commented Jun 9, 2022

This is actually related to this issue I raised last year:
#1371

I remember the request body being encoded and not a text value. I got around it by setting the property above. After I closed the ticket this change was made which now causes the graphql queries to be treated as json (which it shouldn't):
320cc6f

@rholshausen
Copy link
Contributor

I've just checked the GraphQL spec, the recommendation when using it over HTTP is to use JSON encoded bodies. Is this not the case for you?

What format is being used? If it is not JSON, then Pact will not be able to match it.

@rholshausen
Copy link
Contributor

Can you provide the full stack trace?

@toomzzz
Copy link
Author

toomzzz commented Jun 14, 2022

I think it might be different for different language implementations. Here's the documentation for the GraphQL Java which shows a query syntax I'm using: https://www.graphql-java.com/documentation/batching
I think for the json queries the application/json could be used instead?

Here's the stack trace:
`au.com.dius.pact.core.support.json.JsonException: Invalid JSON (1:3), found unexpected character 'd'

at au.com.dius.pact.core.support.json.JsonLexer.unexpectedCharacter(JsonParser.kt:88)
at au.com.dius.pact.core.support.json.JsonLexer.nextToken(JsonParser.kt:79)
at au.com.dius.pact.core.support.json.JsonParser.nextTokenOrThrow(JsonParser.kt:279)
at au.com.dius.pact.core.support.json.JsonParser.parseObject(JsonParser.kt:184)
at au.com.dius.pact.core.support.json.JsonParser.parse(JsonParser.kt:160)
at au.com.dius.pact.core.support.json.JsonParser.parseString(JsonParser.kt:131)
at au.com.dius.pact.core.model.RequestResponseInteraction$Companion.setupBodyForJson(RequestResponseInteraction.kt:131)
at au.com.dius.pact.core.model.RequestResponseInteraction$Companion.requestToMap(RequestResponseInteraction.kt:93)
at au.com.dius.pact.core.model.RequestResponseInteraction.toMap(RequestResponseInteraction.kt:29)
at au.com.dius.pact.core.model.RequestResponsePact.toMap(RequestResponsePact.kt:33)
at au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:66)
at au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:103)
at au.com.dius.pact.core.model.BasePact.write(BasePact.kt:26)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.afterAll(PactConsumerTestExt.kt:534)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeAfterAllCallbacks$16(ClassBasedTestDescriptor.java:447)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeAfterAllCallbacks$17(ClassBasedTestDescriptor.java:447)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeAfterAllCallbacks(ClassBasedTestDescriptor.java:447)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.after(ClassBasedTestDescriptor.java:229)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.after(ClassBasedTestDescriptor.java:80)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:161)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:161)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)`

@rholshausen
Copy link
Contributor

Found the issue. If you change it to

System.setProperty("pact.content_type.override.application\\graphql", "text")

it should work.

But I will fix that.

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jun 15, 2022
@rholshausen
Copy link
Contributor

Sorry, my mistake. The slash should be the other way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants