graphile-settings 4.17.1 → 4.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,9 @@ function createMetaSchemaType() {
25
25
  type: { type: nn(MetaTypeType) },
26
26
  isNotNull: { type: nn(GraphQLBoolean) },
27
27
  hasDefault: { type: nn(GraphQLBoolean) },
28
+ isPrimaryKey: { type: nn(GraphQLBoolean) },
29
+ isForeignKey: { type: nn(GraphQLBoolean) },
30
+ description: { type: GraphQLString },
28
31
  }),
29
32
  });
30
33
  const MetaIndexType = new GraphQLObjectType({
@@ -9,7 +9,25 @@ function buildTableMeta(resource, schemaName, context) {
9
9
  const attributes = codec.attributes;
10
10
  const uniques = getUniques(resource);
11
11
  const relations = getRelations(resource);
12
- const fields = Object.entries(attributes).map(([attrName, attr]) => buildFieldMeta(context.inflectAttr(attrName, codec), attr, context.build));
12
+ // Compute PK and FK attribute name sets for field metadata
13
+ const pkAttrNames = new Set();
14
+ const fkAttrNames = new Set();
15
+ for (const unique of uniques) {
16
+ if (unique.isPrimary) {
17
+ for (const attrName of unique.attributes)
18
+ pkAttrNames.add(attrName);
19
+ }
20
+ }
21
+ for (const relation of Object.values(relations)) {
22
+ if (relation.isReferencee !== false)
23
+ continue;
24
+ for (const attrName of relation.localAttributes || [])
25
+ fkAttrNames.add(attrName);
26
+ }
27
+ const fields = Object.entries(attributes).map(([attrName, attr]) => buildFieldMeta(context.inflectAttr(attrName, codec), attr, context.build, {
28
+ isPrimaryKey: pkAttrNames.has(attrName),
29
+ isForeignKey: fkAttrNames.has(attrName),
30
+ }));
13
31
  const indexes = buildIndexes(codec, attributes, uniques, context);
14
32
  const primaryKey = buildPrimaryKey(codec, attributes, uniques, context);
15
33
  const uniqueConstraints = buildUniqueConstraints(codec, attributes, uniques, context);
@@ -1,3 +1,7 @@
1
1
  import type { FieldMeta, GqlTypeResolverBuild, PgAttribute } from './types';
2
2
  export declare function pgTypeToGqlType(pgTypeName: string): string;
3
- export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild): FieldMeta;
3
+ export interface BuildFieldMetaOptions {
4
+ isPrimaryKey?: boolean;
5
+ isForeignKey?: boolean;
6
+ }
7
+ export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild, options?: BuildFieldMetaOptions): FieldMeta;
@@ -56,7 +56,7 @@ function resolveGqlTypeName(build, codec) {
56
56
  const nestedTypeName = codec.arrayOfCodec?.name;
57
57
  return nestedTypeName ? pgTypeToGqlType(nestedTypeName) : pgTypeName;
58
58
  }
59
- export function buildFieldMeta(name, attr, build) {
59
+ export function buildFieldMeta(name, attr, build, options) {
60
60
  const pgType = attr?.codec?.name || 'unknown';
61
61
  const isNotNull = attr?.notNull || false;
62
62
  const hasDefault = attr?.hasDefault || false;
@@ -71,5 +71,8 @@ export function buildFieldMeta(name, attr, build) {
71
71
  },
72
72
  isNotNull,
73
73
  hasDefault,
74
+ isPrimaryKey: options?.isPrimaryKey ?? false,
75
+ isForeignKey: options?.isForeignKey ?? false,
76
+ description: attr?.description ?? null,
74
77
  };
75
78
  }
@@ -16,6 +16,9 @@ export interface FieldMeta {
16
16
  type: TypeMeta;
17
17
  isNotNull: boolean;
18
18
  hasDefault: boolean;
19
+ isPrimaryKey: boolean;
20
+ isForeignKey: boolean;
21
+ description: string | null;
19
22
  }
20
23
  export interface TypeMeta {
21
24
  pgType: string;
@@ -131,6 +134,7 @@ export interface PgAttribute {
131
134
  codec?: PgCodec | null;
132
135
  notNull?: boolean;
133
136
  hasDefault?: boolean;
137
+ description?: string | null;
134
138
  }
135
139
  export interface PgUnique {
136
140
  attributes: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-settings",
3
- "version": "4.17.1",
3
+ "version": "4.18.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "graphile settings",
6
6
  "main": "index.js",
@@ -29,48 +29,48 @@
29
29
  "test:watch": "jest --watch"
30
30
  },
31
31
  "dependencies": {
32
- "@constructive-io/graphql-env": "^3.5.1",
33
- "@constructive-io/graphql-types": "^3.4.1",
34
- "@constructive-io/s3-streamer": "^2.17.1",
35
- "@constructive-io/upload-names": "^2.10.1",
36
- "@dataplan/json": "1.0.0-rc.6",
37
- "@dataplan/pg": "1.0.0-rc.8",
32
+ "@constructive-io/graphql-env": "^3.5.2",
33
+ "@constructive-io/graphql-types": "^3.4.2",
34
+ "@constructive-io/s3-streamer": "^2.17.2",
35
+ "@constructive-io/upload-names": "^2.10.2",
36
+ "@dataplan/json": "1.0.0",
37
+ "@dataplan/pg": "1.0.0",
38
38
  "@graphile-contrib/pg-many-to-many": "2.0.0-rc.2",
39
- "@pgpmjs/logger": "^2.5.1",
40
- "@pgpmjs/types": "^2.20.1",
39
+ "@pgpmjs/logger": "^2.5.2",
40
+ "@pgpmjs/types": "^2.20.2",
41
41
  "@pgsql/quotes": "^17.1.0",
42
42
  "cors": "^2.8.6",
43
43
  "express": "^5.2.1",
44
- "grafast": "1.0.0-rc.9",
45
- "grafserv": "1.0.0-rc.7",
46
- "graphile-build": "5.0.0-rc.6",
47
- "graphile-build-pg": "5.0.0-rc.8",
48
- "graphile-config": "1.0.0-rc.6",
49
- "graphile-connection-filter": "^1.3.2",
50
- "graphile-postgis": "^2.9.2",
51
- "graphile-search": "^1.5.2",
52
- "graphile-sql-expression-validator": "^2.6.1",
53
- "graphile-upload-plugin": "^2.5.1",
54
- "graphile-utils": "5.0.0-rc.8",
44
+ "grafast": "1.0.0",
45
+ "grafserv": "1.0.0",
46
+ "graphile-build": "5.0.0",
47
+ "graphile-build-pg": "5.0.0",
48
+ "graphile-config": "1.0.0",
49
+ "graphile-connection-filter": "^1.3.4",
50
+ "graphile-postgis": "^2.9.4",
51
+ "graphile-search": "^1.5.4",
52
+ "graphile-sql-expression-validator": "^2.6.2",
53
+ "graphile-upload-plugin": "^2.5.2",
54
+ "graphile-utils": "5.0.0",
55
55
  "graphql": "16.13.0",
56
56
  "inflekt": "^0.6.0",
57
57
  "lru-cache": "^11.2.7",
58
58
  "pg": "^8.20.0",
59
- "pg-query-context": "^2.9.1",
60
- "pg-sql2": "5.0.0-rc.5",
61
- "postgraphile": "5.0.0-rc.10",
59
+ "pg-query-context": "^2.9.2",
60
+ "pg-sql2": "5.0.0",
61
+ "postgraphile": "5.0.0",
62
62
  "request-ip": "^3.3.0",
63
- "tamedevil": "0.1.0-rc.6"
63
+ "tamedevil": "0.1.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/cors": "^2.8.17",
67
67
  "@types/express": "^5.0.6",
68
68
  "@types/pg": "^8.18.0",
69
69
  "@types/request-ip": "^0.0.41",
70
- "graphile-test": "^4.7.2",
71
- "makage": "^0.1.10",
70
+ "graphile-test": "^4.7.4",
71
+ "makage": "^0.3.0",
72
72
  "nodemon": "^3.1.14",
73
- "pgsql-test": "^4.7.2",
73
+ "pgsql-test": "^4.7.4",
74
74
  "ts-node": "^10.9.2"
75
75
  },
76
76
  "keywords": [
@@ -80,5 +80,5 @@
80
80
  "constructive",
81
81
  "graphql"
82
82
  ],
83
- "gitHead": "93deca687ce109bf90d2a0a73ea6b05b22724160"
83
+ "gitHead": "2f6e083d11764a04b2a6bc14df5b2ca2725defc6"
84
84
  }
@@ -28,6 +28,9 @@ function createMetaSchemaType() {
28
28
  type: { type: nn(MetaTypeType) },
29
29
  isNotNull: { type: nn(graphql_1.GraphQLBoolean) },
30
30
  hasDefault: { type: nn(graphql_1.GraphQLBoolean) },
31
+ isPrimaryKey: { type: nn(graphql_1.GraphQLBoolean) },
32
+ isForeignKey: { type: nn(graphql_1.GraphQLBoolean) },
33
+ description: { type: graphql_1.GraphQLString },
31
34
  }),
