GraphQL API - Introduction β
Welcome to the Bagisto GraphQL API documentation! This guide will help you build modern, efficient e-commerce applications using our comprehensive GraphQL platform.
What is GraphQL? β
GraphQL is a query language and runtime that allows clients to request exactly the data they needβnothing more, nothing less. It provides a strongly typed schema and enables developers to build flexible, efficient APIs.
Key Benefits for Bagisto:
- π― Precise Data Fetching - Request only the fields you need
- β‘ Reduced Bandwidth - Smaller payloads improve performance
- π± Mobile Optimized - Perfect for bandwidth-constrained environments
- π Single Endpoint - All operations through one
/api/graphqlendpoint - π Self-Documenting - Schema includes inline documentation
- π οΈ Developer Friendly - Interactive playground included
Architecture Overview β
Bagisto's GraphQL API is built on API Platform for Laravel, a powerful framework that provides robust GraphQL support out of the box. This architecture enables a modern, type-safe API layer with minimal configuration.
Bagisto's GraphQL API is built using the Platforma API Laravel plugin with Bagisto's BagistoApi plugin, providing two distinct API layers:
ποΈ Shop API (Frontend) β
The public-facing API for customer-facing operations:
- Product browsing and search
- Customer authentication and profile management
- Shopping cart management
- Checkout and order placement
- Reviews and ratings
- Wishlist management
π¨βπΌ Admin API (Backend) β
The administrative API for management operations:
- Product and category management
- Customer administration
- Order management and fulfillment
- System configuration
- Reports and analytics
Quick Start β
Access the Playground β
Two ways to explore the API:
Interactive GraphQL Playground:
https://your-domain.com/api/graphiqlAPI Endpoints β
| Endpoint | Purpose | Authentication |
|---|---|---|
/api/graphql | Main GraphQL endpoint | Optional (Shop APIs) / Required (Admin APIs) |
Authentication Methods β
Guest Checkout β
Perfect for unauthenticated users:
mutation {
createCartToken(input: {}) {
cartToken {
id
cartToken
}
}
}Use the cartToken in the Authorization: Bearer TOKEN header along with the X-STOREFRONT-KEY .
Customer Authentication β
mutation {
createCustomerLogin(
input: {
email: "[email protected]"
password: "password123"
}
) {
customerLogin {
id
_id
apiToken
token
success
message
}
}
}Use the accessToken in the Authorization: Bearer TOKEN header along with the X-STOREFRONT-KEY .
Token Verification β
mutation {
createVerifyToken(input: {
token: "your-token-here"
}) {
verifyToken {
isValid
message
}
}
}Making Your First Request β
Using cURL β
curl -X POST https://your-domain.com/api/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query { products(first: 10) { edges { node { id name } } } }"
}'Response Format β
All GraphQL responses follow a consistent format:
{
"data": {
"products": {
"edges": [
{
"node": {
"id": "1",
"name": "Product Name",
"price": "99.99"
}
}
]
}
}
}Error Responses β
{
"errors": [
{
"message": "Validation failed",
"extensions": {
"validation": {
"email": ["The email field is invalid"]
}
}
}
],
"data": null
}Common Headers β
| Header | Purpose | Example |
|---|---|---|
Authorization | Authentication token | Bearer eyJhbGc... |
X-STOREFRONT-KEY | For Public Data | pk_storefront_oJv4u-e29b... |
Content-Type | Request format | application/json |
Pagination β
Bagisto uses cursor-based pagination for efficient data retrieval:
query {
products(first: 20, after: "cursor-value") {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
name
}
}
}
}Parameters:
first: Number of items to return (max: 100)after: Cursor to start fromlast: Number of items from endbefore: Cursor to end at
What's Next? β
- π Shop API Reference - Complete shop operations guide
- π Admin API Reference - Admin operations guide
- π Authentication Guide - Detailed auth methods
- π§ͺ Integration Guides - Code examples for your stack
- π‘ Best Practices - Performance and security tips
Support & Resources β
- π Interactive Playground
- π¬ Community Forum
- π Issue Tracker
- π§ Contact Support

