🚨 Announcing Vendure v2 Beta

ApiOptions

ApiOptions

The ApiOptions define how the Vendure GraphQL APIs are exposed, as well as allowing the API layer to be extended with middleware.

Signature

interface ApiOptions {
  hostname?: string;
  port: number;
  adminApiPath?: string;
  shopApiPath?: string;
  adminApiPlayground?: boolean | any;
  shopApiPlayground?: boolean | any;
  adminApiDebug?: boolean;
  shopApiDebug?: boolean;
  shopListQueryLimit?: number;
  adminListQueryLimit?: number;
  adminApiValidationRules?: Array<(context: ValidationContext) => any>;
  shopApiValidationRules?: Array<(context: ValidationContext) => any>;
  channelTokenKey?: string;
  cors?: boolean | CorsOptions;
  middleware?: Middleware[];
  apolloServerPlugins?: PluginDefinition[];
  introspection?: boolean;
}

Members

hostname

property
type:
string
default:
''
Set the hostname of the server. If not set, the server will be available on localhost.

port

property
type:
number
default:
3000
Which port the Vendure server should listen on.

adminApiPath

property
type:
string
default:
'admin-api'
The path to the admin GraphQL API.

shopApiPath

property
type:
string
default:
'shop-api'
The path to the shop GraphQL API.

adminApiPlayground

property
type:
boolean | any
default:
false
The playground config to the admin GraphQL API ApolloServer playground.

shopApiPlayground

property
type:
boolean | any
default:
false
The playground config to the shop GraphQL API ApolloServer playground.

adminApiDebug

property
type:
boolean
default:
false
The debug config to the admin GraphQL API ApolloServer playground.

shopApiDebug

property
type:
boolean
default:
false
The debug config to the shop GraphQL API ApolloServer playground.

shopListQueryLimit

property
type:
number
default:
100
The maximum number of items that may be returned by a query which returns a PaginatedList response. In other words, this is the upper limit of the take input option.

adminListQueryLimit

property
type:
number
default:
1000
The maximum number of items that may be returned by a query which returns a PaginatedList response. In other words, this is the upper limit of the take input option.

adminApiValidationRules

property
type:
Array<(context: ValidationContext) => any>
default:
[]
Custom functions to use as additional validation rules when validating the schema for the admin GraphQL API ApolloServer validation rules.

shopApiValidationRules

property
type:
Array<(context: ValidationContext) => any>
default:
[]
Custom functions to use as additional validation rules when validating the schema for the shop GraphQL API ApolloServer validation rules.

channelTokenKey

property
type:
string
default:
'vendure-token'
The name of the property which contains the token of the active channel. This property can be included either in the request header or as a query string.

cors

property
type:
boolean | CorsOptions
default:
{ origin: true, credentials: true }
Set the CORS handling for the server. See the express CORS docs.

middleware

property
type:
Middleware[]
default:
[]
Custom Express or NestJS middleware for the server.

apolloServerPlugins

property
type:
PluginDefinition[]
default:
[]

Custom ApolloServerPlugins which allow the extension of the Apollo Server, which is the underlying GraphQL server used by Vendure.

Apollo plugins can be used e.g. to perform custom data transformations on incoming operations or outgoing data.

introspection

property
v1.5.0
type:
boolean
default:
true

Controls whether introspection of the GraphQL APIs is enabled. For production, it is recommended to disable introspection, since exposing your entire schema can allow an attacker to trivially learn all operations and much more easily find any potentially exploitable queries.

Note: when introspection is disabled, tooling which relies on it for things like autocompletion will not work.

Example

{
  introspection: process.env.NODE_ENV !== 'production'
}