Skip to content

V5 Docs: IdToNodeIdPlugin snippet has invalid syntax #2860

@jovanblazek

Description

@jovanblazek

Summary

https://postgraphile.org/postgraphile/5/node-id says:

You can create your plugin similar to the following:

const IdToNodeIdPlugin: GraphileConfig.Plugin = {
  name: "IdToNodeIdPlugin",
  version: "1.0.0",
  inflection: {
    replace: {
      nodeIdFieldName() {
        return "nodeId";
      },
      _attributeName(previous, options, details) {
        const attribute = codec.attributes[attributeName];
        const name = attribute.extensions?.tags?.name || attributeName;
        return this.coerceToGraphQLName(name);
      },
    },
  },
};

The snippet above is missing the following line in the _attributeName function body:
const { codec, attributeName } = details;
Without it the code is not valid.

Correct snippet

const IdToNodeIdPlugin: GraphileConfig.Plugin = {
  name: "IdToNodeIdPlugin",
  version: "1.0.0",
  inflection: {
    replace: {
      nodeIdFieldName() {
        return "nodeId";
      },
      _attributeName(previous, options, details) {
+       const { codec, attributeName } = details;
        const attribute = codec.attributes[attributeName];
        const name = attribute.extensions?.tags?.name || attributeName;
        return this.coerceToGraphQLName(name);
      },
    },
  },
};

Additional context

Sorry, I do not have time to add this to the docs myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🌳 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions