You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by David Holiday <da...@holitek.io> on 2021/02/02 20:30:15 UTC

Re: wonkiness with graphql component

The wonky query results turned out to be human error. The other thing was
resolved by using 'toD' - ty! That enabled me to use velocity to template
the query which is muy bueno. ty!





On Sun, Jan 31, 2021 at 8:06 AM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> For dynamic queries in the endpoint uri, then you should use *toD* and
> not *to*. To D is for To Dynamic.
>
> On Sun, Jan 24, 2021 at 9:05 AM David Holiday <da...@holitek.io>
> wrote:
> >
> > Hello fellow Camel riders,
> >
> > I'm trying to use the graphql component to do some integration work with
> > Github and I've noticed some odd behaviors:
> >
> > 1) for some reason, I can't use Simple to dynamically create queries.
> When
> > I log the query it shows up correctly. for example:
> >
> > the JavaDSL statement:
> >
> >
> > *.log(LoggingLevel.INFO, "graphQL URI is: " + GITHUB_GRAPH_QL_URI +
> > "query=${body}&accessToken=${env.GITHUB_ACCESS_TOKEN}")*
> >
> > will yield
> >
> > *[) thread #0 - ProducerTemplate] githubToJiraRoute              INFO
> >  graphQL URI is:
> > graphql:
> http://api.github.com/orgs/XXXX/repos?query={viewer{organization(login
> > <http://api.github.com/orgs/XXXX/repos?query={viewer{organization(login
> >:
> > "XXXX"){repositories(first: 100, ){pageInfo{hasNextPage}nodes { name
> > pullRequests(first: 100, labels: "dependencies", states: OPEN) { nodes {
> > title url } } vulnerabilityAlerts(first: 100) { nodes {
> > securityVulnerability { advisory { description summary severity
> references
> > { url } ghsaId origin permalink } } } } } } } } }&accessToken=XXXXXXXX*
> >
> > however, when I then invoke
> >
> > *.to(GITHUB_GRAPH_QL_URI +
> > "query=${body}&accessToken=${env.GITHUB_ACCESS_TOKEN}")*
> >
> > and intercept the outbound communication using burp I see
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > *POST /orgs/life360/repos HTTP/1.1Accept:
> application/jsonAccept-Encoding:
> > gzip, deflateAuthorization: Bearer
> > ${env.GITHUB_ACCESS_TOKEN}Content-Length: 55Content-Type:
> application/json;
> > charset=UTF-8Host: api.github.com <http://api.github.com>User-Agent:
> > Apache-HttpClient/4.5.13 (Java/11.0.2)Connection:
> > close{"query":"${body}","operationName":null,"variables":{}}*
> >
> >
> > Which tells me that the placeholders aren't getting resolved. *First
> > question: is this expected behavior from this component? *
> >
> >
> >
> > (2) Once I realized that placeholders weren't being resolved I pivoted to
> > hard coding everything to get stuff working. I then noticed that the same
> > query is being handled differently by github depending on whether or not
> I
> > send it through camel-graphql or via other means.
> >
> > for example, the following query will return a paginated list of
> > repositories for an organization and include any dependabot alerts a
> given
> > repository might have
> >
> > *{viewer{organization(login: ORG_NAME_HERE){repositories(first: 100,
> > ){pageInfo{hasNextPage}nodes { name pullRequests(first: 100, labels:
> > "dependencies", states: OPEN) { nodes { title url } }
> > vulnerabilityAlerts(first: 100) { nodes { securityVulnerability {
> advisory
> > { description summary severity references { url } ghsaId origin
> permalink }
> > } } } } } } } }*
> >
> > I've used it in some python scripts and in github's graphql explorer
> > <https://docs.github.com/en/graphql/overview/explorer> and it works
> > beautifully. However, this same exact query when pushed through the camel
> > graphql connector returns an error from github saying my syntax for
> > *creating* a repository isn't correct. To be clear - *the exact same
> query
> > works as expected everywhere BUT when pushed through the camel graphql
> > component.*
> >
> > here are the germane log entries:
> >
> > *[) thread #0 - ProducerTemplate] githubToJiraRoute              INFO
> >  graphQL URI is:
> > graphql:
> http://api.github.com/orgs/XXXX/repos?query={viewer{organization(login
> > <http://api.github.com/orgs/XXXX/repos?query={viewer{organization(login
> >:
> > "XXXX"){repositories(first: 100, ){pageInfo{hasNextPage}nodes { name
> > pullRequests(first: 100, labels: "dependencies", states: OPEN) { nodes {
> > title url } } vulnerabilityAlerts(first: 100) { nodes {
> > securityVulnerability { advisory { description summary severity
> references
> > { url } ghsaId origin permalink } } } } } } } } }&accessToken=XXXXXXXX*
> >
> > *[) thread #0 - ProducerTemplate] githubToJiraRoute              INFO
> >  response is: {"message":"Repository creation
> >
> failed.","errors":[{"resource":"Repository","code":"missing_field","field":"name"},{"resource":"Repository","code":"custom","field":"name","message":"name
> > is too short (minimum is 1
> > character)"}],"documentation_url":"
> https://docs.github.com/rest/reference/repos#create-an-organization-repository
> > <
> https://docs.github.com/rest/reference/repos#create-an-organization-repository
> >"}*
> >
> > If I have to I can pivot back to using github's v3 REST API but if
> possible
> > I'd prefer to use the v4 GraphQL API as it allows me to reduce the number
> > of network calls for complex queries.
> >
> > *Second Question: why would the same query be getting a wonky result only
> > when pushed through the camel graphql connector? *
> >
> >
> > ty!
> >
> > DH
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>