简体   繁体   English

GraphQL到PostgresQL类型映射

[英]GraphQL to PostgresQL type mapping

First of all I have to admit: I'm quiet new to GraphQL. 首先,我必须承认:我是GraphQL的新手。 But nevertheless I am trying to generate "GraphQLObjectType" schemata out of the database metadata. 但是,尽管如此,我还是试图从数据库元数据中生成“ GraphQLObjectType”模式。

I am looking for a mapping between the GraphQLTypes and PostgresQL basic column types. 我正在寻找GraphQLTypes和PostgresQL基本列类型之间的映射

The following list contains the most interesting types in postgresQL: 以下列表包含postgresQL中最有趣的类型:

bool, text, date, time, timestamp, numeric, integer, interval, bytea, json, timestamptz, bigint, jsonb 布尔,文本,日期,时间,时间戳,数值,整数,间隔,bytea,json,timestamptz,bigint,jsonb

So far I could find the following mapping while digging in several projects like postgraphql. 到目前为止,在挖掘诸如postgraphql之类的几个项目时,我可以找到以下映射。

postgresType -> GraphQLType postgresType-> GraphQLType

text -> GraphQLString 文字-> GraphQLString

integer -> GraphQLInt 整数-> GraphQLInt

boolean -> GraphQLBoolean 布尔-> GraphQLBoolean

As for numeric type, if your problem domain is fine with real or double precision , you can use GraphQLFloat type. 至于numeric类型,如果您的问题域可以使用realdouble precision ,则可以使用GraphQLFloat类型。 They all implement the same IEEE 754 spec. 它们都实现相同的IEEE 754规范。 For more details, see GraphQL spec and PostgreSQL documentation on floating-point types . 有关更多详细信息,请参见GraphQL规范和有关浮点类型的 PostgreSQL文档。

GraphQL currently does not support as many default data types as PostgreSQL. GraphQL当前不支持与PostgreSQL一样多的默认数据类型。 However, it is possible to develop custom GraphQL types using the generic types available in GraphQL. 但是,可以使用GraphQL中可用的通用类型来开发自定义GraphQL类型。 Check out an awesome guide Deep Dive into GraphQL Type System to see how to do that. 查阅出色的指南, 深入了解GraphQL Type System,以了解如何做到这一点。 Another example is graphql-custom-types . 另一个示例是graphql-custom-types

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM