Compare commits

..

6 Commits

Author SHA1 Message Date
Gogs 1fa3fdddd0 Page Title 2021-06-02 17:38:24 +02:00
Gogs cbdc38e98e Pre Commit the 2nd 2021-06-02 16:51:15 +02:00
Gogs 6137098872 Pre Commit Hook 2021-06-02 16:44:34 +02:00
Gogs 1e9b99c7a6 Backend Menu 2021-06-02 15:50:12 +02:00
Gogs a65593b4f9 GraphiQL in Backend 2021-06-02 15:46:20 +02:00
Gogs e7d7d18f77 Settings 2021-06-02 01:52:05 +02:00
26 changed files with 61943 additions and 588 deletions
+1
View File
@@ -0,0 +1 @@
node_modules
+1
View File
@@ -0,0 +1 @@
vendor
+11
View File
@@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"semi": true,
"trailingComma": "es5",
"arrowParens": "always",
"phpVersion": "7.1"
}
+17
View File
@@ -0,0 +1,17 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[php]":
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"search.exclude": {
"**/vendor": true,
"**/node_modules": true,
"yarn.lock": true,
"package.json": true,
"tsconfig.json": true,
".*": true,
},
}
+18 -13
View File
@@ -15,6 +15,18 @@ class Plugin extends PluginBase
public function registerSettings()
{
return [
'settings' => [
'label' => 'germanairlinesva.graphql::lang.settings.label',
'description' => 'germanairlinesva.graphql::lang.settings.description',
'category' => 'system::lang.system.categories.cms',
'icon' => 'icon-compress',
'class' => 'GermanAirlinesVa\Graphql\Models\Settings',
'order' => 1000,
'keywords' => 'graphql',
'permissions' => ['germanairlinesva.graphql.schemas'],
],
];
}
public function boot()
@@ -36,28 +48,22 @@ class Plugin extends PluginBase
$packages = Config::get($pluginNamespace . '::packages');
// Boot each package
foreach ($packages as $name => $options)
{
foreach ($packages as $name => $options) {
// Setup the configuration for the package, pulling from this plugin's config
if (!empty($options['config']) && !empty($options['config_namespace']))
{
if (!empty($options['config']) && !empty($options['config_namespace'])) {
Config::set($options['config_namespace'], $options['config']);
}
// Register any Service Providers for the package
if (!empty($options['providers']))
{
foreach ($options['providers'] as $provider)
{
if (!empty($options['providers'])) {
foreach ($options['providers'] as $provider) {
App::register($provider);
}
}
// Register any Aliases for the package
if (!empty($options['aliases']))
{
foreach ($options['aliases'] as $alias => $path)
{
if (!empty($options['aliases'])) {
foreach ($options['aliases'] as $alias => $path) {
$aliasLoader->alias($alias, $path);
}
}
@@ -66,4 +72,3 @@ class Plugin extends PluginBase
return $packages;
}
}
+61205
View File
File diff suppressed because one or more lines are too long
-2
View File
@@ -6,10 +6,8 @@ use Illuminate\Http\Request;
use Nuwave\Lighthouse\Support\Contracts\CreatesContext as LighthouseCreatesContext;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;
class CreatesContext implements LighthouseCreatesContext
{
/**
* Generate GraphQL context.
*
+4 -12
View File
@@ -5,10 +5,8 @@ namespace GermanAirlinesVa\Graphql\Classes;
use Lang;
use Cms\Classes\Page;
class Graph extends Page
{
/**
* @var string The container name associated with the model.
*/
@@ -17,22 +15,17 @@ class Graph extends Page
/**
* @var array The attributes that are mass assignable.
*/
protected $fillable = [
'title',
'description',
'markup',
'settings',
'code'
];
protected $fillable = ['title', 'description', 'markup', 'settings', 'code'];
/**
* @var array The rules to be applied to the data.
*/
public $rules = [
'title' => 'required'
'title' => 'required',
];
public function getCodeClassParent() : string {
public function getCodeClassParent(): string
{
return GraphCode::class;
}
@@ -42,5 +35,4 @@ class Graph extends Page
$component->onRun();
}
}
}
-2
View File
@@ -8,7 +8,6 @@ use October\Rain\Extension\Extendable;
*/
class GraphCode extends CodeBase
{
public $graph;
/**
@@ -51,5 +50,4 @@ class GraphCode extends CodeBase
{
return isset($this->graph->{$name});
}
}
+11 -13
View File
@@ -8,10 +8,8 @@ use Cms\Classes\Controller;
use Cms\Classes\CmsException;
use Cms\Classes\ComponentManager;
class GraphController// extends Controller
class GraphController // extends Controller
{
protected $graph;
/**
@@ -19,7 +17,6 @@ class GraphController// extends Controller
*/
protected static $instance;
/**
* Creates the controller.
*/
@@ -41,22 +38,25 @@ class GraphController// extends Controller
return self::$instance;
}
public function component($alias) {
public function component($alias)
{
if (isset($this->graph->components[$alias])) {
return $this->graph->components[$alias];
}
foreach ($this->graph->settings['components'] as $component => $properties) {
list($name, $component_alias) = strpos($component, ' ')
? explode(' ', $component)
: [$component, $component];
[$name, $component_alias] = strpos($component, ' ') ? explode(' ', $component) : [$component, $component];
if ($component_alias == $alias) {
// make component
$manager = ComponentManager::instance();
if (!$componentObj = $manager->makeComponent($name, null, $properties)) {
throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
if (!($componentObj = $manager->makeComponent($name, null, $properties))) {
throw new CmsException(
Lang::get('cms::lang.component.not_found', [
'name' => $name,
])
);
}
$this->setComponentPropertiesFromParams($componentObj, $this->router->getParameters());
@@ -93,8 +93,7 @@ class GraphController// extends Controller
if (substr($paramName, 0, 1) == ':') {
$routeParamName = substr($paramName, 1);
$newPropertyValue = $routerParameters[$routeParamName] ?? null;
}
else {
} else {
$newPropertyValue = $parameters[$paramName] ?? null;
}
@@ -114,5 +113,4 @@ class GraphController// extends Controller
{
return $this->router->getParameter($name, $default);
}
}
-3
View File
@@ -7,7 +7,6 @@ use Cms\Classes\Router;
class GraphRouter //extends Router
{
/**
* @var array A list of parameters names and values extracted from the URL pattern and URL string.
*/
@@ -27,7 +26,6 @@ class GraphRouter //extends Router
return $this->parameters;
}
/**
* Returns a routing parameter.
* @return array
@@ -40,5 +38,4 @@ class GraphRouter //extends Router
return $default;
}
}
+2 -4
View File
@@ -9,14 +9,12 @@ use GermanAirlinesVa\Graphql\Classes\CreatesContext as GraphqlCreatesContext;
use October\Rain\Support\ServiceProvider;
class GraphqlServiceProvider extends ServiceProvider {
class GraphqlServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(ProvidesResolver::class, GraphqlProvidesResolver::class);
$this->app->singleton(CreatesContext::class, GraphqlCreatesContext::class);
$this->app->singleton(SchemaSourceProvider::class, GraphqlSchemaSourceProvider::class);
}
}
+2 -4
View File
@@ -6,9 +6,8 @@ use GraphQL\Type\Definition\ResolveInfo;
use Cms\Classes\CodeParser;
use Nuwave\Lighthouse\Schema\ResolverProvider as LighthouseResolverProvider;
class ResolverProvider extends LighthouseResolverProvider {
class ResolverProvider extends LighthouseResolverProvider
{
/**
* Provide a field resolver in case no resolver directive is defined for a field.
*
@@ -35,5 +34,4 @@ class ResolverProvider extends LighthouseResolverProvider {
return parent::provideResolver($fieldValue)($root, $args, $context, $resolveInfo);
};
}
}
-2
View File
@@ -6,7 +6,6 @@ use Cms\Classes\Theme;
class Schema extends Theme
{
/**
* Returns the absolute theme path.
* @param string $dirName Optional theme directory. Defaults to $this->getDirName()
@@ -40,5 +39,4 @@ class Schema extends Theme
{
return 'graphql';
}
}
-4
View File
@@ -7,10 +7,8 @@ use Nuwave\Lighthouse\Schema\Context;
use Illuminate\Http\Request;
use Nuwave\Lighthouse\Schema\Source\SchemaSourceProvider;
class SchemaContext extends Context
{
public $source;
/**
@@ -25,6 +23,4 @@ class SchemaContext extends Context
$this->source = App::make(SchemaSourceProvider::class);
}
}
+24 -28
View File
@@ -11,7 +11,6 @@ use Cms\Classes\ComponentPartial;
class SchemaSourceProvider implements LighthouseSchemaSourceProvider
{
protected $fieldGraphMapCacheKey = 'graphql-schema-field-graph-map';
/**
@@ -36,7 +35,6 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
*/
protected $fieldGraphMap;
/**
* SchemaSource constructor.
*
@@ -72,11 +70,11 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
// root types
$schema = '
type Query {
graphql: Boolean
dummy: Boolean
}
type Mutation {
graphql: Boolean
dummy: Boolean
}
';
// schema
@@ -84,7 +82,8 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
return $schema;
}
public function findGraph($fieldName, $findOrFail=false) {
public function findGraph($fieldName, $findOrFail = false)
{
if (!isset($this->getFieldGraphMap()[$fieldName])) {
if ($findOrFail) {
throw new Error("Could not find graph of field '{$fieldName}'.");
@@ -103,8 +102,9 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
return Graph::loadCached($this->template, $name);
}
public function getFieldGraphMap() {
if (! is_null($this->fieldGraphMap)) {
public function getFieldGraphMap()
{
if (!is_null($this->fieldGraphMap)) {
return $this->fieldGraphMap;
}
@@ -114,11 +114,7 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
if ($cacheable) {
$map = Cache::get($this->fieldGraphMapCacheKey, false);
if (
$map &&
($map = @unserialize(@base64_decode($map))) &&
is_array($map)
) {
if ($map && ($map = @unserialize(@base64_decode($map))) && is_array($map)) {
$this->fieldGraphMap = $map;
return $this->fieldGraphMap;
}
@@ -142,7 +138,7 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
})
->flatMap(function ($node) {
// collect field names
return collect($node->fields)->map(function($field) {
return collect($node->fields)->map(function ($field) {
return $field->name->value;
});
});
@@ -154,17 +150,14 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
// cache mapping
if ($cacheable) {
Cache::put(
$this->fieldGraphMapCacheKey,
base64_encode(serialize($this->fieldGraphMap)),
10
);
Cache::put($this->fieldGraphMapCacheKey, base64_encode(serialize($this->fieldGraphMap)), 10);
}
return $this->fieldGraphMap;
}
public function getGraphMap() {
public function getGraphMap()
{
if (!is_null($this->graphMap)) {
return $this->graphMap;
}
@@ -176,13 +169,13 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
/* @var $graph \GermanAirlinesVa\Graphql\Classes\Graph */
$markup = $graph->markup;
$schema = preg_replace_callback($component_re, function(array $matches) use ($graph, $component_str) {
$schema = preg_replace_callback(
$component_re,
function (array $matches) use ($graph, $component_str) {
$matched_alias = $matches[1];
foreach ($graph->settings['components'] as $component => $properties) {
// find component by alias
list($name, $alias) = strpos($component, ' ')
? explode(' ', $component)
: [$component, $component];
[$name, $alias] = strpos($component, ' ') ? explode(' ', $component) : [$component, $component];
if ($alias == $matched_alias) {
// resolve component schema
return $component_str($name, $alias);
@@ -190,18 +183,21 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
}
// if not found, remove
return '';
}, $markup);
},
$markup
);
$this->graphMap[$graph->getFileName()] = [
'graph' => $graph,
'schema' => $schema
'schema' => $schema,
];
}
return $this->graphMap;
}
public function getComponentSchemaString($componentName, $alias) {
public function getComponentSchemaString($componentName, $alias)
{
$manager = ComponentManager::instance();
$componentObj = $manager->makeComponent($componentName);
if ($partial = ComponentPartial::load($componentObj, 'schema.graphqls')) {
@@ -214,8 +210,8 @@ class SchemaSourceProvider implements LighthouseSchemaSourceProvider
}
}
public function clearCache() {
public function clearCache()
{
Cache::forget($this->fieldGraphMapCacheKey);
}
}
+11 -16
View File
@@ -1,18 +1,15 @@
<?php
use Cms\Classes\Theme;
use GermanAirlinesVa\Graphql\Models\Settings;
return [
'packages' => [
'nuwave/lighthouse' => [
'config_namespace' => 'lighthouse',
'providers' => [
'Nuwave\Lighthouse\LighthouseServiceProvider'
],
'aliases' => [
],
'providers' => ['Nuwave\Lighthouse\LighthouseServiceProvider'],
'aliases' => [],
'config' => [
/*
|--------------------------------------------------------------------------
| Route Configuration
@@ -41,7 +38,7 @@ return [
* so you have to take extra care to return spec-compliant error responses.
* To apply middleware on a field level, use the @middleware directive.
*/
'middleware' => [\Nuwave\Lighthouse\Support\Http\Middleware\AcceptJson::class]
'middleware' => [\Nuwave\Lighthouse\Support\Http\Middleware\AcceptJson::class],
],
/*
@@ -71,7 +68,7 @@ return [
*/
'cache' => [
'enable' => false,
'enable' => Settings::get('enable_cache', false),
'key' => env('GRAPHQL_CACHE_KEY', 'graphql-schema'),
'ttl' => env('GRAPHQL_CACHE_TTL', null),
],
@@ -163,9 +160,7 @@ return [
|
*/
'error_handlers' => [
\Nuwave\Lighthouse\Execution\ExtensionErrorHandler::class,
],
'error_handlers' => [\Nuwave\Lighthouse\Execution\ExtensionErrorHandler::class],
/*
|--------------------------------------------------------------------------
@@ -189,7 +184,7 @@ return [
|
*/
'batched_queries' => true,
'batched_queries' => Settings::get('batched_queries', true),
/*
|--------------------------------------------------------------------------
@@ -240,12 +235,12 @@ return [
],
'pusher' => [
'driver' => 'pusher',
'routes' => \Nuwave\Lighthouse\Subscriptions\SubscriptionRouter::class.'@pusher',
'routes' => \Nuwave\Lighthouse\Subscriptions\SubscriptionRouter::class . '@pusher',
'connection' => 'pusher',
],
],
],
]
]
]
],
],
],
];
+20
View File
@@ -0,0 +1,20 @@
<?php namespace GermanAirlinesVa\Graphql\Controllers;
use Backend\Classes\Controller;
use BackendMenu;
class Playground extends Controller
{
public function __construct()
{
parent::__construct();
BackendMenu::setContext('GermanAirlinesVa.Graphql', 'menu', 'playground');
}
public function index()
{
$this->pageTitle = 'germanairlinesva.graphql::lang.menu.playground';
$this->pageTitleTemplate = '%s ' . trans($this->pageTitle);
}
}
+2
View File
@@ -0,0 +1,2 @@
<div id="mount"></div>
<script type="text/javascript" src="/plugins/germanairlinesva/graphql/assets/js/graphiql.js"></script>
+2 -2
View File
@@ -1,9 +1,9 @@
<?php
if(!function_exists("join_paths")) {
if (!function_exists('join_paths')) {
function join_paths()
{
$paths = array();
$paths = [];
foreach (func_get_args() as $arg) {
if ($arg !== '') {
+25 -1
View File
@@ -4,6 +4,30 @@
'description' => '',
],
'menu' => [
'main' => 'GraphQL',
'playground' => 'GraphiQL',
],
'permission' => [
'tab' => [
'schemas' => 'Schemas',
],
'label' => [
'schemas' => 'Manage schemas',
],
],
'settings' => [
'label' => 'German Airlines VA - GraphQL',
'description' => 'Configure GrapQL',
'general' => 'General',
'engine' => 'Engine',
'enable_cache' => [
'label' => 'Enable Schema Cache',
'comment' =>
'A large part of the Schema generation is parsing the various graph definition into an AST. These operations are pretty expensive so it is recommended to enable caching in production mode.',
],
'batched_queries' => [
'label' => 'Batched Queries',
'comment' =>
'GraphQL query batching means sending multiple queries to the server in one request. You may set this flag to process/deny batched queries.',
],
],
];
+13
View File
@@ -0,0 +1,13 @@
<?php namespace GermanAirlinesVa\Graphql\Models;
use Cms\Classes\Theme;
use Model;
class Settings extends Model
{
public $implement = ['System.Behaviors.SettingsModel'];
public $settingsCode = 'germanairlinesva_graphql_settings';
public $settingsFields = 'fields.yaml';
}
+16
View File
@@ -0,0 +1,16 @@
tabs:
fields:
enable_cache:
label: 'germanairlinesva.graphql::lang.settings.enable_cache.label'
span: left
default: false
type: checkbox
comment: 'germanairlinesva.graphql::lang.settings.enable_cache.comment'
tab: 'germanairlinesva.graphql::lang.settings.engine'
batched_queries:
label: 'germanairlinesva.graphql::lang.settings.batched_queries.label'
span: right
default: true
type: checkbox
comment: 'germanairlinesva.graphql::lang.settings.batched_queries.comment'
tab: 'germanairlinesva.graphql::lang.settings.engine'
+15
View File
@@ -0,0 +1,15 @@
{
"name": "graphql",
"version": "1.0.0",
"main": "Plugin.php",
"repository": "https://git.hofmannnet.myhome-server.de/GermanAirlines/GermanAirlinesVA-GraphQL.git",
"author": "German Airlines VA",
"license": "MIT",
"devDependencies": {
"@prettier/plugin-php": "^0.16.3",
"prettier": "^2.3.0"
},
"scripts": {
"format": "prettier --write './**/*.{php,html}'"
}
}
+9
View File
@@ -4,3 +4,12 @@ plugin:
author: 'German Airlines VA'
icon: oc-icon-database
homepage: ''
permissions:
schemas:
tab: 'germanairlinesva.graphql::lang.permission.tab.schemas'
label: 'germanairlinesva.graphql::lang.permission.label.schemas'
navigation:
menu:
label: 'germanairlinesva.graphql::lang.menu.playground'
url: germanairlinesva/graphql/playground
icon: icon-database
+52
View File
@@ -0,0 +1,52 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@prettier/plugin-php@^0.16.3":
version "0.16.3"
resolved "https://registry.yarnpkg.com/@prettier/plugin-php/-/plugin-php-0.16.3.tgz#74867210079ba3c0c3ae843029d76e25ff0aadf3"
integrity sha512-DNidzeGpP+/wmcCAZNSHxgoAnhEosYG+no4jJRqln19e1o3Okpuir/2JMxb07VCwdG50IWjtNgVwNPVl4uj0Hg==
dependencies:
linguist-languages "^7.5.1"
mem "^8.0.0"
php-parser "3.0.2"
linguist-languages@^7.5.1:
version "7.15.0"
resolved "https://registry.yarnpkg.com/linguist-languages/-/linguist-languages-7.15.0.tgz#a93bed6b93015d8133622cb05da6296890862bfa"
integrity sha512-qkSSNDjDDycZ2Wcw+GziNBB3nNo3ddYUInM/PL8Amgwbd9RQ/BKGj2/1d6mdxKgBFnUqZuaDbkIwkE4KUwwmtQ==
map-age-cleaner@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a"
integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==
dependencies:
p-defer "^1.0.0"
mem@^8.0.0:
version "8.1.1"
resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.1.tgz#cf118b357c65ab7b7e0817bdf00c8062297c0122"
integrity sha512-qFCFUDs7U3b8mBDPyz5EToEKoAkgCzqquIgi9nkkR9bixxOVOre+09lbuH7+9Kn2NFpm56M3GUWVbU2hQgdACA==
dependencies:
map-age-cleaner "^0.1.3"
mimic-fn "^3.1.0"
mimic-fn@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-3.1.0.tgz#65755145bbf3e36954b949c16450427451d5ca74"
integrity sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ==
p-defer@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c"
integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=
php-parser@3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.0.2.tgz#a86dbbc110e57378cba71ab4cd9b0d18f3872ac3"
integrity sha512-a7y1+odEGsceLDLpu7oNyspZ0pK8FMWJOoim4/yd82AtnEZNLdCLZ67arnOQZ9K0lHJiSp4/7lVUpGELVxE14w==
prettier@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.0.tgz#b6a5bf1284026ae640f17f7ff5658a7567fc0d18"
integrity sha512-kXtO4s0Lz/DW/IJ9QdWhAf7/NmPWQXkFr/r/WkR3vyI+0v8amTDxiaQSLzs8NBlytfLWX/7uQUMIW677yLKl4w==