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

Failed to read a GraphQL query from a ConfigMap #1403

Closed
abkieling opened this issue Apr 11, 2020 · 4 comments
Closed

Failed to read a GraphQL query from a ConfigMap #1403

abkieling opened this issue Apr 11, 2020 · 4 comments

Comments

@abkieling
Copy link

GraphQL queries with the query specified in the URI work fine but queries stored in ConfigMaps don't seem to work. An exception is thrown when trying to read the query text.

Command:

kamel run --configmap=hello-config hello.groovy --dev

hello.groovy

from('timer:tick?period=10s')
    .to("graphql://https://countries.trevorblades.com/?query={{query.continents}}")
    .to('log:info')

hello-config.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: hello-config
data:
  application.properties: |
    query.continents={continents{code name}}

Error:

[1] Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[graphql://https://countries.trevorblades.com/?query={{query.continents}}] <<< in route: Route(route1)[From[timer:tick?period=10s] -> [To[graphql://h... because of Missing {{ from the text: {continents{code name}}
[1] 	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:386)
[1] 	at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:108)
[1] 	at org.apache.camel.impl.DefaultModel.start(DefaultModel.java:356)
[1] 	at org.apache.camel.impl.DefaultModel.startRoute(DefaultModel.java:330)
[1] 	at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:323)
[1] 	at org.apache.camel.impl.DefaultModel.startRouteDefinitions(DefaultModel.java:302)
[1] 	at org.apache.camel.impl.AbstractModelCamelContext.startRouteDefinitions(AbstractModelCamelContext.java:342)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.doStartCamel(AbstractCamelContext.java:2595)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.lambda$doStart$2(AbstractCamelContext.java:2443)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.doWithDefinedClassLoader(AbstractCamelContext.java:2460)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.doStart(AbstractCamelContext.java:2441)
[1] 	at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:117)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2350)
[1] 	at org.apache.camel.k.main.ApplicationRuntime$MainAdapter.doStart(ApplicationRuntime.java:189)
[1] 	at org.apache.camel.support.service.ServiceSupport.start(ServiceSupport.java:117)
[1] 	at org.apache.camel.main.MainSupport.run(MainSupport.java:77)
[1] 	at org.apache.camel.k.main.ApplicationRuntime.run(ApplicationRuntime.java:76)
[1] 	at org.apache.camel.k.main.Application.main(Application.java:42)
[1] Caused by: java.lang.IllegalArgumentException: Missing {{ from the text: {continents{code name}}
[1] 	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.readProperty(DefaultPropertiesParser.java:139)
[1] 	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:102)
[1] 	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.doParse(DefaultPropertiesParser.java:113)
[1] 	at org.apache.camel.component.properties.DefaultPropertiesParser$ParsingContext.parse(DefaultPropertiesParser.java:86)
[1] 	at org.apache.camel.component.properties.DefaultPropertiesParser.parseUri(DefaultPropertiesParser.java:59)
[1] 	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:262)
[1] 	at org.apache.camel.component.properties.PropertiesComponent.parseUri(PropertiesComponent.java:166)
[1] 	at org.apache.camel.impl.engine.AbstractCamelContext.resolvePropertyPlaceholders(AbstractCamelContext.java:1661)
[1] 	at org.apache.camel.model.ProcessorDefinitionHelper.resolvePropertyPlaceholders(ProcessorDefinitionHelper.java:806)
[1] 	at org.apache.camel.reifier.ProcessorReifier.makeProcessorImpl(ProcessorReifier.java:551)
[1] 	at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:537)
[1] 	at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:250)
[1] 	at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:384)
[1] 	... 17 more
@nicolaferraro
Copy link
Member

I guess there's something wrong in the parser or we need some escaping. The }} in the query makes the parser to require a {{.

@abkieling
Copy link
Author

Yep, there seems to be an issue with the parser when the property values contain double curly braces. About my example, thanks for letting me know that I should be using the --resource flag to expose the GraphQL query file to the app. It's working fine the following way:

Command

kamel run hello.groovy --resource hello.graphql

hello.groovy

from('timer:tick?period=10s')
    .to("graphql://https://countries.trevorblades.com/?queryFile=hello.graphql")
    .to('log:info')

hello.graphql

query Continents {
  continents {
    code
    name
  }
}

Output

...
2020-04-13 11:31:11.324 �[32mINFO �[m [Camel (camel-k) thread #1 - timer://tick] info - Exchange[ExchangePattern: InOnly, BodyType: String, Body: {"data":{"continents":[{"code":"AF","name":"Africa"},{"code":"AN","name":"Antarctica"},{"code":"AS","name":"Asia"},{"code":"EU","name":"Europe"},{"code":"NA","name":"North America"},{"code":"OC","name":"Oceania"},{"code":"SA","name":"South America"}]}}]
...

@abkieling
Copy link
Author

@nicolaferraro The issue seems to be in the Camel code, not in the Camel K code. Shall I close this issue?

@lburgazzoli
Copy link
Contributor

@akieling yes please

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

3 participants