Compare commits

...

4 Commits

Author SHA1 Message Date
Your Name 2106f15d7f Naming adjusted for consistency 2021-07-29 01:30:05 +02:00
Your Name 63b8173399 Small Adjustments 2021-07-29 01:26:23 +02:00
Your Name df0f8f36f7 Auth 2021-07-28 22:02:10 +02:00
Your Name a6d844bd01 Mutations 2021-07-28 19:10:35 +02:00
9 changed files with 179 additions and 6 deletions
+25
View File
@@ -0,0 +1,25 @@
<?php namespace GermanAirlinesVa\Graphql;
use Closure;
class Authentication
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->input('gql_session') === 'SUPER_SECRET_TOKEN') {
return "false";
}
else {
return "true";
}
return $next($request);
}
}
+9
View File
@@ -4,6 +4,7 @@ use System\Classes\PluginBase;
use App;
use Config;
use Illuminate\Database\DatabaseManager;
use Illuminate\Foundation\AliasLoader;
use GermanAirlinesVa\Graphql\Classes\GraphqlServiceProvider;
use Nuwave\Lighthouse\Subscriptions\SubscriptionServiceProvider;
@@ -33,9 +34,17 @@ class Plugin extends PluginBase
public function boot()
{
App::make('October\Rain\Support\ClassLoader')->addDirectories('graphql');
$this->bootPackages();
App::register(GraphqlServiceProvider::class);
App::register(SubscriptionServiceProvider::class);
$this->app->singleton(DatabaseManager::class, function ($app) {
return $app->make('db');
});
\Illuminate\Support\Facades\Broadcast::routes(['prefix' => '', 'middleware' => 'GermanAirlinesVA\\Graphql\\Classes\\Authentication']);
require("channels/channels.php");
}
public function bootPackages()
+1 -1
View File
@@ -32920,7 +32920,7 @@ var _validUrl = __webpack_require__(429);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var options = { method: 'post', headers: { 'Content-Type': 'application/json' } };
var endpoint = 'http://192.168.64.3/graphql/'; // Initial
var endpoint = 'http://localhost/graphql/'; // Initial
var defaultQuery = '\n# Welcome to GraphiQL\n#\n# GraphiQL is an in-browser tool for writing, validating, and\n# testing GraphQL queries.\n#\n# Type queries into this side of the screen, and you will see intelligent\n# typeaheads aware of the current GraphQL type schema and live syntax and\n# validation errors highlighted within the text.\n#\n# GraphQL queries typically start with a "{" character. Lines that starts\n# with a # are ignored.\n#\n# An example GraphQL query might look like:\n#\n# {\n# field(arg: "value") {\n# subField\n# }\n# }\n#\n# Keyboard shortcuts:\n#\n# Run Query: Ctrl-Enter (or press the play button above)\n#\n# Auto Complete: Ctrl-Space (or just start typing)\n#\n# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n# Default endpoint is an instance of https://www.graph.cool/\n# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\n\nquery {\n countries {\n name\n }\n}\n';
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
<?php
use Illuminate\Support\Facades\Broadcast;
/*
|--------------------------------------------------------------------------
| Broadcast Channels
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/
Broadcast::channel('lighthouse-*', function ($user) {
return true;
});
+26
View File
@@ -0,0 +1,26 @@
<?php namespace GermanAirlinesVa\Graphql\Classes;
use Closure;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class Authentication
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->header('Gql-Session') === 'SUPER_SECRET_KEY_HEADER') {
return "";
}
else {
throw new AccessDeniedHttpException;
}
return $next($request);
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php namespace GermanAirlinesVa\Graphql\Classes;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use GraphQL\Type\Definition\ResolveInfo;
use Nuwave\Lighthouse\Subscriptions\Subscriber;
use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
class Dummy extends GraphQLSubscription
{
/**
* Check if subscriber is allowed to listen to the subscription.
*
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function authorize(Subscriber $subscriber, Request $request): bool
{
return true;
}
/**
* Filter which subscribers should receive the subscription.
*
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
* @param mixed $root
* @return bool
*/
public function filter(Subscriber $subscriber, $root): bool
{
return true;
}
/**
* Encode topic name.
*
* @param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
* @param string $fieldName
* @return string
*/
public function encodeTopic(Subscriber $subscriber, string $fieldName): string
{
// Create a unique topic name based on the `author` argument
return Str::snake($fieldName);
}
/**
* Decode topic name.
*
* @param string $fieldName
* @param \App\Post $root
* @return string
*/
public function decodeTopic(string $fieldName, $root): string
{
return Str::snake($fieldName);
}
/**
* Resolve the subscription.
*
* @param \App\Post $root
* @param array<string, mixed> $args
* @param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context
* @param \GraphQL\Type\Definition\ResolveInfo $resolveInfo
* @return mixed
*/
public function resolve($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): array
{
return array($root);
}
}
+6 -2
View File
@@ -68,7 +68,7 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
public function getSchemaString(): string
{
// root types
$schema = '
$schema = "
type Query {
dummy: Boolean
}
@@ -76,7 +76,11 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
type Mutation {
dummy: Boolean
}
';
type Subscription {
dummy: Boolean @subscription(class: \"GermanAirlinesVa\\\\Graphql\\\\Classes\\\\Dummy\")
}
";
// schema
$schema .= collect($this->getGraphMap())->implode('schema', '');
return $schema;
+20 -3
View File
@@ -7,9 +7,26 @@ extend type Query {
aircraftType: [AircraftType] @all(model: "GermanAirlinesVa\\Fleet\\Models\\AircraftType")
}
type Subscription {
aircraft: [Aircraft] @subscription(class: "GermanAirlinesVa\\Fleet\\Classes\\Aircraft")
extend type Subscription {
aircraftAdded: Aircraft @subscription(class: "GermanAirlinesVa\\Fleet\\Classes\\AircraftAdded")
}
type Aircraft { name: String! registration: String! }
extend type Mutation {
addAircraft(
aircraft_type_id: ID!,
home_airport_id: ID!,
name: String!,
registration: String!
): Aircraft
@create(model: "GermanAirlinesVa\\Fleet\\Models\\Aircraft")
@broadcast(subscription: "aircraftAdded")
}
type Aircraft {
id: ID!
aircraft_type_id: ID!
home_airport_id: ID!
name: String!
registration: String!
}
type AircraftType { type: String! aircrafts: [Aircraft] @hasMany }