Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve the Laravel Documentation #843

Merged
merged 2 commits into from
Apr 11, 2022
Merged

Conversation

danielsum
Copy link
Contributor

Summary

Add a part to explain how to easily add a GraphQL support inside Laravel using de native Http Client provider from Laravel and without external Library.

Why is it needed?

The Laravel Library is not up to date and it's not working.

I think it's way better to use the native GraphQL/Rest Api directly from Strapi and Laravel to handle gql file and have the autocomplete.

Suggested solution(s)

Following the official documentation, we can easily make a Macro for integrated Http client from Laravel :

https://laravel.com/docs/9.x/http-client#macros :

In App\Providers\AppServiceProvider (or a service Provider) :

use Illuminate\Support\Facades\Http;
 
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Http::macro('strapi', function () {
        return Http::withHeaders([
            'Authorization' => 'Bearer '.env('STRAPI_TOKEN'), #Token generated in the admin
        ])->baseUrl(env('STRAPI_URL')); # Base url of your strapi app
    });
}

Once your macro has been configured, you may invoke it from anywhere in your application to create a pending request with the specified configuration:

# Access to GraphQL
$response = Http::strapi()->post('graphql', ['query' => $gqlQuery, 'variables' => $variables]); 
#Tip you might include a .gql file here using $gqlQuery = include('gqlQuery.gql')

# Access to Api Rest
$response = Http::strapi()->get('api/pages');

Related issue(s)/PR(s)

No response

@strapi-cla
Copy link

strapi-cla commented Apr 8, 2022

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link

vercel bot commented Apr 8, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/strapijs/documentation/2C5u6ob3K7C8u3vayAyX3Bh7dEQR
✅ Preview: https://documentation-git-fork-danielsum-patch-1-strapijs.vercel.app

@stb13579
Copy link
Contributor

stb13579 commented Apr 8, 2022

Thanks @danielsum! I have asked one of our Solutions Engineers to review your PR. I will keep you apprised of the progress.

@stb13579 stb13579 self-assigned this Apr 10, 2022
Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with larvel but it looks fine to me.
Thanks for the PR :)

@stb13579 stb13579 merged commit 9f3c8ec into strapi:main Apr 11, 2022
@stb13579 stb13579 added source: Dev Docs PRs/issues targeting the Developer Docs target: v4 Documentation PRs/issues targeting content from docs.strapi.io (main branch). target: next Documentation PRs/issues targeting content from docs-next.strapi.io (next branch) size: medium If the PR includes 1+ file(s) with a total of 10 to 50 lines of text or <100 lines of code issue: doc request Issues that require adding new content, possibly with some prior research labels Apr 11, 2022
@pwizla pwizla removed the target: next Documentation PRs/issues targeting content from docs-next.strapi.io (next branch) label May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: doc request Issues that require adding new content, possibly with some prior research size: medium If the PR includes 1+ file(s) with a total of 10 to 50 lines of text or <100 lines of code source: Dev Docs PRs/issues targeting the Developer Docs target: v4 Documentation PRs/issues targeting content from docs.strapi.io (main branch).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Request]: Add Graphql/rest documentation for V4 using native Http Laravel Client
5 participants