Skip to content

Configuration ​

Constructor options live on Configuration. This page is the option list in one place, including codegen.

Strapi ​

OptionRequiredDefault
baseURLyesOrigin. /api is appended when missing.
defaultLocaleyesOmitted from query strings.
tokennoBearer token.
headersnoMerged into every request.
fetchnoglobalThis.fetch
timeoutno10000 ms, per attempt
retrynoOff. A number is attempts.
refreshOnUnauthorizednoOff. { token?, cookie?, onRefresh? }
concurrencyno5
graphqlEndpointno"/graphql", resolved against the origin
graphqlArgsnoRequired by query() and mutate()

StrapiClient takes the same options plus uid.

generateConfig ​

ts
import { generateConfig } from "@fbritoferreira/strapi";

export default generateConfig({
	types: {
		dir: "../my-strapi", // or url, never both
		includePlugins: false,
		email: process.env.STRAPI_ADMIN_EMAIL, // url only
		password: process.env.STRAPI_ADMIN_PASSWORD,
		output: "src/strapi-types.ts",
	},
	routes: {
		openapi: "./spec.json",
		token: process.env.STRAPI_TOKEN,
		password: process.env.STRAPI_DOCS_PASSWORD,
		output: "src/strapi-routes.ts",
	},
	graphql: {
		url: "http://localhost:1337/graphql",
		token: process.env.STRAPI_TOKEN,
		output: "src/strapi-graphql.ts",
	},
	watch: { interval: 2000 },
});

Every section is optional. See One config file and the CLI.

Released under the MIT License.