api-generator icon indicating copy to clipboard operation
api-generator copied to clipboard

Add GraphQL for Laravel support if it is possible to match with OAS

Open arthurkushman opened this issue 7 years ago • 6 comments

https://github.com/Folkloreatelier/laravel-graphql

arthurkushman avatar Aug 10 '18 11:08 arthurkushman

curl -X GET http://laravel.loc/v1/article/1 -d '{"query": "query { echo(message: "Hello World") }" }'

arthurkushman avatar Aug 12 '18 07:08 arthurkushman

I was debating on using Laravel-JSON:API as my JSON:API server implementation until I found this amazing api-generator.

https://github.com/Folkloreatelier/laravel-graphql is no longer maintained

If we are talking about GraphQL and Laravel, I find Lighthouse-PHP as the best GraphQL Server implementation out there for Laravel.

with just a schema.graphql, Lighthouse-PHP will do it magic, just like a oas/openapi.yaml, api-generator will do it magic.

So here is my proposal, let this generator generate the schema.graphql and let Lighthouse do the rest for you.

Parables avatar May 05 '22 06:05 Parables

Hi @Parables I've tried to implement graph-ql format into api-generator, but unfortunately there is no way of making bindings between objects based on graph-ql type model.

PS repo has been archived

arthurkushman avatar May 06 '22 07:05 arthurkushman

@arthurkushman, I have this obsession with generators. I would like to attempt this.

I need two things from you:

  1. your promise to review, and merge my PRs.
  2. Help to get started. I have managed to create the oas/openapi.json file. generated the codes for the Modules/V1 directory but I can't use the generated codes. How do I add the generated routes to my RouteServiceProvider? The README.md is missing that info and I have tried everything possible

Parables avatar May 10 '22 04:05 Parables

Hi @Parables, You can't find the answer in README.md, because it is added automatically by Laravel-Modules. There is no need of caring RouteServiceProvider in any way because it also has been registered for u in Modules/V{K}/Providers/V{K}ServiceProvider

public function register()
{
    $this->app->register(RouteServiceProvider::class);
}

All the other registration etc done by generator with special scripts in composer.json

Make sure that u have been added into composer.json:

{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "Modules/"
    }
  }
}

Try to execute command (it have to be executed before, just in case):

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"

Run once again:

composer dump-autoload

arthurkushman avatar May 10 '22 10:05 arthurkushman

In my case, the Modules/V{K}/Providers/ directory was empty. I had already added "Modules\\": "Modules/" to my composer.json file

While dozing out, after countless efforts to understand why this is happening, I think I did run

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
composer dump-autoload

And that did the magic 🪄

Woke up this morning to see these new files:

Modules/V1/Providers/RouteServiceProvider.php
Modules/V1/Providers/V1ServiceProvider.php

About the GraphQL support, I am determined to find a solution to it so be checking your emails for my PRs very soon. Thanks so much for creating this amazing package. Its the best so far among the rest

Parables avatar May 10 '22 12:05 Parables