From a6d844bd01bb6df35c4622fdee8a45a088fb3851 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 28 Jul 2021 19:10:35 +0200 Subject: [PATCH] Mutations --- Plugin.php | 4 ++ assets/js/graphiql.js | 2 +- classes/Dummy.php | 74 ++++++++++++++++++++++++++++++++ classes/SchemaSourceProvider.php | 8 +++- graphs/fleet.htm | 22 ++++++++-- 5 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 classes/Dummy.php diff --git a/Plugin.php b/Plugin.php index 132a696..ea7e1f8 100644 --- a/Plugin.php +++ b/Plugin.php @@ -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; @@ -36,6 +37,9 @@ class Plugin extends PluginBase $this->bootPackages(); App::register(GraphqlServiceProvider::class); App::register(SubscriptionServiceProvider::class); + $this->app->singleton(DatabaseManager::class, function ($app) { + return $app->make('db'); + }); } public function bootPackages() diff --git a/assets/js/graphiql.js b/assets/js/graphiql.js index 9deb21a..072dfde 100644 --- a/assets/js/graphiql.js +++ b/assets/js/graphiql.js @@ -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'; diff --git a/classes/Dummy.php b/classes/Dummy.php new file mode 100644 index 0000000..b485336 --- /dev/null +++ b/classes/Dummy.php @@ -0,0 +1,74 @@ + $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); + } +} diff --git a/classes/SchemaSourceProvider.php b/classes/SchemaSourceProvider.php index fccbcf2..cdde4ba 100644 --- a/classes/SchemaSourceProvider.php +++ b/classes/SchemaSourceProvider.php @@ -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; diff --git a/graphs/fleet.htm b/graphs/fleet.htm index ba1227d..f9c74f7 100644 --- a/graphs/fleet.htm +++ b/graphs/fleet.htm @@ -7,9 +7,25 @@ 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\\Aircraft") } -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 { + aircraft_type_id: ID! + home_airport_id: ID! + name: String! + registration: String! +} type AircraftType { type: String! aircrafts: [Aircraft] @hasMany }