Download the PHP package gorilladash/laravel-website-sdk without Composer
On this page you can find all versions of the php package gorilladash/laravel-website-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gorilladash/laravel-website-sdk
More information about gorilladash/laravel-website-sdk
Files in gorilladash/laravel-website-sdk
Package laravel-website-sdk
Short Description Laravel SDK for the GorillaDash website GraphQL API with stale-while-revalidate caching for instant SSR.
License MIT
Informations about the package laravel-website-sdk
GorillaDash Website SDK
A Laravel package that connects a client website to the GorillaDash website GraphQL API and serves its content through a stale-while-revalidate (SWR) cache — so server-rendered pages return instantly from cache while fresh data is fetched from the API in the background. The browser never waits on an API call.
Live demo: website-sdk-demo.gorilladash.com — a small Inertia + SSR site that lets you enter credentials, run any of the website GraphQL queries, and watch the cache behaviour (and timings) live.
Why
Client websites built on GorillaDash need to render marketing/content pages fast. Calling the GraphQL API on every request adds latency and a hard dependency on the API being up. This SDK puts a cache in front of the API with stale-while-revalidate semantics:
| Cache state | Behaviour |
|---|---|
| No cache | Block, fetch from the API, store, return. |
| Younger than TTL (default 60s) | Serve cached. No API call. |
| Older than TTL | Serve cached instantly, and refresh from the API in the background (after the response is sent — no queue worker needed). The next request gets the newer data. |
Stale data is retained well past the TTL so there is always something to serve, and background refreshes are guarded by a per-key lock to avoid stampedes.
Requirements
- PHP 8.3+
- Laravel 11, 12 or 13
Installation
The service provider and the GorillaDash facade are auto-discovered.
The provider is built on spatie/laravel-package-tools:
it extends PackageServiceProvider and wires everything declaratively in configurePackage() —
the config file (published under the website-sdk-config tag) and the cache-clear webhook route
(routes/web.php). Service bindings are registered in the packageRegistered() lifecycle hook.
Credentials
From the GorillaDash website API settings you get three values. Map them as follows — the public key is not used for GraphQL auth:
The SDK exchanges these for a bearer token at {base_uri}/oauth/token
(OAuth2 client-credentials grant) and caches the token automatically.
Configuration
All options live in config/website-sdk.php and are env-driven:
| Option | Env var | Default | Description |
|---|---|---|---|
base_uri |
GD_WEBSITE_BASE_URI |
https://api.gorilladash.com |
API base URL (token + GraphQL). |
client_id |
GD_WEBSITE_CLIENT_ID |
— | Passport OAuth client id (website "ID"). |
client_secret |
GD_WEBSITE_CLIENT_SECRET |
— | Passport client secret ("API Access Token"). |
public_key |
GD_WEBSITE_PUBLIC_KEY |
— | Website public key — authenticates the cache-clear webhook (not GraphQL). |
cache_ttl |
GD_WEBSITE_CACHE_TTL |
60 |
Freshness window (seconds). |
cache_store |
GD_WEBSITE_CACHE_STORE |
app default | Laravel cache store to use. |
cache_prefix |
GD_WEBSITE_CACHE_PREFIX |
gd_website: |
Cache key prefix. |
stale_retention_multiplier |
GD_WEBSITE_STALE_RETENTION |
100 |
Stale data kept for cache_ttl × this (0 = forever). |
max_stale_age |
GD_WEBSITE_MAX_STALE_AGE |
86400 |
Hard ceiling on stale age (seconds); past it, block and refetch. 0 = disabled. |
register_graphql_route |
GD_WEBSITE_GRAPHQL_ROUTE |
true |
Expose the POST GraphQL endpoint. |
graphql_path |
GD_WEBSITE_GRAPHQL_PATH |
graphql |
Path for the GraphQL endpoint. |
register_clear_cache_route |
GD_WEBSITE_CLEAR_CACHE_ROUTE |
true |
Register the cache-clear webhook. |
clear_cache_path |
GD_WEBSITE_CLEAR_CACHE_PATH |
gorilla-dash/clear-cache |
Path for the cache-clear webhook. |
token_skew |
GD_WEBSITE_TOKEN_SKEW |
60 |
Re-exchange the token this many seconds early. |
http_timeout |
GD_WEBSITE_HTTP_TIMEOUT |
10 |
Per-request timeout (seconds). |
Usage
Queries are built with mghoneimy/php-graphql-client
(Packagist: gmostafa/php-graphql-client, a dependency of this package). graphql() takes a
Query (or QueryBuilderInterface) object; graphqlWithMeta() additionally accepts a raw
query string.
HTTP endpoints
The package registers two routes (both can be disabled or repathed via config — see the table above):
POST /graphql
A ready-to-use GraphQL endpoint that proxies a { query, variables } body through the SWR
cache and returns the full envelope (data + cache metadata). Useful for client-side / SSR
fetching without writing a controller:
Cache-clear webhook
GorillaDash calls this when content changes, to flush this site's cache. Point GorillaDash's
"Cache Clear URL" at {your-site}/gorilla-dash/clear-cache?key={public_key}; a request whose
key matches public_key flushes the cache (any other request gets a 404).
Error handling
Transport, auth and GraphQL errors throw GorillaDash\WebsiteSdk\Exceptions\GdRequestException:
Inertia SSR client sites
Fetch in the controller and pass the data as Inertia props — the cache keeps it fast and SSR renders it into the initial HTML:
Testing
Fake the HTTP layer with Laravel's Http::fake() — no real API calls:
Run the package test suite:
How it works
TokenManager— exchanges client-credentials for a bearer token and caches it until just before expiry.GraphQlTransport— sends queries with the bearer token; retries once on a 401 with a fresh token.SwrCache— the stale-while-revalidate logic; schedules background refreshes via the application'sterminatingcallbacks (runs after the response is sent).
License
MIT — see LICENSE.
All versions of laravel-website-sdk with dependencies
gmostafa/php-graphql-client Version ^1.14
illuminate/cache Version ^11.0 || ^12.0 || ^13.0
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/http Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.16