Unofficial Discourse GraphQL API.
Follow Install a Plugin
how-to from the official Discourse Meta, using git clone https://github.com/tgxworld/discourse-graphql.git
as the plugin command.
require "graphql/client"
require "graphql/client/http"
module DiscourseAPI
HTTP = GraphQL::Client::HTTP.new("http://localhost:3000/discourse-graphql/graphql") do
def headers(context)
{ "Api-Key": 'ef984ff3d0d242998b7df8eaa975229e4ce07c19500b55baa181fc7abd2fd04b', "Api-Username": 'system' }
end
end
Schema = GraphQL::Client.load_schema(HTTP)
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end
Query = DiscourseAPI::Client.parse(<<~QUERY)
query {
latestTopics {
fancyTitle
}
}
QUERY
DiscourseAPI::Client.query(Query).latest_topics.each do |topic|
puts topic.fancy_title
end
If you have issues or suggestions for the plugin, please open an issue.