# Configuring requests: envs, drafts, strict mode, cache tags, etc.

Each request to the GraphQL endpoint can carry **headers** that control behavior: target a specific environment, opt into draft content, narrow down GraphQL types, retrieve cache tags, and embed visual-editing metadata. Below, each section shows the raw HTTP header alongside the equivalent option on [`@datocms/cda-client`](https://www.datocms.com/docs/content-delivery-api/your-first-request.md), so you can pick whichever style fits your setup.

### Specifying an environment

If no environment is specified, the [primary environment](https://www.datocms.com/docs/general-concepts/primary-and-sandbox-environments.md) is used. To explicitly read from a different one:

@datocms/cda-client

```typescript
import { executeQuery } from '@datocms/cda-client';

const result = await executeQuery(query, {
  token: process.env.DATOCMS_READONLY_TOKEN,
  environment: 'my-sandbox-environment',
});
```

Raw HTTP header

```plaintext
X-Environment: <ENVIRONMENT-NAME>
```

### Preview mode to retrieve draft content

If you have the [Draft/Published system](https://www.datocms.com/docs/general-concepts/draft-published.md) active on some of your models, you can request the latest draft version of each record instead of the currently published one — useful for staging environments and local development:

@datocms/cda-client

```typescript
const result = await executeQuery(query, {
  token: process.env.DATOCMS_PREVIEW_TOKEN,
  includeDrafts: true,
});
```

Raw HTTP header

```plaintext
X-Include-Drafts: true
```

### Strict mode for non-nullable GraphQL types

If you want to make sure that no invalid record is ever returned without having to manually add an `_isValid` filter to every query, you can opt into strict mode:

@datocms/cda-client

```typescript
const result = await executeQuery(query, {
  token: process.env.DATOCMS_READONLY_TOKEN,
  excludeInvalid: true,
});
```

Raw HTTP header

```plaintext
X-Exclude-Invalid: true
```

In contrast to the `_isValid` filter, this header also has the effect of **narrowing down GraphQL types**:

-   Every field with a "Required" validation enforced will be associated with a non-nullable GraphQL type (e.g. `String` becomes `String!`)
-   Asset fields (both single and multiple) that have a "Image transformable by imgix" format validation will have the following properties associated with a non-nullable type: `focalPoint`, `width`, `height`, `responsiveImage`
    
-   Asset fields (both single and multiple) that have a "Video" format validation will have the following property associated with a non-nullable type: `video`
-   Asset fields (both single and multiple) that have a required alt and/or title validation will have the `alt` and/or `title` properties marked as non-null
    

You can read a little bit more about Strict Mode in our [announcement blog post](https://www.datocms.com/blog/introducing-strict-mode-for-graphql-cda-get-the-best-typescript-dx.md).

### Cache tags

To receive the [Cache Tags](https://www.datocms.com/docs/content-delivery-api/cache-tags.md) associated with your query, opt into the dedicated header. Cache tags travel back in the `X-Cache-Tags` response header, so on the client side you'll need access to the underlying `Response` — `rawExecuteQuery` returns it alongside the parsed result:

@datocms/cda-client

```typescript
import { rawExecuteQuery } from '@datocms/cda-client';

const [result, response] = await rawExecuteQuery(query, {
  token: process.env.DATOCMS_READONLY_TOKEN,
  returnCacheTags: true,
});

const cacheTags = response.headers.get('x-cache-tags');
```

Raw HTTP header

```plaintext
X-Cache-Tags: true
```

### Content Link

If you have [Content Link](https://www.datocms.com/docs/general-concepts/visual-editing.md) available on your project, two extra headers tell the CDA to embed the metadata that powers visual editing on websites hosted on Vercel:

@datocms/cda-client

```typescript
const result = await executeQuery(query, {
  token: process.env.DATOCMS_READONLY_TOKEN,
  contentLink: 'v1',
  baseEditingUrl: 'https://your-project.admin.datocms.com',
});
```

Raw HTTP headers

```plaintext
X-Visual-Editing: v1
X-Base-Editing-Url: https://<YOUR-PROJECT-NAME>.admin.datocms.com
```

`X-Base-Editing-Url` (and the equivalent `baseEditingUrl` option) can also be used in isolation: it enables the usage of the `_editingUrl` field in the GraphQL API.

## Related content in "Content Delivery API"

- [Content Delivery API Overview](https://www.datocms.com/docs/content-delivery-api.md)
- [Using the JavaScript CDA client](https://www.datocms.com/docs/content-delivery-api/your-first-request.md)
- [Authentication and permissions](https://www.datocms.com/docs/content-delivery-api/authentication.md)
- [Configuring requests: envs, drafts, strict mode, cache tags, etc.](https://www.datocms.com/docs/content-delivery-api/api-endpoints.md)
- [How to fetch records](https://www.datocms.com/docs/content-delivery-api/how-to-fetch-records.md)
- [Filtering records](https://www.datocms.com/docs/content-delivery-api/filtering-records.md)
- [Deep Filtering](https://www.datocms.com/docs/content-delivery-api/deep-filtering.md)
- [Ordering records](https://www.datocms.com/docs/content-delivery-api/ordering-records.md)
- [Pagination](https://www.datocms.com/docs/content-delivery-api/pagination.md)
- [Localization](https://www.datocms.com/docs/content-delivery-api/localization.md)
- [Direct vs. Inverse relationships](https://www.datocms.com/docs/content-delivery-api/inverse-relationships.md)
- [Hierarchical sorting (Tree-like collections)](https://www.datocms.com/docs/content-delivery-api/hierarchical-sorting.md)
- [Modular content fields](https://www.datocms.com/docs/content-delivery-api/modular-content-fields.md)
- [Structured text fields](https://www.datocms.com/docs/content-delivery-api/structured-text-fields.md)
- [Images and videos](https://www.datocms.com/docs/content-delivery-api/images-and-videos.md)
- [Filtering uploads](https://www.datocms.com/docs/content-delivery-api/filtering-uploads.md)
- [SEO and favicon fields](https://www.datocms.com/docs/content-delivery-api/seo-and-favicon.md)
- [Meta fields](https://www.datocms.com/docs/content-delivery-api/meta-fields.md)
- [Error codes & handling failures (CDA)](https://www.datocms.com/docs/content-delivery-api/errors.md)
- [CDA Technical Limits & Rate Limits](https://www.datocms.com/docs/content-delivery-api/technical-limits.md)
- [Complexity](https://www.datocms.com/docs/content-delivery-api/complexity.md)
- [Cache Tags](https://www.datocms.com/docs/content-delivery-api/cache-tags.md)
- [Custom Scalar Types](https://www.datocms.com/docs/content-delivery-api/custom-scalar-types.md)
- [Changelog](https://www.datocms.com/docs/content-delivery-api/changelog.md)