Skip to content

Commit 009450b

Browse files
committed
Exposing some data to GraphQL API. WARNING its insecure yet
1 parent e0642f6 commit 009450b

File tree

7 files changed

+35
-1
lines changed

7 files changed

+35
-1
lines changed

.graphqlconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Ads Warehouse GraphQL Schema",
3+
"schemaPath": "./src/",
4+
"extensions": {
5+
"endpoints": {
6+
"Default GraphQL Endpoint": {
7+
"url": "http://localhost:8034/graphql",
8+
"headers": {
9+
"user-agent": "JS GraphQL"
10+
},
11+
"introspect": false
12+
}
13+
}
14+
}
15+
}

bin/server.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
$context = new Context();
2020
$context->schema = require_once "$basedir/src/schema.php";
2121
$context->warehouse = new Warehouse\Pdo($pdo);
22+
$context->debug = getenv('APP_DEBUG') === 'true';
2223

2324
http(new Handler($context), 8000)->start();

src/Ad/Ad.graphql

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
type Ad {
22
id: ID!
33
name: String!
4+
cost: Float!
5+
impressions: Int!
6+
clicks: Int!
7+
cpm: Float!
8+
cpc: Float!
9+
ctr: Float!
10+
source: String!
11+
date: String!
12+
timestamp: String!
413
}

src/Ad/Resolver/Ads.php

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ public function __invoke($root, array $args, Context $context)
1212
return $context->warehouse->items();
1313
}
1414
}
15+

src/Context.php

+2
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ class Context
1616
public $warehouse;
1717
/** @var ETL[] */
1818
public $etl;
19+
/** @var bool */
20+
public $debug;
1921
}

src/Http/Handler.php

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace AdsWarehouse\Http;
44

55
use AdsWarehouse\Context;
6+
use GraphQL\Error\Debug;
67
use GraphQL\Error\FormattedError;
78
use Siler\Monolog as Log;
89
use Swoole\Http\Request;
910
use Swoole\Http\Response;
1011
use Throwable;
1112
use function Siler\Encoder\Json\decode;
13+
use function Siler\GraphQL\debug;
1214
use function Siler\GraphQL\execute;
1315
use function Siler\Swoole\{cors, json, raw};
1416

@@ -20,6 +22,8 @@ class Handler
2022
public function __construct(Context $context)
2123
{
2224
$this->context = $context;
25+
26+
debug($context->debug ? Debug::INCLUDE_DEBUG_MESSAGE : 0);
2327
}
2428

2529
public function __invoke(Request $request, Response $response)

src/resolvers.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
namespace AdsWarehouse;
44

55
return [
6-
'ads' => new Ad\Resolver\Ads()
6+
'Query' => [
7+
'ads' => new Ad\Resolver\Ads()
8+
],
79
];

0 commit comments

Comments
 (0)