Class <Interface> SchemaService

public

The SchemaService provides the ability to query for information about the structure of any resource type.

Applications can provide any implementation of the SchemaService they please so long as it conforms to this interface.

The design of the service means that schema information could be lazily populated, derived-on-demand, or progressively enhanced during the course of an application's runtime. The primary requirement is merely that any information the service needs to correctly respond to an inquest is available by the time it is asked.

The @ember-data/model package provides an implementation of this service which makes use of your model classes as the source of information to respond to queries about resource schema. While this is useful, this may not be ideal for your application. For instance, Schema information could be sideloaded or pre-flighted for API calls, resulting in no need to bundle and ship potentially large and expensive JSON or large Javascript based Models to pull information from.

To register a custom schema implementation, implement the store's createSchemaService hook to return an instance of your service.

import Store from '@ember-data/store';
import CustomSchemas from './custom-schemas';

export default class extends Store {
  createSchemaService() {
    return new CustomSchemas();
  }
}

At runtime, both the Store and the CacheCapabilitiesManager provide access to this service via the schema property.

export default class extends Component {
 @service store;

 get fields() {
   return this.store
     .schema
     .fields(this.args.dataType);
 }
}

Show:

}
DerivedField| type: string

field

returns
Derivation

Returns the derivation registered with the name provided by field.type. Validates that the field is a valid DerivedField.

}
StableRecordIdentifier| type: string

resource

returns
Map<string, FieldSchema>

Queries for the fields of a given resource type or resource identity.

Should error if the resource type is not recognized.

}
StableRecordIdentifier| type: string

resource

returns
Boolean

Queries whether the SchemaService recognizes type as a resource type

type
String
returns
Boolean

Queries whether the SchemaService recognizes type as a resource trait

}
HashField| type: string

field

returns
HashFn

Returns the hash function registered with the name provided by field.type. Validates that the field is a valid HashField.

derivation
Derivation

Enables registration of a derivation.

The derivation can later be retrieved by the name attached to it's [Type] property.

hashfn
HashFn

Enables registration of a hashing function

The hashing function can later be retrieved by the name attached to it's [Type] property.

schema
ResourceSchema

Enables registration of a single ResourceSchema.

This can be useful for either pre-loading schema information or for registering schema information delivered by API calls or other sources just-in-time.

schemas

Enables registration of multiple ResourceSchemas at once.

This can be useful for either pre-loading schema information or for registering schema information delivered by API calls or other sources just-in-time.

transform
Transformation

Enables registration of a transformation.

The transformation can later be retrieved by the name attached to it's [Type] property.

}
StableRecordIdentifier| type: string

resource

returns
ResourceSchema

Returns the schema for the provided resource type.

}
StableRecordIdentifier| type: string

resource

trait
String
returns
Boolean

Queries whether the given resource has the given trait

}
TransformableField| type: string

field

returns
Transformation

Returns the transformation registered with the name provided by field.type. Validates that the field is a valid transformable.