graphile-build-pg 4.13.0 → 4.14.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.
Files changed (106) hide show
  1. package/README.md +4 -13
  2. package/node8plus/GraphQLJSON.js +0 -11
  3. package/node8plus/GraphQLJSON.js.map +1 -1
  4. package/node8plus/PgLiveProvider.js +4 -11
  5. package/node8plus/PgLiveProvider.js.map +1 -1
  6. package/node8plus/QueryBuilder.js +42 -176
  7. package/node8plus/QueryBuilder.js.map +1 -1
  8. package/node8plus/index.js +8 -47
  9. package/node8plus/index.js.map +1 -1
  10. package/node8plus/inflections.js +9 -61
  11. package/node8plus/inflections.js.map +1 -1
  12. package/node8plus/omit.js +7 -22
  13. package/node8plus/omit.js.map +1 -1
  14. package/node8plus/parseIdentifier.js +0 -1
  15. package/node8plus/parseIdentifier.js.map +1 -1
  16. package/node8plus/pgPrepareAndRun.js +2 -14
  17. package/node8plus/pgPrepareAndRun.js.map +1 -1
  18. package/node8plus/plugins/PageInfoStartEndCursor.js +0 -4
  19. package/node8plus/plugins/PageInfoStartEndCursor.js.map +1 -1
  20. package/node8plus/plugins/PgAllRows.js +0 -29
  21. package/node8plus/plugins/PgAllRows.js.map +1 -1
  22. package/node8plus/plugins/PgBackwardRelationPlugin.js +2 -41
  23. package/node8plus/plugins/PgBackwardRelationPlugin.js.map +1 -1
  24. package/node8plus/plugins/PgBasicsPlugin.js +20 -147
  25. package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
  26. package/node8plus/plugins/PgColumnDeprecationPlugin.js +2 -5
  27. package/node8plus/plugins/PgColumnDeprecationPlugin.js.map +1 -1
  28. package/node8plus/plugins/PgColumnsPlugin.js +4 -17
  29. package/node8plus/plugins/PgColumnsPlugin.js.map +1 -1
  30. package/node8plus/plugins/PgComputedColumnsPlugin.js +4 -19
  31. package/node8plus/plugins/PgComputedColumnsPlugin.js.map +1 -1
  32. package/node8plus/plugins/PgConditionComputedColumnPlugin.js +12 -23
  33. package/node8plus/plugins/PgConditionComputedColumnPlugin.js.map +1 -1
  34. package/node8plus/plugins/PgConnectionArgCondition.js +1 -9
  35. package/node8plus/plugins/PgConnectionArgCondition.js.map +1 -1
  36. package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js +0 -12
  37. package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js.map +1 -1
  38. package/node8plus/plugins/PgConnectionArgOrderBy.js +2 -19
  39. package/node8plus/plugins/PgConnectionArgOrderBy.js.map +1 -1
  40. package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js +0 -6
  41. package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js.map +1 -1
  42. package/node8plus/plugins/PgConnectionTotalCount.js +0 -8
  43. package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
  44. package/node8plus/plugins/PgForwardRelationPlugin.js +2 -25
  45. package/node8plus/plugins/PgForwardRelationPlugin.js.map +1 -1
  46. package/node8plus/plugins/PgIntrospectionPlugin.js +91 -180
  47. package/node8plus/plugins/PgIntrospectionPlugin.js.flow +30 -2
  48. package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
  49. package/node8plus/plugins/PgJWTPlugin.js +2 -18
  50. package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
  51. package/node8plus/plugins/PgMutationCreatePlugin.js +0 -18
  52. package/node8plus/plugins/PgMutationCreatePlugin.js.map +1 -1
  53. package/node8plus/plugins/PgMutationPayloadEdgePlugin.js +4 -25
  54. package/node8plus/plugins/PgMutationPayloadEdgePlugin.js.map +1 -1
  55. package/node8plus/plugins/PgMutationProceduresPlugin.js +0 -6
  56. package/node8plus/plugins/PgMutationProceduresPlugin.js.map +1 -1
  57. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +14 -49
  58. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +5 -2
  59. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
  60. package/node8plus/plugins/PgNodeAliasPostGraphile.js +0 -6
  61. package/node8plus/plugins/PgNodeAliasPostGraphile.js.map +1 -1
  62. package/node8plus/plugins/PgOrderAllColumnsPlugin.js +0 -4
  63. package/node8plus/plugins/PgOrderAllColumnsPlugin.js.map +1 -1
  64. package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js +0 -6
  65. package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js.map +1 -1
  66. package/node8plus/plugins/PgOrderComputedColumnsPlugin.js +10 -14
  67. package/node8plus/plugins/PgOrderComputedColumnsPlugin.js.map +1 -1
  68. package/node8plus/plugins/PgQueryProceduresPlugin.js +4 -16
  69. package/node8plus/plugins/PgQueryProceduresPlugin.js.map +1 -1
  70. package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +3 -20
  71. package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
  72. package/node8plus/plugins/PgRecordReturnTypesPlugin.js +11 -16
  73. package/node8plus/plugins/PgRecordReturnTypesPlugin.js.map +1 -1
  74. package/node8plus/plugins/PgRowByUniqueConstraint.js +4 -25
  75. package/node8plus/plugins/PgRowByUniqueConstraint.js.map +1 -1
  76. package/node8plus/plugins/PgRowNode.js +0 -32
  77. package/node8plus/plugins/PgRowNode.js.map +1 -1
  78. package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +3 -17
  79. package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
  80. package/node8plus/plugins/PgTablesPlugin.js +7 -59
  81. package/node8plus/plugins/PgTablesPlugin.js.map +1 -1
  82. package/node8plus/plugins/PgTypesPlugin.js +140 -240
  83. package/node8plus/plugins/PgTypesPlugin.js.flow +76 -23
  84. package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
  85. package/node8plus/plugins/addStartEndCursor.js +2 -5
  86. package/node8plus/plugins/addStartEndCursor.js.map +1 -1
  87. package/node8plus/plugins/debugSql.js +1 -16
  88. package/node8plus/plugins/debugSql.js.map +1 -1
  89. package/node8plus/plugins/introspectionQuery.js +3 -4
  90. package/node8plus/plugins/introspectionQuery.js.flow +11 -3
  91. package/node8plus/plugins/introspectionQuery.js.map +1 -1
  92. package/node8plus/plugins/makeProcField.js +40 -90
  93. package/node8plus/plugins/makeProcField.js.map +1 -1
  94. package/node8plus/plugins/pgField.js +2 -7
  95. package/node8plus/plugins/pgField.js.map +1 -1
  96. package/node8plus/plugins/viaTemporaryTable.js +6 -12
  97. package/node8plus/plugins/viaTemporaryTable.js.map +1 -1
  98. package/node8plus/postgresInterval.js +4 -4
  99. package/node8plus/postgresInterval.js.map +1 -1
  100. package/node8plus/queryFromResolveDataFactory.js +33 -77
  101. package/node8plus/queryFromResolveDataFactory.js.map +1 -1
  102. package/node8plus/utils.js +8 -9
  103. package/node8plus/utils.js.map +1 -1
  104. package/node8plus/withPgClient.js +4 -26
  105. package/node8plus/withPgClient.js.map +1 -1
  106. package/package.json +4 -4
