graphile-build-pg
Version:
Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build
33 lines (29 loc) • 954 B
Flow
// @flow
import { LiveProvider } from "graphile-build";
import type { PgClass } from "./plugins/PgIntrospectionPlugin";
export default class PgLiveProvider extends LiveProvider {
// eslint-disable-next-line flowtype/no-weak-types
constructor(...args: any[]) {
super(...args);
this.namespace = "pg";
}
collectionIdentifierIsValid(collectionIdentifier: PgClass) {
return collectionIdentifier && collectionIdentifier.kind === "class";
}
recordIdentifierIsValid(
collectionIdentifier: PgClass,
// eslint-disable-next-line flowtype/no-weak-types
recordIdentifier: Array<any>
) {
if (!Array.isArray(recordIdentifier)) return false;
if (!collectionIdentifier.primaryKeyConstraint) return false;
if (
recordIdentifier.length !==
collectionIdentifier.primaryKeyConstraint.keyAttributes.length
) {
return false;
}
// TODO: more validation would not go amiss
return true;
}
}