0.0.1 • Published 10 months ago

@cran/lib.gql.jm v0.0.1

Weekly downloads
-
License
SEE LICENSE IN li...
Repository
-
Last release
10 months ago

@cran/lib.gql.jm

GraphQL JoinMonster Integration

Setup

import { Plugin, withCoreFeatures } from "@cran/lib.gql.core";
import { withJm } from "@cran/lib.gql.jm";

export const schema = Plugin.apply(Plugin.compose([
  // ORDER MATTERS
  { typeDefs: fs.readFileSync(`${__dirname}/schema.gql`, "utf-8"), },
  ...withCoreFeatures(),
  ...withJm(),
]));

Inflection

Want to rename things?

...withJm({
  inflection: {
    sqlTable: "MakeTable"
  }
});
type Table
@MakeTable
{ }

Example

For a more complete example see example in poc, this follows the join-monster documentation for data and schema structure.

Directives

Resolver

Note: This one is critical for functionality

sqlResolver on COMPOSITE_FIELD

type Query {
  accounts: [Account!]
  @sqlResolver
}

Table

sqlTable on COMPOSITE_TYPE

ParameterTypeDefaultDescription
nametexttype.nameTable Name
key[text!]["id"]Primary Key
fetch[text!]Always get these fields
type Type
@sqlTable(name: "table_name")
{ }

Column

on COMPOSITE_FIELD

ParameterTypeDefaultDescription
nametexttype.nameColumn Name
deps[text!]Dependencies
exprtextColumn Expression
wheretextWhere statement
ordertextOrder records by
limittextEnforced record limit
type Type
@sqlTable(name: "table_name")
{
  id
  @sqlColumn(name: "table_name_id")
}

Pagination

sqlPaginate on COMPOSITE_FIELD

ParameterTypeDefaultDescription
limittextinfinityMaximum page size
size[text!]Default page size
sorttextKeys to sort by
type Query {
  types: [Type!]
  @sqlPaginate(limit: 100, size: 20)
  @sqlResolver
}