Basker Docs

Send your first query

Query a Basker site from the browser, from curl, and from JavaScript with the FrontStage client

Every Basker site serves the FrontStage API at /graphql on its own host. The examples use https://www.example.org. Replace it with the host of your site.

Open the explorer

Open https://www.example.org/graphql in a browser. The page shows GraphiQL, an editor that runs queries against your site and shows the schema documentation.

Enter this query and run it:

{
  site {
    name
    defaultLocale
    locales {
      code
    }
  }
  navigation {
    title
    path
  }
}

GraphiQL sends the query as a GET request, the same way your site does.

Send the query with curl

Put the query in the query URL parameter. curl -G with --data-urlencode encodes it for you:

curl -s -G https://www.example.org/graphql \
  --data-urlencode 'query={ site { name } navigation { title path } }'

The response is JSON with a data key:

{
  "data": {
    "site": { "name": "Remarkable Theatre" },
    "navigation": [
      { "title": "Home", "path": "/" },
      { "title": "About", "path": "/about" },
      { "title": "Visit", "path": "/visit" },
      { "title": "Calendar", "path": "/calendar" }
    ]
  }
}

Pass variables

Send variables as JSON in the variables parameter. This query gets one event by its slug:

curl -s -G https://www.example.org/graphql \
  --data-urlencode 'query=query Event($slug: String!) { event(slug: $slug) { title path startDate venue { title } } }' \
  --data-urlencode 'variables={"slug":"holst-the-planets"}'
{
  "data": {
    "event": {
      "title": "Holst: The Planets",
      "path": "/events/holst-the-planets",
      "startDate": "2027-01-07T19:30:00.000Z",
      "venue": { "title": "Studio" }
    }
  }
}

A record that does not exist, or is not published, returns null.

Query from JavaScript

Any HTTP client works. Build the URL with URLSearchParams and send a GET request:

const url = new URL("https://www.example.org/graphql");
url.searchParams.set("query", "query Event($slug: String!) { event(slug: $slug) { title path } }");
url.searchParams.set("variables", JSON.stringify({ slug: "holst-the-planets" }));

const response = await fetch(url);
const { data, errors } = await response.json();

Do not add custom request headers in browser code. A custom header makes the browser send a preflight request first.

Use the FrontStage client

The @baskerhq/frontstage-client package sends queries as GET requests, uses persisted queries, and keeps URLs stable for the cache.

Not on npm yet

The client is not published to npm. For now, get it from the Basker repository, in packages/frontstage-client, and add it to your project as a local package.

import { createFrontstageClient } from "@baskerhq/frontstage-client";

const basker = createFrontstageClient({
  endpoint: "https://www.example.org/graphql",
});

const { event } = await basker.query<{
  event: { title: string; path: string } | null;
}>(
  `query Event($slug: String!) {
    event(slug: $slug) { title path }
  }`,
  { slug: "holst-the-planets" },
);

query throws a FrontstageError when the response has errors. To read errors yourself, call request. It returns { data, errors, cacheControl }.

To use another language, pass locale, either to createFrontstageClient or as the third argument of query:

const { event } = await basker.query(EVENT_QUERY, { slug: "holst-the-planets" }, { locale: "es" });

On this page