Created
March 27, 2023 20:34
-
-
Save sunny/c2ad09718a515304d318d8db095bee34 to your computer and use it in GitHub Desktop.
Example Ruby GraphQL call for Cults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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