Skip to content

Instantly share code, notes, and snippets.

@sunny
Created March 27, 2023 20:34
Show Gist options
  • Save sunny/c2ad09718a515304d318d8db095bee34 to your computer and use it in GitHub Desktop.
Save sunny/c2ad09718a515304d318d8db095bee34 to your computer and use it in GitHub Desktop.
Example Ruby GraphQL call for Cults
# Example GraphQL call using https://github.com/github/graphql-client
require 'graphql/client'
require 'graphql/client/http'
require 'base64'
query_string = <<~QUERY
{
creationsBatch(limit: 3) {
results {
name(locale: EN)
url
creator {
nick
}
}
}
}
QUERY
user = 'USER'
password = 'PASSWORD'
http = GraphQL::Client::HTTP.new("https://cults3d.com/graphql") do
def headers(context)
token = Base64.strict_encode64("#{user}:#{password}")
{
"Authorization" => "Basic #{token}",
"User-Agent" => "GraphQL API client",
}
end
end
schema = GraphQL::Client.load_schema(http)
client = GraphQL::Client.new(schema: schema, execute: http)
query = client.parse(query_string)
result = client.query(query)
puts result.data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment