GraphQL type mapping for PostgresQL

First of all, I have to admit: I am a silent newbie in GraphQL. Nevertheless, I am trying to create "GraphQLObjectType" schemas from database metadata.

I am looking for a mapping between GraphQLTypes and PostgresQL base column types.

The following list contains the most interesting types in postgresQL:

bool, text, date, time, timestamp, numeric, integer, interval, bytea, json, timestamptz, bigint, jsonb

So far, I could find the following mapping while digging in several projects like postgraphql.

postgresType → GraphQLType

text -> GraphQLString

integer → GraphQLInt

boolean → GraphQLBoolean

+4
source share
1 answer

As for the type numeric, if your problem domain is ok with realor double precision, you can use a type GraphQLFloat. They all implement the same IEEE 754 specification. For more information, see the GraphQL spec and the PostgreSQL documentation for floating point types .

GraphQL currently does not support as many default data types as PostgreSQL. However, you can create your own GraphQL types using the generic types available in GraphQL. Check out the great Deep Dive tutorial on the GraphQL type system to learn how to do this. Another example is graphql-custom-types .

+3

Source: https://habr.com/ru/post/1661956/


All Articles