Alexander I.
Alexander I.

Reputation: 2714

PostGraphile NodeId identifiers for composite PrimaryKey

We implemented a Postgraphile mutation plugin using method makeExtendSchemaPlugin.

In our plugin we use NodeId and we parse this NodeId using method getTypeAndIdentifiersFromNodeId. This method returns GraphQL Type and collection of Identifiers.

If our type has only one PrimaryKey column then we don't have any issues. We use only first element of Identifiers collection. And we can generate our SQL script without any troubles.

If we have composite PrimaryKey then Identifiers collection has multiple elements (as expected).

  1. What order have elements for Identifiers collection?
  2. Is there a correct way to define correct order (or names) of Identifiers elements for generation correct SQL query?

Will be grateful for any help/suggestions.

Upvotes: 0

Views: 88

Answers (1)

Benjie
Benjie

Reputation: 7946

The order of the identifiers is the same as the order of the columns in the primary key constraint in the table; for example:

create table attendance (
  module_id int not null,
  student_id int not null,
  primary key (student_id, module_id)
);

In this case the order of identifiers would be: student_id, module_id.

You can determine the names of the identifiers by looking at the associated columns in the primary key constraint.

Upvotes: 2

Related Questions