Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fieldContext: ContextGraphQLObjectTypeFieldsField
): {
type: import("graphql").GraphQLOutputType;
args?: {};
deprecationReason?: string;
descroption?: string;
} => {
const { pgIntrospection } = fieldContext.scope;
// @requires directive: pulls down necessary columns from table.
//
// e.g. `@requires(columns: ["id", "name"])`
//
if (
directives.requires &&
pgIntrospection &&
pgIntrospection.kind === PgEntityKind.CLASS
) {
const table: PgClass = pgIntrospection;
if (Array.isArray(directives.requires.columns)) {
const attrs = table.attributes.filter(
attr => directives.requires.columns.indexOf(attr.name) >= 0
);
const fieldNames = attrs.map(attr =>
build.inflection.column(attr)
);
const ReturnTypes = attrs.map(
attr =>
build.pgGetGqlTypeByTypeIdAndModifier(
attr.typeId,
attr.typeModifier
) || build.graphql.GraphQLString
);
function process(
kind: PgEntityKind,
identifier: string,
subKind: PgEntityKind,
obj: unknown,
key: string,
deprecated = false
): void {
if (kind !== PgEntityKind.CLASS) {
throw new Error(
`makeJSONPgSmartTagsPlugin: '${key}' is only valid on a class; you tried to set it on a '${kind}' at 'config.${kind}.${identifier}.${key}'`
);
}
const path = `config.${kind}.${identifier}.${key}`;
if (deprecated) {
console.warn(
`Tags JSON path '${path}' is deprecated, please use 'config.${kind}.${identifier}.attribute' instead`
);
}
if (typeof obj !== "object" || obj == null) {
throw new Error(`Invalid value for '${path}'`);
}
const entities: object = obj;
for (const entityName of Object.keys(entities)) {
if (entityName.includes(".")) {
export function isClass(obj: PgEntity): obj is PgClass {
return obj.kind === PgEntityKind.CLASS;
}
kind: T["kind"];
match: PgSmartTagFilterFunction;
tags?: PgSmartTagTags;
description?: string;
}
export type PgSmartTagSupportedKinds =
| PgEntityKind.CLASS
| PgEntityKind.ATTRIBUTE
| PgEntityKind.CONSTRAINT
| PgEntityKind.PROCEDURE;
const meaningByKind: {
[kind in PgSmartTagSupportedKinds]: string;
} = {
[PgEntityKind.CLASS]:
"for tables, composite types, views and materialized views",
[PgEntityKind.ATTRIBUTE]: "for columns/attributes (of any 'class' type)",
[PgEntityKind.CONSTRAINT]: "for table constraints",
[PgEntityKind.PROCEDURE]: "for functions/procedures",
};
const validKinds = Object.entries(meaningByKind)
.map(([kind, meaning]) => `'${kind}' (${meaning})`)
.join(", ");
function compileRule(
rule: PgSmartTagRule
): CompiledPgSmartTagRule {
const { kind, match: incomingMatch, ...rest } = rule;
if (!Object.prototype.hasOwnProperty.call(meaningByKind, kind)) {
throw new Error(