Bagisto's GraphQL API enables a seamless, headless eCommerce experience built on Laravel. This API delivers ultra-fast, dynamic, and personalized shopping experiences through a scalable, open-source platform.
Read our full documentation: Bagisto GraphQL API Docs
This API was developed in collaboration with the Ucraft Team.
- Bagisto: v2.3.0
To install the Bagisto GraphQL API, follow these steps:
-
Install via Composer
Run the following command in your terminal to install the GraphQL API package:
composer require bagisto/graphql-api:dev-main
-
Update Middleware Configuration
In your
bootstrap/app.php
file, add the following session middleware changes:use Illuminate\Session\Middleware\StartSession; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; return Application::configure(basePath: dirname(__DIR__)) ->withMiddleware(function (Middleware $middleware) { // ... rest of middleware setup /** * Remove session and cookie middleware from the 'web' middleware group. */ $middleware->removeFromGroup('web', [StartSession::class, AddQueuedCookiesToResponse::class]); /** * Adding session and cookie middleware globally to apply across non-web routes (e.g. GraphQL) */ $middleware->append([StartSession::class, AddQueuedCookiesToResponse::class]); }) // ... rest of configuration
This ensures that session and cookie middleware are applied globally across all routes, including API and GraphQL endpoints.
-
Update Environment Settings
Add the following entries to your
.env
file to configure JWT settings:JWT_TTL=525600 JWT_SHOW_BLACKLIST_EXCEPTION=true
-
Publish Assets and Configurations
Run the command below to publish assets and configurations for Bagisto GraphQL:
php artisan bagisto-graphql:install
-
GraphQL Playground
After installation, you can test your API through the GraphQL Playground. Visit:
http://your-domain.com/graphiql
-
Postman Integration
Alternatively, you can test the API using Postman by accessing:
http://your-domain.com/graphql
-
Authorization
To authorize requests for certain APIs, you may need to provide the
MOBIKUL_API_KEY
.-
Locate the API Key
Find the
MOBIKUL_API_KEY
in your.env
file:MOBIKUL_API_KEY=your-mobikul-api-key
-
Share with App Development Team
Copy this key and securely share it with the Development team as required for API authorization.
-
Using the API Key
When making requests to protected admin endpoints, include the API key in the request headers:
MOBIKUL_API_KEY: your-mobikul-api-key
Replace
your-mobikul-api-key
with the actual value from your.env
file.
-
-
GraphQL Playground Endpoint Configuration
Ensure that the
GRAPHQL_ENDPOINT
in your.env
file is set to your application's URL followed by/graphiql
. For example:GRAPHQL_ENDPOINT=https://your-domain.com/graphiql
-
Cache Your GraphQL Schema for Better Performance
To avoid rebuilding the schema on every request, you can cache it. This improves performance significantly in production environments.
Run the following Artisan command to cache the schema:
php artisan lighthouse:cache
If you make changes to your schema, remember to clear the cache:
php artisan lighthouse:clear-cache
That's it! Your Bagisto GraphQL API is now ready. Execute the project on your specified domain and start building your headless eCommerce solution.