GraphQL 到 PostgresQL 类型映射
GraphQL to PostgresQL type mapping
首先我必须承认:我是 GraphQL 的新手。但是尽管如此,我还是试图从数据库元数据中生成 "GraphQLObjectType" 模式。
我正在寻找 GraphQLTypes 和 PostgresQL 基本列类型之间的 映射。
以下列表包含 postgresQL 中最有趣的类型:
bool、text、date、time、timestamp、numeric、integer、interval、bytea、json、timestamptz、bigint、jsonb
到目前为止,我在挖掘 postgraphql 等几个项目时可以找到以下映射。
postgresType -> GraphQLType
文本 -> GraphQLString
整数 -> GraphQLInt
布尔值 -> GraphQLBoolean
至于numeric
类型,如果你的问题域可以用real
或double precision
,你可以使用GraphQLFloat
类型。它们都实现了相同的 IEEE 754 规范。有关详细信息,请参阅 GraphQL spec and PostgreSQL documentation on floating-point types。
GraphQL 目前支持的默认数据类型不如 PostgreSQL。但是,可以使用 GraphQL 中可用的通用类型来开发自定义 GraphQL 类型。查看很棒的指南 Deep Dive into GraphQL Type System to see how to do that. Another example is graphql-custom-types。
首先我必须承认:我是 GraphQL 的新手。但是尽管如此,我还是试图从数据库元数据中生成 "GraphQLObjectType" 模式。
我正在寻找 GraphQLTypes 和 PostgresQL 基本列类型之间的 映射。
以下列表包含 postgresQL 中最有趣的类型:
bool、text、date、time、timestamp、numeric、integer、interval、bytea、json、timestamptz、bigint、jsonb
到目前为止,我在挖掘 postgraphql 等几个项目时可以找到以下映射。
postgresType -> GraphQLType
文本 -> GraphQLString
整数 -> GraphQLInt
布尔值 -> GraphQLBoolean
至于numeric
类型,如果你的问题域可以用real
或double precision
,你可以使用GraphQLFloat
类型。它们都实现了相同的 IEEE 754 规范。有关详细信息,请参阅 GraphQL spec and PostgreSQL documentation on floating-point types。
GraphQL 目前支持的默认数据类型不如 PostgreSQL。但是,可以使用 GraphQL 中可用的通用类型来开发自定义 GraphQL 类型。查看很棒的指南 Deep Dive into GraphQL Type System to see how to do that. Another example is graphql-custom-types。