@@ -5,6 +5,8 @@ import makeGraphQLJSONType from "../GraphQLJSON";
5
5
 
6
6
  import { parseInterval } from "../postgresInterval";
7
7
 
8
+ const ENUM_DOMAIN_SUFFIX = "_enum_domain";
9
+
8
10
  function indent(str) {
9
11
  return " " + str.replace(/\n/g, "\n ");
10
12
  }
@@ -30,6 +32,7 @@ export default (function PgTypesPlugin(
30
32
  build => {
31
33
  const {
32
34
  pgIntrospectionResultsByKind: introspectionResultsByKind,
35
+ getPgFakeEnumIdentifier,
33
36
  getTypeByName,
34
37
  pgSql: sql,
35
38
  inflection,
@@ -753,6 +756,10 @@ export default (function PgTypesPlugin(
753
756
  gqlInputType;
754
757
  }
755
758
  }
759
+
760
+ // cf https://github.com/graphile/graphile-engine/pull/748#discussion_r650828353
761
+ let shouldSkipAddType = false;
762
+
756
763
  // Enums
757
764
  if (
758
765
  !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&
@@ -994,30 +1001,72 @@ end`;
994
1001
  type.type === "d" &&
995
1002
  type.domainBaseTypeId
996
1003
  ) {
997
- const baseType = getGqlTypeByTypeIdAndModifier(
998
- type.domainBaseTypeId,
999
- typeModifier
1000
- );
1001
- const baseInputType = getGqlInputTypeByTypeIdAndModifier(
1002
- type.domainBaseTypeId,
1003
- typeModifier
1004
- );
1005
- // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16
1006
- gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Object.assign(
1007
- Object.create(baseType),
1008
- {
1009
- name: inflection.domainType(type),
1010
- description: type.description,
1004
+ // might be used as an enum alias: https://github.com/graphile/postgraphile/issues/1500
1005
+ const tagEnumName =
1006
+ type.tags && typeof type.tags.enum === "string"
1007
+ ? type.tags.enum
1008
+ : null;
1009
+ const truncatedTypeName =
1010
+ !tagEnumName && type.name.endsWith(ENUM_DOMAIN_SUFFIX)
1011
+ ? type.name.slice(0, type.name.length - ENUM_DOMAIN_SUFFIX.length)
1012
+ : null;
1013
+ const underlyingEnumTypeName = tagEnumName || truncatedTypeName;
1014
+ if (underlyingEnumTypeName !== null) {
1015
+ const baseTypeId = getPgFakeEnumIdentifier(
1016
+ type.namespaceName,
1017
+ underlyingEnumTypeName
1018
+ );
1019
+
1020
+ const baseType = getGqlTypeByTypeIdAndModifier(
1021
+ baseTypeId,
1022
+ typeModifierKey
1023
+ );
1024
+
1025
+ const baseInputType = getGqlInputTypeByTypeIdAndModifier(
1026
+ baseTypeId,
1027
+ typeModifierKey
1028
+ );
1029
+
1030
+ if (!baseType || !baseInputType) {
1031
+ if (tagEnumName) {
1032
+ throw new Error(
1033
+ `The domain ${type.name} uses '@enum ${tagEnumName}' to references its underlying enum type, but no type named ${tagEnumName} could be found.`
1034
+ );
1035
+ } else {
1036
+ throw new Error(
1037
+ `The domain ${type.name} references the enum type ${underlyingEnumTypeName}, but no such type could be found.`
1038
+ );
1039
+ }
1011
1040
  }
1012
- );
1013
- if (baseInputType && baseInputType !== baseType) {
1041
+
1042
+ gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = baseType;
1014
1043
  gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] =
1015
- Object.assign(Object.create(baseInputType), {
1016
- name: inflection.inputType(
1017
- gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]
1018
- ),
1044
+ baseInputType;
1045
+ shouldSkipAddType = true;
1046
+ } else {
1047
+ const baseType = getGqlTypeByTypeIdAndModifier(
1048
+ type.domainBaseTypeId,
1049
+ typeModifier
1050
+ );
1051
+ const baseInputType = getGqlInputTypeByTypeIdAndModifier(
1052
+ type.domainBaseTypeId,
1053
+ typeModifier
1054
+ );
1055
+ // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16
1056
+ gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] =
1057
+ Object.assign(Object.create(baseType), {
1058
+ name: inflection.domainType(type),
1019
1059
  description: type.description,
1020
1060
  });
1061
+ if (baseInputType && baseInputType !== baseType) {
1062
+ gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] =
1063
+ Object.assign(Object.create(baseInputType), {
1064
+ name: inflection.inputType(
1065
+ gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]
1066
+ ),
1067
+ description: type.description,
1068
+ });
1069
+ }
1021
1070
  }
1022
1071
  }
1023
1072
 
@@ -1076,9 +1125,13 @@ end`;
1076
1125
  gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];
1077
1126
  }
1078
1127
  }
1079
- addType(
1080
- getNamedType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])
1081
- );
1128
+ // if its a domain type substituting for an enum table,
1129
+ // adding it creates a duplicate
1130
+ if (!shouldSkipAddType) {
1131
+ addType(
1132
+ getNamedType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])
1133
+ );
1134
+ }
1082
1135
  return gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];
1083
1136
  };
1084
1137