Closed marshall007 closed 5 years ago
Here's a starting point; maybe you'd like to tidy it up, add tests, and turn it into a PR?
module.exports = builder => {
builder.hook("GraphQLObjectType:fields:field", (field, build, context) => {
const {
scope: { pgFieldIntrospection }
} = context;
if (!pgFieldIntrospection || pgFieldIntrospection.kind !== "attribute") {
return field;
}
const attribute = pgFieldIntrospection;
const table = pgFieldIntrospection.class;
if (!table) {
return field;
}
const attributeIsInPrimaryKey =
table.primaryKeyConstraint && table.primaryKeyConstraint.keyAttributes.indexOf(attribute) >= 0;
const attributeIsInForeignKeys = table.constraints.some(constraint => {
if (constraint.type === "f") {
return constraint.keyAttributes.indexOf(attribute) >= 0;
}
return false;
});
if (!attributeIsInPrimaryKey && !attributeIsInForeignKeys) {
return field;
}
return {
...field,
deprecationReason: "fish"
};
});
};
Would be nice if the plugin could be configured to automatically add
@deprecated
tags to non-NodeID foreign key properties in the generated schema. For example, given atext
columnposts.created_by
with a FK tousers.username
:This would be useful for steering consistent usage across front-end developers/clients.