# Схема объекта environment

Платформа dbt | Starter, Enterprise, Enterprise+

Объект environment позволяет запрашивать и сравнивать состояния definition (заданное) и applied (фактическое) для узлов (моделей, сидов, снимков, моделей и других) в вашем проекте dbt. Например, вы можете указать `environmentId`, чтобы получить дополнительную информацию об определённой модели (или узле другого типа) в этом окружении.

В разделе [Примеры запросов](#example-queries) показаны некоторые поля, которые можно запрашивать с помощью объекта `environment`. Полная схема со всеми доступными для запроса полями приведена в разделе [Поля](#fields).

### Аргументы

При запросе `environment` можно использовать следующие аргументы.

# Fetching data...

### Примеры запросов

Вы можете использовать `id` своего производственного окружения:

```graphql
query Example {
	environment(id: 834){ # Get the latest state of the production environment
		applied { # The state of an executed node as it exists as an object in the database
			models(first: 100){ # Pagination to ensure manageable response for large projects
				edges { node {
					uniqueId, name, description, rawCode, compiledCode, # Basic properties
					database, schema, alias, # Table/view identifier (can also filter by)
					executionInfo {executeCompletedAt, executionTime}, # Metadata from when the model was built
					tests {name, executionInfo{lastRunStatus, lastRunError}}, # Latest test results
					catalog {columns {name, description, type}, stats {label, value}}, # Catalog info
					ancestors(types:[Source]) {name, ...on SourceAppliedStateNode {freshness{maxLoadedAt, freshnessStatus}}}, # Source freshness }
					children {name, resourceType}}} # Immediate dependencies in lineage
				totalCount } # Number of models in the project
		}
		definition { # The logical state of a given project node given its most recent manifest generated
			models(first: 100, filter:{access:public}){ # Filter on model access (or other properties)
				edges { node {
					rawCode, # Compare to see if/how the model has changed since the last build
					jobDefinitionId, runGeneratedAt,	# When the code was last compiled or run
					contractEnforced, group, version}}} # Model governance
		}
	}
```

В связи с прекращением поддержки типа данных `Int` для `id` ниже приведён пример его замены на `BigInt`:

```graphql
query ($environmentId: BigInt!, $first: Int!) {
  environment(id: $environmentId) {
    applied {
      models(first: $first) {
        edges {
          node {
            uniqueId
            executionInfo {
              lastRunId
            }
          }
        }
      }
    }
  }
}
```

В связи с прекращением поддержки `modelByEnvironment` ниже приведён пример его замены на `environment`:

```graphql
query ($environmentId: BigInt!, $uniqueId: String) {
  environment(id: $environmentId) {
    applied {
      modelHistoricalRuns(uniqueId: $uniqueId) {
        uniqueId
        executionTime
        executeCompletedAt
      }
    }
  }
}
```

### Поля

При запросе `environment` можно использовать следующие поля.

# Fetching data...

Подробную информацию о запросах к полю `applied` объекта `environment` см. в разделе: [Применённое состояние](https://docs.getdbt.tech/docs/dbt-apis/discovery-schema-environment-applied.md)

Подробную информацию о запросах к полю `definition` объекта `environment` см. в разделе: [Определение](https://docs.getdbt.tech/docs/dbt-apis/discovery-schema-environment-definition.md)
