@terascope/data-types / data-type / DataType
Class: DataType
Defined in: data-types/src/data-type.ts:41
A DataType is used to define the structure of data with version support and can be converted to the following formats:
- Elasticsearch Mappings
- GraphQL Schemas
- xLucene
It is constructed from a DataTypeConfig (a version plus a map of field
names to their BaseType configs); nested Object and Tuple fields
declared with dot-notation are grouped into GroupType /
TupleType instances during construction.
Example
const dataType = new DataType({
version: 1,
fields: {
name: { type: 'Keyword' },
location: { type: 'GeoPoint' },
},
}, 'Person');
dataType.toESMapping(); // Elasticsearch/OpenSearch mapping
dataType.toGraphQL(); // GraphQL schema string
dataType.toXlucene(); // xLucene type config
Constructors
Constructor
new DataType(
config,typeName?,description?):DataType
Defined in: data-types/src/data-type.ts:123
Parameters
| Parameter | Type | Description |
|---|---|---|
config | Partial<DataTypeConfig> | the data type config; version defaults to the latest and fields to {}, and the config is validated (throwing on an unknown version or invalid field config). |
typeName? | string | optional name for the type (required by some conversions, e.g. GraphQL). |
description? | string | optional description carried into the GraphQL output. |
Returns
DataType
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
description? | readonly | string | - | data-types/src/data-type.ts:43 |
fields | readonly | ReadonlyDataTypeFields | - | data-types/src/data-type.ts:44 |
groupedFields | readonly | GroupedFields | An object of base fields with their child fields | data-types/src/data-type.ts:47 |
name | readonly | string | - | data-types/src/data-type.ts:42 |
version | readonly | number | - | data-types/src/data-type.ts:45 |
Methods
toESMapping()
toESMapping(
__namedParameters?):ESMapping
Defined in: data-types/src/data-type.ts:142
Convert the DataType to an elasticsearch mapping.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | Partial<ESMappingOptions> |
Returns
ESMapping
toGraphQL()
toGraphQL(
args?,removeScalars?):string
Defined in: data-types/src/data-type.ts:199
Convert the DataType to a formatted GraphQL schema string. Combines the
generated custom types, the base type, an optional input type, and any
args.customTypes, then validates and prints the result. Pass
removeScalars to strip scalar declarations from the output.
Note: fields that reference an undeclared scalar (e.g. Any/Tuple →
JSON) require that scalar to be supplied for the schema to validate.
Parameters
| Parameter | Type | Default value |
|---|---|---|
args? | GraphQLOptions | undefined |
removeScalars? | boolean | false |
Returns
string
toGraphQLTypes()
toGraphQLTypes(
args?):GraphQLTypesResult
Defined in: data-types/src/data-type.ts:215
Build the GraphQL type parts without assembling/validating a full schema:
the baseType definition, an optional inputType, and the customTypes
(scalars and generated nested types) the fields reference. Use this when
composing several data types into one schema (see
DataType.mergeGraphQLDataTypes); use toGraphQL for a single,
ready-to-use schema string. Throws if no type name is available.
Parameters
| Parameter | Type |
|---|---|
args | GraphQLOptions |
Returns
toXlucene()
toXlucene():
xLuceneTypeConfig
Defined in: data-types/src/data-type.ts:294
Convert the DataType to an xLucene type config — a flat map of field name (including nested dot-notation paths) to its xLucene field type, merged across every field.
Returns
xLuceneTypeConfig
mergeGraphQLDataTypes()
staticmergeGraphQLDataTypes(types,options?):string
Defined in: data-types/src/data-type.ts:58
Merge multiple data types into a single GraphQL schema, de-duplicating
shared custom types and scalars. Throws on a missing or duplicate type
name (or duplicate input name when createInputTypes is set). Options
control input-type generation, snake_case naming, scalar removal, and
per-type reference/virtual fields.
Parameters
| Parameter | Type |
|---|---|
types | DataType[] |
options | MergeGraphQLOptions |
Returns
string