# SchemaFile

The Schema for a GraphQL Api.

If no options are configured, schema will be generated
code-first.

Implements: [ISchema](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.ISchema.html)
Obtainable from: SchemaFile.fromAsset

- Source: [`aws-appsync/lib/schema.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-appsync/lib/schema.ts#L64)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

TypeScript:

```ts
const schema = new appsync.SchemaFile({ filePath: 'mySchemaFile' })
new appsync.GraphqlApi(this, 'api', {
  name: 'myApi',
  definition: appsync.Definition.fromSchema(schema),
  enhancedMetricsConfig: {
    dataSourceLevelMetricsBehavior: appsync.DataSourceLevelMetricsBehavior.FULL_REQUEST_DATA_SOURCE_METRICS,
    operationLevelMetricsConfig: appsync.OperationLevelMetricsConfig.ENABLED,
    resolverLevelMetricsBehavior: appsync.ResolverLevelMetricsBehavior.FULL_REQUEST_RESOLVER_METRICS,
  },
});
```

Python:

```python
schema = appsync.SchemaFile(file_path="mySchemaFile")
appsync.GraphqlApi(self, "api",
    name="myApi",
    definition=appsync.Definition.from_schema(schema),
    enhanced_metrics_config=appsync.EnhancedMetricsConfig(
        data_source_level_metrics_behavior=appsync.DataSourceLevelMetricsBehavior.FULL_REQUEST_DATA_SOURCE_METRICS,
        operation_level_metrics_config=appsync.OperationLevelMetricsConfig.ENABLED,
        resolver_level_metrics_behavior=appsync.ResolverLevelMetricsBehavior.FULL_REQUEST_RESOLVER_METRICS
    )
)
```

Java:

```java
SchemaFile schema = SchemaFile.Builder.create().filePath("mySchemaFile").build();
GraphqlApi.Builder.create(this, "api")
        .name("myApi")
        .definition(Definition.fromSchema(schema))
        .enhancedMetricsConfig(EnhancedMetricsConfig.builder()
                .dataSourceLevelMetricsBehavior(DataSourceLevelMetricsBehavior.FULL_REQUEST_DATA_SOURCE_METRICS)
                .operationLevelMetricsConfig(OperationLevelMetricsConfig.ENABLED)
                .resolverLevelMetricsBehavior(ResolverLevelMetricsBehavior.FULL_REQUEST_RESOLVER_METRICS)
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var schema = new SchemaFile(new SchemaProps { FilePath = "mySchemaFile" });
new GraphqlApi(this, "api", new GraphqlApiProps {
    Name = "myApi",
    Definition = Definition.FromSchema(schema),
    EnhancedMetricsConfig = new EnhancedMetricsConfig {
        DataSourceLevelMetricsBehavior = DataSourceLevelMetricsBehavior.FULL_REQUEST_DATA_SOURCE_METRICS,
        OperationLevelMetricsConfig = OperationLevelMetricsConfig.ENABLED,
        ResolverLevelMetricsBehavior = ResolverLevelMetricsBehavior.FULL_REQUEST_RESOLVER_METRICS
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
schema := appsync.NewSchemaFile(&SchemaProps{
	FilePath: jsii.String("mySchemaFile"),
})
appsync.NewGraphqlApi(this, jsii.String("api"), &GraphqlApiProps{
	Name: jsii.String("myApi"),
	Definition: appsync.Definition_FromSchema(schema),
	EnhancedMetricsConfig: &EnhancedMetricsConfig{
		DataSourceLevelMetricsBehavior: appsync.DataSourceLevelMetricsBehavior_FULL_REQUEST_DATA_SOURCE_METRICS,
		OperationLevelMetricsConfig: appsync.OperationLevelMetricsConfig_ENABLED,
		ResolverLevelMetricsBehavior: appsync.ResolverLevelMetricsBehavior_FULL_REQUEST_RESOLVER_METRICS,
	},
})
```

## Initializer

TypeScript:

```ts
new SchemaFile(options: SchemaProps)
```

Python:

```python
SchemaFile(options: SchemaProps)
```

Java:

```java
new SchemaFile(SchemaProps options)
```

C# / .NET:

```csharp
new SchemaFile(SchemaProps options)
```

Golang:

```go
NewSchemaFile(Options SchemaProps)
```

## Properties

- `definition`: string — The definition for this schema.

## Methods

- `bind(api: IGraphQLApiRef, _options?: SchemaBindOptions): ISchemaConfig` — Called when the GraphQL Api is initialized to allow this object to bind to the stack.

  **Parameters**

  - `api` — The binding GraphQL Api.

- `fromAsset(filePath: string): SchemaFile // chainable` (static) — Generate a Schema from file.

  **Parameters**

  - `filePath` — the file path of the schema file.

  **Returns:** `SchemaAsset` with immutable schema definition
