Skip to content

Commit 6112803

Browse files
committed
Resolving warehouse items
1 parent 3b830f0 commit 6112803

17 files changed

+177
-129
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = space
9+
max_line_length = off
10+
indent_size = 4
11+
tab_width = 4

bin/server.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
namespace AdsWarehouse;
44

55
use AdsWarehouse\Http\Handler;
6-
use function Siler\GraphQL\schema;
6+
use Monolog\Handler\ErrorLogHandler;
7+
use PDO;
8+
use Siler\Monolog as Log;
79
use function Siler\Swoole\http;
810

911
$basedir = dirname(__DIR__, 1);
1012
require_once "$basedir/vendor/autoload.php";
1113

12-
$type_defs = graphql_files("$basedir/src/");
13-
$resolvers = require_once "$basedir/src/resolvers.php";
14-
$schema = schema($type_defs, $resolvers);
14+
Log\handler(new ErrorLogHandler());
15+
16+
$pdo = new PDO(getenv('POSTGRES_DSN'));
17+
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::ERRMODE_EXCEPTION);
1518

1619
$context = new Context();
17-
$context->schema = $schema;
20+
$context->schema = require_once "$basedir/src/schema.php";
21+
$context->warehouse = new Warehouse\Pdo($pdo);
1822

19-
http(new Handler($context), 8000)->start();
23+
http(new Handler($context), 8000)->start();

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "Data warehouse for multi-data-source ads campaings.",
44
"type": "project",
55
"require": {
6+
"ext-pdo": "*",
67
"leocavalcante/siler": "dev-master",
78
"monolog/monolog": "^2.0",
89
"firebase/php-jwt": "^5.0",
@@ -23,12 +24,8 @@
2324
"autoload": {
2425
"psr-4": {
2526
"AdsWarehouse\\": [
26-
"src/",
27-
"lib/"
27+
"src/"
2828
]
29-
},
30-
"files": [
31-
"lib/graphql_files.php"
32-
]
29+
}
3330
}
3431
}

composer.lock

Lines changed: 80 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ services:
2424
- "${DOCKER_HTTP_PORT}:8000"
2525
volumes:
2626
- ./:/app
27+
env_file: ./.env
2728
environment:
28-
ENTRY_POINT_FILE: /app/bin/server.php
29+
ENTRY_POINT_FILE: /app/bin/server.php

lib/graphql_files.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Ad/Ad.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
type Ad {
22
id: ID!
33
name: String!
4-
}
4+
}

src/Ad/Ad.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class Ad
88
public $id;
99
/** @var string */
1010
public $name;
11-
}
11+
}

src/Ad/Resolver/Ads.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AdsWarehouse\Ad\Resolver;
4+
5+
use AdsWarehouse\Context;
6+
use AdsWarehouse\Resolver;
7+
8+
class Ads implements Resolver
9+
{
10+
public function __invoke($root, array $args, Context $context)
11+
{
12+
return $context->warehouse->items();
13+
}
14+
}

src/Http/Handler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public function __invoke(Request $request, Response $response)
2626
{
2727
try {
2828
$input = decode(raw());
29-
$response = execute($this->context->schema, $input, $this->context->rootValue, $this->context);
29+
$result = execute($this->context->schema, $input, $this->context->rootValue, $this->context);
3030
} catch (Throwable $exception) {
3131
Log\error('Internal error', ['exception' => $exception]);
32-
$response = FormattedError::createFromException($exception);
32+
$result = FormattedError::createFromException($exception);
3333
} finally {
3434
cors();
35-
json($response);
35+
json($result);
3636
}
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)