Types & Fields

The crux of GraphQLize is generating the GraphQL types and queries by making use of JDBC metadata. This page documents the conventions and assumptions behind this automatic generation.

Type name

For every tables and views in the database, GraphQLize generates a GraphQL type. The name of the GraphQL type is the singularized, PascalCase version of the corresponding table or view name.

Table/View NameGraphQL Type Name
actorActor
film_actorFilmActor
commentsComment

GraphQlize supports Postgres schema. If the schema in question is not a default schema (public), then it will be used as a prefix in the GraphQL type name.

Schema NameTable/View NameGraphQL Type Name
personstate_provincePersonStateProvince
human_resourcesemployeeHumanResourcesEmployee
note

The table name is alone singularized and not the schema name.

Field name

The Field names of a generated GraphQL Type represent the column names of the corresponding database table or view. GraphQLize generates the field name by converting the column name to its camelCase version.

For a table like below,

CREATE TABLE actor (
actor_id SERIAL PRIMARY KEY,
first_name character varying(45) NOT NULL,
last_name character varying(45) NOT NULL
);

GraphQLize generates a GraphQL type as

type Actor {
actorId: Int!
firstName: String!
lastName: String!
}

Field type

GraphQLize supports the standard GraphQL scalar types and some custom scalar types.

During the schema generation, GraphQLize checks the column's database type and convert it to a GraphQL scalar type. Refer the table below for the type conversion mapping.

GraphQL Scalar TypeData Type(s)
Intinteger, int, int2 int4, smallint, smallserial, serial, serial2, serial4
Floatreal, float4, float8, double precision
Stringbit, bit varying, char, character varying, varchar, citext, bpchar, macaddr8, text, money
Booleanboolean, bool
UUIDuuid
Longbigint,int8,bigserial,serial8
BigDecimalnumeric,decimal
Datedate
Timetime, time without time zone
TimeWithTimeZonetimetz, time with time zone
DateTimetimestamp,timestamp without time zone
DateTimeWithTimeZonetimestamptz,timestamp with time zone
note

If a column's database type is not available in the above table, GraphQLize assumes String as the default scalar data type for the corresponding GraphQL field.