How to use graphile-build-pg - 10 common examples

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
);
      }

      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(
github graphile / graphile-engine / packages / postgraphile-core / src / index.ts View on Github external
},
};

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));
      },
    });
github graphile / graphile-engine / packages / postgraphile-core / src / index.ts View on Github external
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;
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;
}

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