Skip to Content

Scalars

Protobuf scalar types to GraphQL scalar mappings.

Default Mappings

Integer Types

ProtobufGraphQL (ts-proto)GraphQL (protobuf-es-v1)
int32IntInt
uint32IntInt
sint32IntInt
fixed32IntInt
sfixed32IntInt
int64StringInt64
uint64StringInt64
sint64StringInt64
fixed64StringInt64
sfixed64StringInt64

Note: ts-proto maps 64-bit integers to String because JavaScript’s number type cannot safely represent all 64-bit integer values.

Floating Point Types

ProtobufGraphQL
floatFloat
doubleFloat

Other Types

ProtobufGraphQL
stringString
boolBoolean
bytesByte

Well-Known Types

Wrapper Types

Wrapper types are nullable versions of scalar types:

ProtobufGraphQL (ts-proto)GraphQL (protobuf-es-v1)
google.protobuf.Int32ValueIntInt
google.protobuf.UInt32ValueIntInt
google.protobuf.Int64ValueStringInt64
google.protobuf.UInt64ValueStringInt64
google.protobuf.SInt32ValueIntInt
google.protobuf.SInt64ValueStringInt64
google.protobuf.Fixed32ValueIntInt
google.protobuf.Fixed64ValueStringInt64
google.protobuf.SFixed32ValueIntInt
google.protobuf.SFixed64ValueStringInt64
google.protobuf.FloatValueFloatFloat
google.protobuf.DoubleValueFloatFloat
google.protobuf.StringValueStringString
google.protobuf.BoolValueBooleanBoolean
google.protobuf.BytesValueByteByte

Timestamp

ProtobufGraphQL
google.protobuf.TimestampDateTime

Custom Scalar Mappings

Override default mappings with the scalar option:

opt: - scalar=proto_type=GraphQLType

Example: Map 64-bit integers to BigInt

opt: - scalar=int64=BigInt - scalar=uint64=BigInt - scalar=sint64=BigInt - scalar=fixed64=BigInt - scalar=sfixed64=BigInt - scalar=google.protobuf.Int64Value=BigInt - scalar=google.protobuf.UInt64Value=BigInt - scalar=google.protobuf.SInt64Value=BigInt - scalar=google.protobuf.Fixed64Value=BigInt - scalar=google.protobuf.SFixed64Value=BigInt

Example: Map custom types

opt: - scalar=google.type.Date=Date - scalar=google.type.Money=Money

Example: Use Int for 64-bit integers

opt: - scalar=int64=Int - scalar=uint64=Int

Warning: This may lose precision for values larger than Number.MAX_SAFE_INTEGER.

ID Type

Use (graphql.field).id = true to use GraphQL ID type instead of the mapped scalar:

message User { // Required. Output only. uint64 id = 1 [(graphql.field).id = true]; }
type User { id: ID! }