I'm trying to figure out how to do a simple GraphQL query without using gems. The following cURL
commands works
curl -X POST "https://gql.example.com/graphql/public"
-H "Authorization: Bearer <ACCESS_TOKEN>"
-H "Content-Type: application/json"
-d '{ "query": "query { user { id defaultEmail } }", "variables": {} }'
and the corresponding javascript code is
fetch('https://gql.example.com/graphql/public', {
method: 'POST',
headers: {
'Authorization': 'Bearer <ACCESS_TOKEN>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: 'query { user { id defaultEmail } }',
variables: {}
})
})
.then(r => r.json())
.then(data => console.log(data));
Is it possible to do this easily in Ruby without using the graphql
gem? I only need to do simple queries like the examples above so I'm hoping it's easy to do them in a single Ruby script.
question from:
https://stackoverflow.com/questions/65660682/how-to-do-a-simple-graphql-query-in-a-native-ruby-script 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…