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 GraphQL 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/graphqlAPI 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
}
}Use the cartToken in subsequent requests via the X-Cart-Token header.
Customer Authentication β
mutation {
createLogin(input: {
email: "[email protected]"
password: "password123"
}) {
accessToken
customer {
id
firstName
email
}
}
}Use the accessToken in the Authorization: Bearer TOKEN header.
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 } } } }"
}'Using JavaScript/Fetch β
const query = `
query {
products(first: 10) {
edges {
node {
id
name
price
}
}
}
}
`;
const response = await fetch('https://your-domain.com/api/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query })
});
const data = await response.json();
console.log(data);Using Python β
import requests
query = """
query {
products(first: 10) {
edges {
node {
id
name
price
}
}
}
}
"""
response = requests.post(
'https://your-domain.com/api/graphql',
json={'query': query}
)
data = response.json()
print(data)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-Cart-Token | Guest cart token | 550e8400-e29b... |
Content-Type | Request format | application/json |
Accept-Language | Locale/Language | en_US or fr_FR |
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
- π Schema Documentation
- π¬ Community Forum
- π Issue Tracker
- π§ Contact Support

