Commit cdc6e175 authored by dmorley's avatar dmorley

API v2 using graphql

parent 5f1c1eee
......@@ -9,13 +9,17 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
### Fixed
### Security
## [Unreleased]
## [2.8.2]
### Added
- API v2 using graphql and Siler framework
- graphiql web-ide
### Changed
- Tell robots not to follow links to pods
- Limit stats to 2019 further as old data is inconsistant
- Limit stats to 2019 further as old data is inconsistent
- yarn 2.0
### Deprecated
- yarn 1.0 support
- API v1 api.php
### Removed
### Fixed
- Show stats in proper order yymm
......
#Graphql API Endpoint
Install your favorite Graphql extension on your browser and build away
<html>
<head>
<title>GraphiQL</title>
<link href="/node_modules/graphiql/graphiql.min.css" rel="stylesheet" />
</head>
<body style="margin: 0;">
<div class="graphiql-container" style="height: 2vh;">Use your favorite graphql browser extension, IDE, or graphiql below to get started.</div>
<div id="graphiql" style="height: 98vh;"></div>
<script
src="/node_modules/react/umd/react.production.min.js"
></script>
<script
src="/node_modules/react-dom/umd/react-dom.production.min.js"
></script>
<script
src="/node_modules/graphiql/graphiql.min.js"
></script>
<script>
const graphQLFetcher = graphQLParams =>
fetch('', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(graphQLParams),
})
.then(response => response.json())
.catch(() => response.text());
ReactDOM.render(
React.createElement(GraphiQL, { fetcher: graphQLFetcher }),
document.getElementById('graphiql'),
);
</script>
</body>
</html>
<?php
use Siler\GraphQL;
use Siler\Http\Request;
use Siler\Http\Response;
require_once __DIR__ . '/../boot.php';
Response\cors();
if (Request\method_is('post')) {
$schema = include __DIR__.'/schema.php';
GraphQL\init($schema);
} else {
require 'graphiql.php';
}
<?php
use RedBeanPHP\R;
use function Siler\{array_get_str};
require_once __DIR__ . '/../boot.php';
$queryType = array(
'nodes' => function () {
return R::getAll('
SELECT
id,
domain,
name,
softwarename,
masterversion,
fullversion,
shortversion,
stats_apikey,
score,
ip,
detectedlanguage,
country,
countryname,
city,
state,
lat,
long,
email,
ipv6,
sslvalid,
monthsmonitored,
daysmonitored,
signup,
total_users,
active_users_halfyear,
active_users_monthly,
local_posts,
uptime_alltime,
status,
latency,
service_xmpp,
services,
protocols,
token,
publickey,
tokenexpire,
podmin_statement,
podmin_notify,
podmin_notify_level,
sslexpire,
dnssec,
comment_counts,
weight,
date_updated,
date_laststats,
date_created
FROM pods
');
},
'node' => function ($_, array $args) {
$domain = array_get_str($args, 'domain');
return R::getAll('
SELECT
id,
domain,
name,
softwarename,
masterversion,
fullversion,
shortversion,
stats_apikey,
score,
ip,
detectedlanguage,
country,
countryname,
city,
state,
lat,
long,
email,
ipv6,
sslvalid,
monthsmonitored,
daysmonitored,
signup,
total_users,
active_users_halfyear,
active_users_monthly,
local_posts,
uptime_alltime,
status,
latency,
service_xmpp,
services,
protocols,
token,
publickey,
tokenexpire,
podmin_statement,
podmin_notify,
podmin_notify_level,
sslexpire,
dnssec,
comment_counts,
weight,
date_updated,
date_laststats,
date_created
FROM pods
WHERE domain = ?
', [$domain]);
},
'checks' => function ($_, array $args) {
if ($args) {
$limit = array_get_str($args, 'limit');
} else {
$limit = 5000;
}
return R::getAll('
SELECT id, domain, online, error, latency, total_users, local_posts, comment_counts, shortversion, version, date_checked
FROM checks
ORDER BY date_checked DESC
LIMIT ?
', [$limit]);
},
'clicks' => function ($_, array $args) {
if ($args) {
$limit = array_get_str($args, 'limit');
} else {
$limit = 5000;
}
return R::getAll('
SELECT id, domain, manualclick, autoclick, date_clicked
FROM clicks
ORDER BY date_clicked DESC
LIMIT ?
', [$limit]);
},
'monthlystats' => function () {
return R::getAll('
SELECT id, softwarename, total_users, total_posts, total_comments, total_pods, total_uptime, date_checked
FROM monthlystats
');
},
'masterversions' => function () {
return R::getAll('
SELECT id, software, version, devlastcommit, releasedate, date_checked
FROM masterversions
');
},
);
return [
'Query' => $queryType,
];
type Node {
id: Int!
name: String
domain: String
podmin_statement: String
masterversion: String
shortversion: String
softwarename: String
daysmonitored: Int
monthsmonitored: Int
fullversion: String
score: Int
ip: String
detectedlanguage: String
country: String
countryname: String
city: String
state: String
lat: String
long: String
ipv6: Boolean
sslvalid: String
signup: Boolean
total_users: Int
active_users_halfyear: Int
active_users_monthly: Int
local_posts: Int
uptime_alltime: String
status: Int
latency: Int
service_xmpp: Boolean
services: String
protocols: String
sslexpire: String
dnssec: Boolean
comment_counts: Int
weight: Int
date_updated: String
date_laststats: String
date_created: String
}
type Click {
id: Int!
domain: String
manualclick: Int
autoclick: Int
date_clicked: String
}
type Check {
id: Int!
domain: String
online: Boolean
error: String
latency: Int
total_users: Int
local_posts: Int
comment_counts: Int
shortversion: String
version: String
date_checked: String
}
type MonthlyStat {
id: Int!
softwarename: String
total_users: Int
total_posts: Int
total_comments: Int
total_pods: Int
total_uptime: Int
date_checked: String
}
type MasterVersion {
id: Int!
software: String
version: String
devlastcommit: String
releasedate: String
date_checked: String
}
type Query {
nodes: [Node]
node (domain: String): [Node]
clicks (limit: Int): [Click]
checks (limit: Int): [Check]
monthlystats: [MonthlyStat]
masterversions: [MasterVersion]
}
<?php
use Siler\GraphQL;
$typeDefs = file_get_contents(__DIR__.'/schema.graphql');
$resolvers = include __DIR__.'/resolvers.php';
return GraphQL\schema($typeDefs, $resolvers);
This diff is collapsed.
......@@ -88,7 +88,8 @@ $navs = [
['text' => 'Edit a pod', 'href' => '/podminedit', 'active' => $podminedit],
['text' => 'Open Source Code', 'href' => 'https://git.feneas.org/diasporg/Poduptime', 'active' => false],
['text' => 'Support', 'href' => 'https://dia.so/support', 'active' => false],
['text' => 'Wiki/API', 'href' => 'https://git.feneas.org/diasporg/Poduptime/wikis/home', 'active' => false],
['text' => 'Wiki', 'href' => 'https://git.feneas.org/diasporg/Poduptime/wikis/home', 'active' => false],
['text' => 'API', 'href' => '//api.' . c('domain'), 'active' => false],
['text' => 'More about the Fediverse', 'href' => 'https://fediverse.party', 'active' => false],
['text' => 'Federated Networks Association', 'href' => 'https://feneas.org', 'active' => false],
],
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment