graphile/crystal

How to omit a class and specific field

Closed this issue · 3 comments

Summary

In previous v4 implementation, we used smartTagPlugin to "remove/hide" some class and fields, but omit looks like been deprecated in V5, and the plugin isn't make any changes.

// Plugin in v4
export const smartTagsPlugin = makePgSmartTagsPlugin([
    // Set _id as the primary key for all entity expect _metadata
    {
      kind: "class",
      // match: '_metadata',
      match(entity) {
        const klass = entity as PgClass;
        return (
            METADATA_REGEX.test(klass.relname)
        );
      },
      tags: {
        omit: true,
      },
    },
  // Omit _block_range column
  {
    kind: "attribute",
    match(entity) {
      const attribute = entity as PgAttribute;
      return (
          /^_block_range$/.test(attribute.attname)
      );
    },
    tags: {
      omit: true,
    },
    description: 'Omit _block_range column from the node'
  },
  // Omit _id column
  {
    kind: "attribute",
    match(entity) {
      const attribute = entity as PgAttribute;
      return (
          /^_id$/.test(attribute.attname)
      );
    },
    tags: {
      omit: true,
    },
    description: 'Omit _id column from the node'
  },
])

And how to convert this to use entityBehaviors? write a custom plugin will be the right approach? Thanks

Additional context

Current preset:

export const preset: GraphileConfig.Preset = {
  extends: [PostGraphileAmberPreset, PgSimplifyInflectionPreset],
  gather: { pgFakeConstraintsAutofixForeignKeyUniqueness: true },
  grafserv: { port: DEFAULT_PORT },
  pgServices: [makePgService({
    connectionString: pgConnection,
    schemas: pgSchema,
  })],
  schema: {
    defaultBehavior: "-connection +list -insert -update -delete",
    pgOmitListSuffix: true
  },
  plugins: [smartTagsPlugin],
  // disablePlugins: [""]
};

image

Are you using the V4 preset? omit is only implemented in that preset.

If not, you can use behavior instead of omit. See https://postgraphile.org/postgraphile/next/behavior and https://postgraphile.org/postgraphile/next/migrating-from-v4/#smart-tag-changes

[semi-automated message] To keep things manageable I'm going to close this issue as I think it's solved; but if not or you require further help please re-open it.

Thanks, looks this works

 tags: {
        behavior: "-*",
      },