32
35
  });
33
36
  const MetaIndexType = new graphql_1.GraphQLObjectType({
@@ -12,7 +12,25 @@ function buildTableMeta(resource, schemaName, context) {
12
12
  const attributes = codec.attributes;
13
13
  const uniques = (0, table_resource_utils_1.getUniques)(resource);
14
14
  const relations = (0, table_resource_utils_1.getRelations)(resource);
15
- const fields = Object.entries(attributes).map(([attrName, attr]) => (0, type_mappings_1.buildFieldMeta)(context.inflectAttr(attrName, codec), attr, context.build));
15
+ // Compute PK and FK attribute name sets for field metadata
16
+ const pkAttrNames = new Set();
17
+ const fkAttrNames = new Set();
18
+ for (const unique of uniques) {
19
+ if (unique.isPrimary) {
20
+ for (const attrName of unique.attributes)
21
+ pkAttrNames.add(attrName);
22
+ }
23
+ }
24
+ for (const relation of Object.values(relations)) {
25
+ if (relation.isReferencee !== false)
26
+ continue;
27
+ for (const attrName of relation.localAttributes || [])
28
+ fkAttrNames.add(attrName);
29
+ }
30
+ const fields = Object.entries(attributes).map(([attrName, attr]) => (0, type_mappings_1.buildFieldMeta)(context.inflectAttr(attrName, codec), attr, context.build, {
31
+ isPrimaryKey: pkAttrNames.has(attrName),
32
+ isForeignKey: fkAttrNames.has(attrName),
33
+ }));
16
34
  const indexes = (0, constraint_meta_builders_1.buildIndexes)(codec, attributes, uniques, context);
17
35
  const primaryKey = (0, constraint_meta_builders_1.buildPrimaryKey)(codec, attributes, uniques, context);
18
36
  const uniqueConstraints = (0, constraint_meta_builders_1.buildUniqueConstraints)(codec, attributes, uniques, context);
@@ -1,3 +1,7 @@
1
1
  import type { FieldMeta, GqlTypeResolverBuild, PgAttribute } from './types';
2
2
  export declare function pgTypeToGqlType(pgTypeName: string): string;
3
- export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild): FieldMeta;
3
+ export interface BuildFieldMetaOptions {
4
+ isPrimaryKey?: boolean;
5
+ isForeignKey?: boolean;
6
+ }
7
+ export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild, options?: BuildFieldMetaOptions): FieldMeta;
@@ -60,7 +60,7 @@ function resolveGqlTypeName(build, codec) {
60
60
  const nestedTypeName = codec.arrayOfCodec?.name;
61
61
  return nestedTypeName ? pgTypeToGqlType(nestedTypeName) : pgTypeName;
62
62
  }
63
- function buildFieldMeta(name, attr, build) {
63
+ function buildFieldMeta(name, attr, build, options) {
64
64
  const pgType = attr?.codec?.name || 'unknown';
65
65
  const isNotNull = attr?.notNull || false;
66
66
  const hasDefault = attr?.hasDefault || false;
@@ -75,5 +75,8 @@ function buildFieldMeta(name, attr, build) {
75
75
  },
76
76
  isNotNull,
77
77
  hasDefault,
78
+ isPrimaryKey: options?.isPrimaryKey ?? false,
79
+ isForeignKey: options?.isForeignKey ?? false,
80
+ description: attr?.description ?? null,
78
81
  };
79
82
  }
@@ -16,6 +16,9 @@ export interface FieldMeta {
16
16
  type: TypeMeta;
17
17
  isNotNull: boolean;
18
18
  hasDefault: boolean;
19
+ isPrimaryKey: boolean;
20
+ isForeignKey: boolean;
21
+ description: string | null;
19
22
  }
20
23
  export interface TypeMeta {
21
24
  pgType: string;
@@ -131,6 +134,7 @@ export interface PgAttribute {
131
134
  codec?: PgCodec | null;
132
135
  notNull?: boolean;
133
136
  hasDefault?: boolean;
137
+ description?: string | null;
134
138
  }
135
139
  export interface PgUnique {
136
140
  attributes: string[];