Custom Scalars and Enums

Custom scalars

You can use custom scalars to describe your data model's fields, but in addition to including them in your schema, you will also need to configure Sqlmancer accordingly. The @sqlmancer directive includes a customScalars directive for mapping any additional scalars to their appropriate type. The available types are: string, number, boolean, JSON and Date. The type you map a custom scalar to effects the TypeScript typings as well as any generated types (like those added with the @where and @aggregate directives). The customScalars object has the following type:

input SqlmancerCustomScalars {
string: [String!]
number: [String!]
boolean: [String!]
JSON: [String!]
Date: [String!]
}

Example usage:

import { GraphQLDateTime, GraphQLJSON, GraphQLGUID, GraphQLURL } from 'graphql-scalars'
const typeDefs = gql`
scalar DateTime
scalar JSON
scalar GUID
scalar URL
type Query @sqlmancer(
customScalars: {
Date: ["DateTime"]
JSON: ["JSON"]
string: ["GUID", "URL"]
}
) {
...
}
...
`
const resolvers = {
DateTime: GraphQLDateTime,
JSON: GraphQLJSON,
GUID: GraphQLGUID,
URL: GraphQLURL,
}

Enums

You can use enums to represent the data in any text column. If you are using PostgreSQL, however, you can use an enum for your column's type as well. Because PostgreSQL allows enum values to include characters which GraphQL prohibits like spaces and dashes, it's possible you'll need to map your GraphQL enum values to the ones used by your database. This should be done using the @value directive:

enum FilmRating {
G
PG
PG13 @value(is: "PG-13")
R
NC17 @value(is: "NC-17")
}