Class <Interface> SchemaService
publicThe 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);
}
}
derivation (}) Derivation public
Defined in ../packages/store/src/-types/q/schema-service.ts:155
- }
- 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.
fields (}) Map<string, FieldSchema> public
Defined in ../packages/store/src/-types/q/schema-service.ts:121
- }
- 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.
hasResource (}) Boolean public
Defined in ../packages/store/src/-types/q/schema-service.ts:90
- }
- StableRecordIdentifier| type: string
resource
- returns
- Boolean
Queries whether the SchemaService recognizes type
as a resource type
hasTrait (type) Boolean public
Defined in ../packages/store/src/-types/q/schema-service.ts:100
- type
- String
- returns
- Boolean
Queries whether the SchemaService recognizes type
as a resource trait
hashFn (}) HashFn public
Defined in ../packages/store/src/-types/q/schema-service.ts:144
- }
- 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.
registerDerivations (derivation) public
Defined in ../packages/store/src/-types/q/schema-service.ts:214
- derivation
- Derivation
Enables registration of a derivation.
The derivation can later be retrieved by the name
attached to it's [Type]
property.
registerHashFn (hashfn) public
Defined in ../packages/store/src/-types/q/schema-service.ts:226
- hashfn
- HashFn
Enables registration of a hashing function
The hashing function can later be retrieved by the name
attached to it's [Type]
property.
registerResource (schema) public
Defined in ../packages/store/src/-types/q/schema-service.ts:189
- 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.
registerResources (schemas) public
Defined in ../packages/store/src/-types/q/schema-service.ts:176
- 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.
registerTransformations (transform) public
Defined in ../packages/store/src/-types/q/schema-service.ts:202
- transform
- Transformation
Enables registration of a transformation.
The transformation can later be retrieved by the name
attached to it's [Type]
property.
resource (}) ResourceSchema public
Defined in ../packages/store/src/-types/q/schema-service.ts:166
- }
- StableRecordIdentifier| type: string
resource
- returns
- ResourceSchema
Returns the schema for the provided resource type.
resourceHasTrait (}, trait) Boolean public
Defined in ../packages/store/src/-types/q/schema-service.ts:110
- }
- StableRecordIdentifier| type: string
resource
- trait
- String
- returns
- Boolean
Queries whether the given resource has the given trait
transformation (}) Transformation public
Defined in ../packages/store/src/-types/q/schema-service.ts:133
- }
- 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.