grooviter / gql

Groovy GraphQL library
http://grooviter.github.io/gql/
Apache License 2.0
49 stars 6 forks source link

Trying to use gql from Jenkins Shared Library #35

Closed deiga closed 3 years ago

deiga commented 3 years ago

We are trying to use the gql library to do GQL calls from inside a Jenkinsfile

In a Shared Library we have the following snippet defined:

@Grab("com.github.grooviter:gql-core:0.4.0")
@GrabExclude('org.codehaus.groovy:groovy-all')
import gql.DSL
import gql.dsl.QueryBuilder
import gql.dsl.query.ReturnsBlockBuilder
import groovy.json.JsonOutput
import com.cloudbees.groovy.cps.NonCPS

@NonCPS
Boolean call(String repoName, String branchName = BRANCH_NAME) {
  String queryString = DSL.buildQuery {
    QueryBuilder.query('repository', [owner: 'foobar', name: repoName]) {
          QueryBuilder.query('pullRequests', [first: 10, headRefName: branchName, state: [OPEN]] {
            ReturnsBlockBuilder.returns {
              totalCount
            }
          }
    }
  }
  ...
}

And when calling it inside a Jenkins Declarative Pipeline we get the following error message:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: static gql.dsl.QueryBuilder.query() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap, isPR$_call_closure1$_closure2) values: [repository, [owner:amboss-mededu, name:manus-nito], isPR$_call_closure1$_closure2@7eca252f]
Possible solutions: query(java.lang.String, groovy.lang.Closure), query(java.lang.String, java.util.Map, groovy.lang.Closure)

I've tried to figure what the matter here is, but I'm falling short on understanding how Groovy and Jenkins really works in this aspect. Do you have any ideas what could be the matter here?

deiga commented 3 years ago

Okay, this was resolved finally

mariogarcia commented 3 years ago

@deiga could u provide more information about how it was solved ? Did it have to do with GQL ? Maybe it could help others. Thanks anyway

deiga commented 3 years ago

The solution was to not use static references:

@Grab("com.github.grooviter:gql-core:0.4.0")
@GrabExclude('org.codehaus.groovy:groovy-all')
import gql.DSL
import groovy.json.JsonOutput
import com.cloudbees.groovy.cps.NonCPS

@NonCPS
Boolean call(String repoName, String branchName = BRANCH_NAME) {
  String queryString = DSL.buildQuery {
   query('repository', [owner: 'foobar', name: repoName]) {
         query('pullRequests', [first: 10, headRefName: branchName, state: [OPEN]] {
           returns {
              totalCount
            }
          }
    }
  }
  ...
}
mariogarcia commented 3 years ago

:+1: Perfect, thanks for the feedback