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
);
);
}
rules.push({
kind,
match: identifier,
tags,
description,
});
if (columns) {
// This was in graphile-utils 4.0.0 but was deprecated in 4.0.1 for consistency reasons.
process(
kind,
identifier,
PgEntityKind.ATTRIBUTE,
columns,
"columns",
true
);
}
if (attribute) {
process(
kind,
identifier,
PgEntityKind.ATTRIBUTE,
attribute,
"attribute"
);
}
if (constraint) {
process(
},
};
export const postGraphileClassicIdsOverrides = {
column(name: string, _table: string, _schema?: string) {
return name === "id" ? "rowId" : inflections.defaultUtils.camelCase(name);
},
};
export const postGraphileInflection = inflections.newInflector(
// @ts-ignore
postGraphileBaseOverrides
);
// @ts-ignore
export const postGraphileClassicIdsInflection = inflections.newInflector({
...postGraphileBaseOverrides,
...postGraphileClassicIdsOverrides,
});
/*
* ABOVE HERE IS DEPRECATED.
*/
export const PostGraphileInflectionPlugin = function(builder: SchemaBuilder) {
builder.hook("inflection", (inflection: Inflection) => {
const previous = inflection.enumName;
// Overwrite directly so that we don't lose the 'extend' hints
Object.assign(inflection, {
enumName(value: string) {
return this.constantCase(previous.call(this, value));
},
});
export const postGraphileBaseOverrides = {
enumName(value: string) {
return inflections.defaultUtils.constantCase(
inflections.defaultInflection.enumName(value)
);
},
};
export const postGraphileClassicIdsOverrides = {
column(name: string, _table: string, _schema?: string) {
return name === "id" ? "rowId" : inflections.defaultUtils.camelCase(name);
},
};
export const postGraphileInflection = inflections.newInflector(
// @ts-ignore
postGraphileBaseOverrides
);
// @ts-ignore
export const postGraphileClassicIdsInflection = inflections.newInflector({
...postGraphileBaseOverrides,
...postGraphileClassicIdsOverrides,
});
/*
* ABOVE HERE IS DEPRECATED.
*/
export const PostGraphileInflectionPlugin = function(builder: SchemaBuilder) {
builder.hook("inflection", (inflection: Inflection) => {
const previous = inflection.enumName;
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(".")) {
.filter(attr => !omit(attr, 'filter'));
.filter(proc => !omit(proc, 'filter'));
.filter(attr => !omit(attr, 'order'))
.reduce((memo, attr) => {
.filter(proc => !omit(proc, 'order'));
export function isClass(obj: PgEntity): obj is PgClass {
return obj.kind === PgEntityKind.CLASS;
}