Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2106f15d7f | |||
| 63b8173399 | |||
| df0f8f36f7 | |||
| a6d844bd01 |
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ use System\Classes\PluginBase;
|
|||||||
|
|
||||||
use App;
|
use App;
|
||||||
use Config;
|
use Config;
|
||||||
|
use Illuminate\Database\DatabaseManager;
|
||||||
use Illuminate\Foundation\AliasLoader;
|
use Illuminate\Foundation\AliasLoader;
|
||||||
use GermanAirlinesVa\Graphql\Classes\GraphqlServiceProvider;
|
use GermanAirlinesVa\Graphql\Classes\GraphqlServiceProvider;
|
||||||
use Nuwave\Lighthouse\Subscriptions\SubscriptionServiceProvider;
|
use Nuwave\Lighthouse\Subscriptions\SubscriptionServiceProvider;
|
||||||
@@ -33,9 +34,17 @@ class Plugin extends PluginBase
|
|||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
App::make('October\Rain\Support\ClassLoader')->addDirectories('graphql');
|
App::make('October\Rain\Support\ClassLoader')->addDirectories('graphql');
|
||||||
|
|
||||||
$this->bootPackages();
|
$this->bootPackages();
|
||||||
|
|
||||||
App::register(GraphqlServiceProvider::class);
|
App::register(GraphqlServiceProvider::class);
|
||||||
App::register(SubscriptionServiceProvider::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()
|
public function bootPackages()
|
||||||
|
|||||||
@@ -32920,7 +32920,7 @@ var _validUrl = __webpack_require__(429);
|
|||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||||
|
|
||||||
var options = { method: 'post', headers: { 'Content-Type': 'application/json' } };
|
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';
|
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.
@@ -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;
|
||||||
|
});
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,7 +68,7 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
|
|||||||
public function getSchemaString(): string
|
public function getSchemaString(): string
|
||||||
{
|
{
|
||||||
// root types
|
// root types
|
||||||
$schema = '
|
$schema = "
|
||||||
type Query {
|
type Query {
|
||||||
dummy: Boolean
|
dummy: Boolean
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,11 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
|
|||||||
type Mutation {
|
type Mutation {
|
||||||
dummy: Boolean
|
dummy: Boolean
|
||||||
}
|
}
|
||||||
';
|
|
||||||
|
type Subscription {
|
||||||
|
dummy: Boolean @subscription(class: \"GermanAirlinesVa\\\\Graphql\\\\Classes\\\\Dummy\")
|
||||||
|
}
|
||||||
|
";
|
||||||
// schema
|
// schema
|
||||||
$schema .= collect($this->getGraphMap())->implode('schema', '');
|
$schema .= collect($this->getGraphMap())->implode('schema', '');
|
||||||
return $schema;
|
return $schema;
|
||||||
|
|||||||
+20
-3
@@ -7,9 +7,26 @@ extend type Query {
|
|||||||
aircraftType: [AircraftType] @all(model: "GermanAirlinesVa\\Fleet\\Models\\AircraftType")
|
aircraftType: [AircraftType] @all(model: "GermanAirlinesVa\\Fleet\\Models\\AircraftType")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Subscription {
|
extend type Subscription {
|
||||||
aircraft: [Aircraft] @subscription(class: "GermanAirlinesVa\\Fleet\\Classes\\Aircraft")
|
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 }
|
type AircraftType { type: String! aircrafts: [Aircraft] @hasMany }
|
||||||
|
|||||||
Reference in New Issue
Block a user