After referring this guide I needed to access the github graphql
by using curl
for a testing purpose. I tried this simple command
curl -i -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: "wso2", name: "product-is") {description}}"}' https://api.github.com/graphql
but it gives me
problems parsing JSON
what I am doing wrong. I spent nearly 2 hours trying to figure it and tried different examples but none of them worked. Can you please be kind enough help me resolve this
In three steps, you write the schema that describes your GraphQL endpoint. Define an interface and queries for a type that the front-end application will query. This could be a customer type, an order type, a ticket, whatever. Connect backends by creating one or more concrete types in support of the interface type.
GitHub chose GraphQL because it offers significantly more flexibility for our integrators. The ability to define precisely the data you want—and only the data you want—is a powerful advantage over traditional REST API endpoints.
Using this interface, simply write queries using the GraphQL syntax and specify any variables used in the query in JSON format. You can then run the test step on its own, or add an assertion to verify a particular response using properties like contains, equals, counts and even regular expression matches.
You just need to escape the double quotes that are inside the JSON as the query
$ curl -i -H 'Content-Type: application/json' -H "Authorization: bearer myGithubAccessToken" -X POST -d '{"query": "query {repository(owner: \"wso2\", name: \"product-is\") {description}}"}' https://api.github.com/graphql
If you want your queries to stay nice and multiline, you may do like this:
script='query { repositoryOwner(login:\"danbst\") { repositories(first: 100) { edges { node { nameWithOwner pullRequests(last: 100, states: OPEN) { edges { node { title url author { login } labels(first: 20) { edges { node { name } } } } } } } } } } }' script="$(echo $script)" # the query should be a one-liner, without newlines curl -i -H 'Content-Type: application/json' \ -H "Authorization: bearer ........." \ -X POST -d "{ \"query\": \"$script\"}" https://api.github.com/graphql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With