How to use the graphile-build-pg.PgEntityKind.CLASS function in graphile-build-pg

To help you get started, we’ve selected a few graphile-build-pg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphile / graphile-engine / packages / graphile-utils / src / makeExtendSchemaPlugin.ts View on Github external
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
                );
github graphile / graphile-engine / packages / graphile-utils / src / makePgSmartTagsPlugin.ts View on Github external
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(".")) {
github graphile / graphile-engine / packages / graphile-utils / src / introspectionHelpers.ts View on Github external
export function isClass(obj: PgEntity): obj is PgClass {
  return obj.kind === PgEntityKind.CLASS;
}
github graphile / graphile-engine / packages / graphile-utils / src / makePgSmartTagsPlugin.ts View on Github external
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(

graphile-build-pg

Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis