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
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getComputedColumnDetails = exports.default = void 0;
7
-
8
7
  const getComputedColumnDetails = (build, table, proc) => {
9
8
  if (!proc.isStable) return null;
10
9
  if (proc.namespaceId !== table.namespaceId) return null;
@@ -12,30 +11,27 @@ const getComputedColumnDetails = (build, table, proc) => {
12
11
  if (proc.argTypeIds.length < 1) return null;
13
12
  if (proc.argTypeIds[0] !== table.type.id) return null;
14
13
  const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {
15
- if (proc.argModes.length === 0 || // all args are `in`
16
- proc.argModes[idx] === "i" || // this arg is `in`
14
+ if (proc.argModes.length === 0 ||
15
+ // all args are `in`
16
+ proc.argModes[idx] === "i" ||
17
+ // this arg is `in`
17
18
  proc.argModes[idx] === "b" // this arg is `inout`
18
19
  ) {
19
20
  prev.push(build.pgIntrospectionResultsByKind.typeById[typeId]);
20
21
  }
21
-
22
22
  return prev;
23
23
  }, []);
24
-
25
24
  if (argTypes.slice(1).some(type => type.type === "c" && type.class && type.class.isSelectable)) {
26
25
  // Accepts two input tables? Skip.
27
26
  return null;
28
27
  }
29
-
30
28
  const pseudoColumnName = proc.name.slice(table.name.length + 1);
31
29
  return {
32
30
  argTypes,
33
31
  pseudoColumnName
34
32
  };
35
33
  };
36
-
37
34
  exports.getComputedColumnDetails = getComputedColumnDetails;
38
-
39
35
  var PgComputedColumnsPlugin = function PgComputedColumnsPlugin(builder, {
40
36
  pgSimpleCollections
41
37
  }) {
@@ -50,11 +46,9 @@ var PgComputedColumnsPlugin = function PgComputedColumnsPlugin(builder, {
50
46
  fieldWithHooks,
51
47
  Self
52
48
  } = context;
53
-
54
49
  if (isInputType || !(isPgRowType || isPgCompoundType) || !table || table.kind !== "class" || !table.namespace) {
55
50
  return fields;
56
51
  }
57
-
58
52
  const {
59
53
  extend,
60
54
  pgIntrospectionResultsByKind: introspectionResultsByKind,
@@ -66,11 +60,9 @@ var PgComputedColumnsPlugin = function PgComputedColumnsPlugin(builder, {
66
60
  sqlCommentByAddingTags
67
61
  } = build;
68
62
  const tableType = table.type;
69
-
70
63
  if (!tableType) {
71
64
  throw new Error("Could not determine the type for this table");
72
65
  }
73
-
74
66
  return extend(fields, introspectionResultsByKind.procedure.reduce((memo, proc) => {
75
67
  if (omit(proc, "execute")) return memo;
76
68
  const computedColumnDetails = getComputedColumnDetails(build, table, proc);
@@ -78,10 +70,8 @@ var PgComputedColumnsPlugin = function PgComputedColumnsPlugin(builder, {
78
70
  const {
79
71
  pseudoColumnName
80
72
  } = computedColumnDetails;
81
-
82
73
  function makeField(forceList) {
83
74
  const fieldName = forceList ? inflection.computedColumnList(pseudoColumnName, proc, table) : inflection.computedColumn(pseudoColumnName, proc, table);
84
-
85
75
  try {
86
76
  memo = extend(memo, {
87
77
  [fieldName]: makeProcField(fieldName, proc, build, {
@@ -96,23 +86,18 @@ var PgComputedColumnsPlugin = function PgComputedColumnsPlugin(builder, {
96
86
  swallowError(e);
97
87
  }
98
88
  }
99
-
100
89
  const simpleCollections = proc.tags.simpleCollections || pgSimpleCollections;
101
90
  const hasConnections = simpleCollections !== "only";
102
91
  const hasSimpleCollections = simpleCollections === "only" || simpleCollections === "both";
103
-
104
92
  if (!proc.returnsSet || hasConnections) {
105
93
  makeField(false);
106
94
  }
107
-
108
95
  if (proc.returnsSet && hasSimpleCollections) {
109
96
  makeField(true);
110
97
  }
111
-
112
98
  return memo;
113
99
  }, {}), `Adding computed column to '${Self.name}'`);
114
100
  }, ["PgComputedColumns"]);
115
101
  };
116
-
117
102
  exports.default = PgComputedColumnsPlugin;
118
103
  //# sourceMappingURL=PgComputedColumnsPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgComputedColumnsPlugin.js"],"names":["getComputedColumnDetails","build","table","proc","isStable","namespaceId","name","startsWith","argTypeIds","length","type","id","argTypes","reduce","prev","typeId","idx","argModes","push","pgIntrospectionResultsByKind","typeById","slice","some","class","isSelectable","pseudoColumnName","PgComputedColumnsPlugin","builder","pgSimpleCollections","hook","fields","context","scope","isPgRowType","isPgCompoundType","isInputType","pgIntrospection","fieldWithHooks","Self","kind","namespace","extend","introspectionResultsByKind","inflection","pgOmit","omit","pgMakeProcField","makeProcField","swallowError","describePgEntity","sqlCommentByAddingTags","tableType","Error","procedure","memo","computedColumnDetails","makeField","forceList","fieldName","computedColumnList","computedColumn","computed","e","simpleCollections","tags","hasConnections","hasSimpleCollections","returnsSet"],"mappings":";;;;;;;AAIO,MAAMA,wBAAwB,GAAG,CACtCC,KADsC,EAEtCC,KAFsC,EAGtCC,IAHsC,KAInC;AACH,MAAI,CAACA,IAAI,CAACC,QAAV,EAAoB,OAAO,IAAP;AACpB,MAAID,IAAI,CAACE,WAAL,KAAqBH,KAAK,CAACG,WAA/B,EAA4C,OAAO,IAAP;AAC5C,MAAI,CAACF,IAAI,CAACG,IAAL,CAAUC,UAAV,CAAsB,GAAEL,KAAK,CAACI,IAAK,GAAnC,CAAL,EAA6C,OAAO,IAAP;AAC7C,MAAIH,IAAI,CAACK,UAAL,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PgProc } from \"./PgIntrospectionPlugin\";\n\nexport const getComputedColumnDetails = (\n build: Build,\n table: PgClass,\n proc: PgProc\n) => {\n if (!proc.isStable) return null;\n if (proc.namespaceId !== table.namespaceId) return null;\n if (!proc.name.startsWith(`${table.name}_`)) return null;\n if (proc.argTypeIds.length < 1) return null;\n if (proc.argTypeIds[0] !== table.type.id) return null;\n\n const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (\n proc.argModes.length === 0 || // all args are `in`\n proc.argModes[idx] === \"i\" || // this arg is `in`\n proc.argModes[idx] === \"b\" // this arg is `inout`\n ) {\n prev.push(build.pgIntrospectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n if (\n argTypes\n .slice(1)\n .some(type => type.type === \"c\" && type.class && type.class.isSelectable)\n ) {\n // Accepts two input tables? Skip.\n return null;\n }\n\n const pseudoColumnName = proc.name.slice(table.name.length + 1);\n return { argTypes, pseudoColumnName };\n};\n\nexport default (function PgComputedColumnsPlugin(\n builder,\n { pgSimpleCollections }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n scope: {\n isPgRowType,\n isPgCompoundType,\n isInputType,\n pgIntrospection: table,\n },\n fieldWithHooks,\n Self,\n } = context;\n\n if (\n isInputType ||\n !(isPgRowType || isPgCompoundType) ||\n !table ||\n table.kind !== \"class\" ||\n !table.namespace\n ) {\n return fields;\n }\n\n const {\n extend,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n inflection,\n pgOmit: omit,\n pgMakeProcField: makeProcField,\n swallowError,\n describePgEntity,\n sqlCommentByAddingTags,\n } = build;\n const tableType = table.type;\n if (!tableType) {\n throw new Error(\"Could not determine the type for this table\");\n }\n return extend(\n fields,\n introspectionResultsByKind.procedure.reduce((memo, proc) => {\n if (omit(proc, \"execute\")) return memo;\n const computedColumnDetails = getComputedColumnDetails(\n build,\n table,\n proc\n );\n if (!computedColumnDetails) return memo;\n const { pseudoColumnName } = computedColumnDetails;\n function makeField(forceList) {\n const fieldName = forceList\n ? inflection.computedColumnList(pseudoColumnName, proc, table)\n : inflection.computedColumn(pseudoColumnName, proc, table);\n try {\n memo = extend(\n memo,\n {\n [fieldName]: makeProcField(fieldName, proc, build, {\n fieldWithHooks,\n computed: true,\n forceList,\n }),\n },\n `Adding computed column for ${describePgEntity(\n proc\n )}. You can rename this field with a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n fieldName: \"newNameHere\",\n }\n )}`\n );\n } catch (e) {\n swallowError(e);\n }\n }\n const simpleCollections =\n proc.tags.simpleCollections || pgSimpleCollections;\n const hasConnections = simpleCollections !== \"only\";\n const hasSimpleCollections =\n simpleCollections === \"only\" || simpleCollections === \"both\";\n if (!proc.returnsSet || hasConnections) {\n makeField(false);\n }\n if (proc.returnsSet && hasSimpleCollections) {\n makeField(true);\n }\n return memo;\n }, {}),\n `Adding computed column to '${Self.name}'`\n );\n },\n [\"PgComputedColumns\"]\n );\n}: Plugin);\n"],"file":"PgComputedColumnsPlugin.js"}
1
+ {"version":3,"file":"PgComputedColumnsPlugin.js","names":["getComputedColumnDetails","build","table","proc","isStable","namespaceId","name","startsWith","argTypeIds","length","type","id","argTypes","reduce","prev","typeId","idx","argModes","push","pgIntrospectionResultsByKind","typeById","slice","some","class","isSelectable","pseudoColumnName","exports","PgComputedColumnsPlugin","builder","pgSimpleCollections","hook","fields","context","scope","isPgRowType","isPgCompoundType","isInputType","pgIntrospection","fieldWithHooks","Self","kind","namespace","extend","introspectionResultsByKind","inflection","pgOmit","omit","pgMakeProcField","makeProcField","swallowError","describePgEntity","sqlCommentByAddingTags","tableType","Error","procedure","memo","computedColumnDetails","makeField","forceList","fieldName","computedColumnList","computedColumn","computed","e","simpleCollections","tags","hasConnections","hasSimpleCollections","returnsSet","default"],"sources":["../../src/plugins/PgComputedColumnsPlugin.js"],"sourcesContent":["// @flow\nimport type { Plugin, Build } from \"graphile-build\";\nimport type { PgClass, PgProc } from \"./PgIntrospectionPlugin\";\n\nexport const getComputedColumnDetails = (\n build: Build,\n table: PgClass,\n proc: PgProc\n) => {\n if (!proc.isStable) return null;\n if (proc.namespaceId !== table.namespaceId) return null;\n if (!proc.name.startsWith(`${table.name}_`)) return null;\n if (proc.argTypeIds.length < 1) return null;\n if (proc.argTypeIds[0] !== table.type.id) return null;\n\n const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {\n if (\n proc.argModes.length === 0 || // all args are `in`\n proc.argModes[idx] === \"i\" || // this arg is `in`\n proc.argModes[idx] === \"b\" // this arg is `inout`\n ) {\n prev.push(build.pgIntrospectionResultsByKind.typeById[typeId]);\n }\n return prev;\n }, []);\n if (\n argTypes\n .slice(1)\n .some(type => type.type === \"c\" && type.class && type.class.isSelectable)\n ) {\n // Accepts two input tables? Skip.\n return null;\n }\n\n const pseudoColumnName = proc.name.slice(table.name.length + 1);\n return { argTypes, pseudoColumnName };\n};\n\nexport default (function PgComputedColumnsPlugin(\n builder,\n { pgSimpleCollections }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n scope: {\n isPgRowType,\n isPgCompoundType,\n isInputType,\n pgIntrospection: table,\n },\n fieldWithHooks,\n Self,\n } = context;\n\n if (\n isInputType ||\n !(isPgRowType || isPgCompoundType) ||\n !table ||\n table.kind !== \"class\" ||\n !table.namespace\n ) {\n return fields;\n }\n\n const {\n extend,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n inflection,\n pgOmit: omit,\n pgMakeProcField: makeProcField,\n swallowError,\n describePgEntity,\n sqlCommentByAddingTags,\n } = build;\n const tableType = table.type;\n if (!tableType) {\n throw new Error(\"Could not determine the type for this table\");\n }\n return extend(\n fields,\n introspectionResultsByKind.procedure.reduce((memo, proc) => {\n if (omit(proc, \"execute\")) return memo;\n const computedColumnDetails = getComputedColumnDetails(\n build,\n table,\n proc\n );\n if (!computedColumnDetails) return memo;\n const { pseudoColumnName } = computedColumnDetails;\n function makeField(forceList) {\n const fieldName = forceList\n ? inflection.computedColumnList(pseudoColumnName, proc, table)\n : inflection.computedColumn(pseudoColumnName, proc, table);\n try {\n memo = extend(\n memo,\n {\n [fieldName]: makeProcField(fieldName, proc, build, {\n fieldWithHooks,\n computed: true,\n forceList,\n }),\n },\n `Adding computed column for ${describePgEntity(\n proc\n )}. You can rename this field with a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n fieldName: \"newNameHere\",\n }\n )}`\n );\n } catch (e) {\n swallowError(e);\n }\n }\n const simpleCollections =\n proc.tags.simpleCollections || pgSimpleCollections;\n const hasConnections = simpleCollections !== \"only\";\n const hasSimpleCollections =\n simpleCollections === \"only\" || simpleCollections === \"both\";\n if (!proc.returnsSet || hasConnections) {\n makeField(false);\n }\n if (proc.returnsSet && hasSimpleCollections) {\n makeField(true);\n }\n return memo;\n }, {}),\n `Adding computed column to '${Self.name}'`\n );\n },\n [\"PgComputedColumns\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAIO,MAAMA,wBAAwB,GAAGA,CACtCC,KAAY,EACZC,KAAc,EACdC,IAAY,KACT;EACH,IAAI,CAACA,IAAI,CAACC,QAAQ,EAAE,OAAO,IAAI;EAC/B,IAAID,IAAI,CAACE,WAAW,KAAKH,KAAK,CAACG,WAAW,EAAE,OAAO,IAAI;EACvD,IAAI,CAACF,IAAI,CAACG,IAAI,CAACC,UAAU,CAAE,GAAEL,KAAK,CAACI,IAAK,GAAE,CAAC,EAAE,OAAO,IAAI;EACxD,IAAIH,IAAI,CAACK,UAAU,CAACC,MAAM,GAAG,CAAC,EAAE,OAAO,IAAI;EAC3C,IAAIN,IAAI,CAACK,UAAU,CAAC,CAAC,CAAC,KAAKN,KAAK,CAACQ,IAAI,CAACC,EAAE,EAAE,OAAO,IAAI;EAErD,MAAMC,QAAQ,GAAGT,IAAI,CAACK,UAAU,CAACK,MAAM,CAAC,CAACC,IAAI,EAAEC,MAAM,EAAEC,GAAG,KAAK;IAC7D,IACEb,IAAI,CAACc,QAAQ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F,CAAE,EACJ,CAAC;QACH,CAAC,CAAC,OAAOI,CAAC,EAAE;UACVd,YAAY,CAACc,CAAC,CAAC;QACjB;MACF;MACA,MAAMC,iBAAiB,GACrB7D,IAAI,CAAC8D,IAAI,CAACD,iBAAiB,IAAInC,mBAAmB;MACpD,MAAMqC,cAAc,GAAGF,iBAAiB,KAAK,MAAM;MACnD,MAAMG,oBAAoB,GACxBH,iBAAiB,KAAK,MAAM,IAAIA,iBAAiB,KAAK,MAAM;MAC9D,IAAI,CAAC7D,IAAI,CAACiE,UAAU,IAAIF,cAAc,EAAE;QACtCT,SAAS,CAAC,KAAK,CAAC;MAClB;MACA,IAAItD,IAAI,CAACiE,UAAU,IAAID,oBAAoB,EAAE;QAC3CV,SAAS,CAAC,IAAI,CAAC;MACjB;MACA,OAAOF,IAAI;IACb,CAAC,EAAE,CAAC,CAAC,CAAC,EACL,8BAA6BhB,IAAI,CAACjC,IAAK,GAC1C,CAAC;EACH,CAAC,EACD,CAAC,mBAAmB,CACtB,CAAC;AACH,CAAC;AAAAoB,OAAA,CAAA2C,OAAA,GAAA1C,uBAAA"}
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _PgComputedColumnsPlugin = require("./PgComputedColumnsPlugin");
9
-
10
8
  var _assert = _interopRequireDefault(require("assert"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  function getCompatibleComputedColumns(build, table) {
15
11
  const {
16
12
  pgIntrospectionResultsByKind: introspectionResultsByKind,
@@ -19,23 +15,25 @@ function getCompatibleComputedColumns(build, table) {
19
15
  return introspectionResultsByKind.procedure.reduce((memo, proc) => {
20
16
  /* ALSO SEE PgOrderComputedColumnsPlugin */
21
17
  // Must be marked @filterable
22
- if (!proc.tags.filterable) return memo; // Must not be omitted
18
+ if (!proc.tags.filterable) return memo;
23
19
 
24
- if (omit(proc, "execute")) return memo; // Must be a computed column
20
+ // Must not be omitted
21
+ if (omit(proc, "execute")) return memo;
25
22
 
23
+ // Must be a computed column
26
24
  const computedColumnDetails = (0, _PgComputedColumnsPlugin.getComputedColumnDetails)(build, table, proc);
27
25
  if (!computedColumnDetails) return memo;
28
26
  const {
29
27
  pseudoColumnName
30
- } = computedColumnDetails; // Must have only one required argument
28
+ } = computedColumnDetails;
31
29
 
30
+ // Must have only one required argument
32
31
  const nonOptionalArgumentsCount = proc.inputArgsCount - proc.argDefaultsNum;
33
-
34
32
  if (nonOptionalArgumentsCount > 1) {
35
33
  return memo;
36
- } // Must return a scalar
37
-
34
+ }
38
35
 
36
+ // Must return a scalar
39
37
  if (proc.returnsSet) return memo;
40
38
  const returnType = introspectionResultsByKind.typeById[proc.returnTypeId];
41
39
  if (returnType.isPgArray) return memo;
@@ -44,8 +42,9 @@ function getCompatibleComputedColumns(build, table) {
44
42
  const isRecordLike = returnType.id === "2249";
45
43
  if (isRecordLike) return memo;
46
44
  const isVoid = String(returnType.id) === "2278";
47
- if (isVoid) return memo; // Looks good
45
+ if (isVoid) return memo;
48
46
 
47
+ // Looks good
49
48
  memo.push({
50
49
  proc,
51
50
  pseudoColumnName,
@@ -54,7 +53,6 @@ function getCompatibleComputedColumns(build, table) {
54
53
  return memo;
55
54
  }, []);
56
55
  }
57
-
58
56
  var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(builder) {
59
57
  builder.hook("GraphQLInputObjectType:fields", (fields, build, context) => {
60
58
  const {
@@ -70,11 +68,9 @@ var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(b
70
68
  },
71
69
  fieldWithHooks
72
70
  } = context;
73
-
74
71
  if (!isPgCondition || !table || table.kind !== "class") {
75
72
  return fields;
76
73
  }
77
-
78
74
  const compatibleComputedColumns = getCompatibleComputedColumns(build, table);
79
75
  return extend(fields, compatibleComputedColumns.reduce((memo, {
80
76
  proc,
@@ -118,25 +114,19 @@ var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(b
118
114
  } = context;
119
115
  const shouldAddCondition = isPgFieldConnection || isPgFieldSimpleCollection;
120
116
  if (!shouldAddCondition) return args;
121
-
122
117
  if (!args.condition) {
123
118
  return args;
124
119
  }
125
-
126
120
  const proc = pgFieldIntrospection.kind === "procedure" ? pgFieldIntrospection : null;
127
121
  const table = pgFieldIntrospection.kind === "class" ? pgFieldIntrospection : proc ? pgFieldIntrospectionTable : null;
128
-
129
122
  if (!table || table.kind !== "class" || !table.namespace || omit(table, "filter")) {
130
123
  return args;
131
124
  }
132
-
133
125
  const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
134
126
  const TableConditionType = getTypeByName(inflection.conditionType(TableType.name));
135
-
136
127
  if (!TableConditionType) {
137
128
  return args;
138
129
  }
139
-
140
130
  (0, _assert.default)(getNullableType(args.condition.type) === TableConditionType, "Condition is present, but doesn't match?");
141
131
  const compatibleComputedColumns = getCompatibleComputedColumns(build, table).map(o => {
142
132
  const {
@@ -145,7 +135,8 @@ var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(b
145
135
  } = o;
146
136
  const fieldName = inflection.computedColumn(pseudoColumnName, proc, table);
147
137
  const sqlFnName = sql.identifier(proc.namespaceName, proc.name);
148
- return { ...o,
138
+ return {
139
+ ...o,
149
140
  fieldName,
150
141
  sqlFnName
151
142
  };
@@ -163,7 +154,6 @@ var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(b
163
154
  }) => {
164
155
  const val = condition[fieldName];
165
156
  const sqlCall = sql.fragment`${sqlFnName}(${queryBuilder.getTableAlias()})`;
166
-
167
157
  if (val != null) {
168
158
  queryBuilder.where(sql.fragment`${sqlCall} = ${gql2pg(val, returnType, null)}`);
169
159
  } else if (val === null) {
@@ -177,6 +167,5 @@ var PgConditionComputedColumnPlugin = function PgConditionComputedColumnPlugin(b
177
167
  return args;
178
168
  }, ["PgConditionComputedColumn"]);
179
169
  };
180
-
181
170
  exports.default = PgConditionComputedColumnPlugin;
182
171
  //# sourceMappingURL=PgConditionComputedColumnPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgConditionComputedColumnPlugin.js"],"names":["getCompatibleComputedColumns","build","table","pgIntrospectionResultsByKind","introspectionResultsByKind","pgOmit","omit","procedure","reduce","memo","proc","tags","filterable","computedColumnDetails","pseudoColumnName","nonOptionalArgumentsCount","inputArgsCount","argDefaultsNum","returnsSet","returnType","typeById","returnTypeId","isPgArray","returnTypeTable","classById","classId","isRecordLike","id","isVoid","String","push","PgConditionComputedColumnPlugin","builder","hook","fields","context","extend","pgGetGqlInputTypeByTypeIdAndModifier","inflection","describePgEntity","scope","isPgCondition","pgIntrospection","fieldWithHooks","kind","compatibleComputedColumns","fieldName","computedColumn","Type","description","wrapDescription","type","isPgConnectionConditionInputField","pgFieldIntrospection","args","pgSql","sql","gql2pg","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","graphql","getNullableType","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospectionTable","addArgDataGenerator","shouldAddCondition","condition","namespace","TableType","TableConditionType","conditionType","name","map","o","sqlFnName","identifier","namespaceName","connectionCondition","pgQuery","queryBuilder","forEach","val","sqlCall","fragment","getTableAlias","where"],"mappings":";;;;;;;AAEA;;AACA;;;;AACA,SAASA,4BAAT,CAAsCC,KAAtC,EAA6CC,KAA7C,EAAoD;AAClD,QAAM;AACJC,IAAAA,4BAA4B,EAAEC,0BAD1B;AAEJC,IAAAA,MAAM,EAAEC;AAFJ,MAGFL,KAHJ;AAIA,SAAOG,0BAA0B,CAACG,SAA3B,CAAqCC,MAArC,CAA4C,CAACC,IAAD,EAAOC,IAAP,KAAgB;AACjE;AACA;AACA,QAAI,CAACA,IAAI,CAACC,IAAL,CAAUC,UAAf,EAA2B,OAAOH,IAAP,CAHsC,CAKjE;;AACA,QAAIH,IAAI,CAACI,IAAD,EAAO,SAAP,CAAR,EAA2B,OAAOD,IAAP,CANsC,CAQjE;;AACA,UAAM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AI,IAAX,EAAiB;AACfF,gBAAAA,YAAY,CAACM,KAAb,CACE9B,GAAG,CAAC4B,QAAS,GAAED,OAAQ,MAAK1B,MAAM,CAChCyB,GADgC,EAEhC/D,UAFgC,EAGhC,IAHgC,CAIhC,EALJ;AAOD,eARD,MAQO,IAAI+D,GAAG,KAAK,IAAZ,EAAkB;AACvBF,gBAAAA,YAAY,CAACM,KAAb,CAAmB9B,GAAG,CAAC4B,QAAS,GAAED,OAAQ,UAA1C;AACD;AACF,aAfH;AAiBD;AACF;AArBI,OAAP;AAuBD,KAxBkB,CAAnB;AA0BA,WAAO7B,IAAP;AACD,GArGH,EAsGE,CAAC,2BAAD,CAtGF;AAwGD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport { getComputedColumnDetails } from \"./PgComputedColumnsPlugin\";\nimport assert from \"assert\";\nfunction getCompatibleComputedColumns(build, table) {\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgOmit: omit,\n } = build;\n return introspectionResultsByKind.procedure.reduce((memo, proc) => {\n /* ALSO SEE PgOrderComputedColumnsPlugin */\n // Must be marked @filterable\n if (!proc.tags.filterable) return memo;\n\n // Must not be omitted\n if (omit(proc, \"execute\")) return memo;\n\n // Must be a computed column\n const computedColumnDetails = getComputedColumnDetails(build, table, proc);\n if (!computedColumnDetails) return memo;\n const { pseudoColumnName } = computedColumnDetails;\n\n // Must have only one required argument\n const nonOptionalArgumentsCount = proc.inputArgsCount - proc.argDefaultsNum;\n if (nonOptionalArgumentsCount > 1) {\n return memo;\n }\n\n // Must return a scalar\n if (proc.returnsSet) return memo;\n const returnType = introspectionResultsByKind.typeById[proc.returnTypeId];\n if (returnType.isPgArray) return memo;\n const returnTypeTable =\n introspectionResultsByKind.classById[returnType.classId];\n if (returnTypeTable) return memo;\n const isRecordLike = returnType.id === \"2249\";\n if (isRecordLike) return memo;\n const isVoid = String(returnType.id) === \"2278\";\n if (isVoid) return memo;\n\n // Looks good\n memo.push({ proc, pseudoColumnName, returnType });\n return memo;\n }, []);\n}\n\nexport default (function PgConditionComputedColumnPlugin(builder) {\n builder.hook(\n \"GraphQLInputObjectType:fields\",\n (fields, build, context) => {\n const {\n extend,\n pgGetGqlInputTypeByTypeIdAndModifier,\n inflection,\n describePgEntity,\n } = build;\n const {\n scope: { isPgCondition, pgIntrospection: table },\n fieldWithHooks,\n } = context;\n if (!isPgCondition || !table || table.kind !== \"class\") {\n return fields;\n }\n const compatibleComputedColumns = getCompatibleComputedColumns(\n build,\n table\n );\n return extend(\n fields,\n compatibleComputedColumns.reduce((memo, { proc, pseudoColumnName }) => {\n const fieldName = inflection.computedColumn(\n pseudoColumnName,\n proc,\n table\n );\n const Type = pgGetGqlInputTypeByTypeIdAndModifier(\n proc.returnTypeId,\n null\n );\n if (!Type) return memo;\n memo = build.extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n {\n description: build.wrapDescription(\n `Checks for equality with the object’s \\`${fieldName}\\` field.`,\n \"field\"\n ),\n type: Type,\n },\n {\n isPgConnectionConditionInputField: true,\n pgFieldIntrospection: proc,\n }\n ),\n },\n `Adding computed column condition argument for ${describePgEntity(\n proc\n )}`\n );\n return memo;\n }, {})\n );\n },\n [\"PgConditionComputedColumn\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n pgSql: sql,\n gql2pg,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n inflection,\n pgOmit: omit,\n graphql: { getNullableType },\n } = build;\n const {\n scope: {\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection,\n pgFieldIntrospectionTable,\n },\n addArgDataGenerator,\n } = context;\n\n const shouldAddCondition =\n isPgFieldConnection || isPgFieldSimpleCollection;\n if (!shouldAddCondition) return args;\n if (!args.condition) {\n return args;\n }\n const proc =\n pgFieldIntrospection.kind === \"procedure\" ? pgFieldIntrospection : null;\n const table =\n pgFieldIntrospection.kind === \"class\"\n ? pgFieldIntrospection\n : proc\n ? pgFieldIntrospectionTable\n : null;\n if (\n !table ||\n table.kind !== \"class\" ||\n !table.namespace ||\n omit(table, \"filter\")\n ) {\n return args;\n }\n const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);\n const TableConditionType = getTypeByName(\n inflection.conditionType(TableType.name)\n );\n if (!TableConditionType) {\n return args;\n }\n assert(\n getNullableType(args.condition.type) === TableConditionType,\n \"Condition is present, but doesn't match?\"\n );\n\n const compatibleComputedColumns = getCompatibleComputedColumns(\n build,\n table\n ).map(o => {\n const { proc, pseudoColumnName } = o;\n\n const fieldName = inflection.computedColumn(\n pseudoColumnName,\n proc,\n table\n );\n const sqlFnName = sql.identifier(proc.namespaceName, proc.name);\n return {\n ...o,\n fieldName,\n sqlFnName,\n };\n });\n addArgDataGenerator(function connectionCondition({ condition }) {\n return {\n pgQuery: queryBuilder => {\n if (condition != null) {\n compatibleComputedColumns.forEach(\n ({ fieldName, sqlFnName, returnType }) => {\n const val = condition[fieldName];\n const sqlCall = sql.fragment`${sqlFnName}(${queryBuilder.getTableAlias()})`;\n if (val != null) {\n queryBuilder.where(\n sql.fragment`${sqlCall} = ${gql2pg(\n val,\n returnType,\n null\n )}`\n );\n } else if (val === null) {\n queryBuilder.where(sql.fragment`${sqlCall} IS NULL`);\n }\n }\n );\n }\n },\n };\n });\n\n return args;\n },\n [\"PgConditionComputedColumn\"]\n );\n}: Plugin);\n"],"file":"PgConditionComputedColumnPlugin.js"}
1
+ {"version":3,"file":"PgConditionComputedColumnPlugin.js","names":["_PgComputedColumnsPlugin","require","_assert","_interopRequireDefault","obj","__esModule","default","getCompatibleComputedColumns","build","table","pgIntrospectionResultsByKind","introspectionResultsByKind","pgOmit","omit","procedure","reduce","memo","proc","tags","filterable","computedColumnDetails","getComputedColumnDetails","pseudoColumnName","nonOptionalArgumentsCount","inputArgsCount","argDefaultsNum","returnsSet","returnType","typeById","returnTypeId","isPgArray","returnTypeTable","classById","classId","isRecordLike","id","isVoid","String","push","PgConditionComputedColumnPlugin","builder","hook","fields","context","extend","pgGetGqlInputTypeByTypeIdAndModifier","inflection","describePgEntity","scope","isPgCondition","pgIntrospection","fieldWithHooks","kind","compatibleComputedColumns","fieldName","computedColumn","Type","description","wrapDescription","type","isPgConnectionConditionInputField","pgFieldIntrospection","args","pgSql","sql","gql2pg","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","graphql","getNullableType","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospectionTable","addArgDataGenerator","shouldAddCondition","condition","namespace","TableType","TableConditionType","conditionType","name","assert","map","o","sqlFnName","identifier","namespaceName","connectionCondition","pgQuery","queryBuilder","forEach","val","sqlCall","fragment","getTableAlias","where","exports"],"sources":["../../src/plugins/PgConditionComputedColumnPlugin.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport { getComputedColumnDetails } from \"./PgComputedColumnsPlugin\";\nimport assert from \"assert\";\nfunction getCompatibleComputedColumns(build, table) {\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgOmit: omit,\n } = build;\n return introspectionResultsByKind.procedure.reduce((memo, proc) => {\n /* ALSO SEE PgOrderComputedColumnsPlugin */\n // Must be marked @filterable\n if (!proc.tags.filterable) return memo;\n\n // Must not be omitted\n if (omit(proc, \"execute\")) return memo;\n\n // Must be a computed column\n const computedColumnDetails = getComputedColumnDetails(build, table, proc);\n if (!computedColumnDetails) return memo;\n const { pseudoColumnName } = computedColumnDetails;\n\n // Must have only one required argument\n const nonOptionalArgumentsCount = proc.inputArgsCount - proc.argDefaultsNum;\n if (nonOptionalArgumentsCount > 1) {\n return memo;\n }\n\n // Must return a scalar\n if (proc.returnsSet) return memo;\n const returnType = introspectionResultsByKind.typeById[proc.returnTypeId];\n if (returnType.isPgArray) return memo;\n const returnTypeTable =\n introspectionResultsByKind.classById[returnType.classId];\n if (returnTypeTable) return memo;\n const isRecordLike = returnType.id === \"2249\";\n if (isRecordLike) return memo;\n const isVoid = String(returnType.id) === \"2278\";\n if (isVoid) return memo;\n\n // Looks good\n memo.push({ proc, pseudoColumnName, returnType });\n return memo;\n }, []);\n}\n\nexport default (function PgConditionComputedColumnPlugin(builder) {\n builder.hook(\n \"GraphQLInputObjectType:fields\",\n (fields, build, context) => {\n const {\n extend,\n pgGetGqlInputTypeByTypeIdAndModifier,\n inflection,\n describePgEntity,\n } = build;\n const {\n scope: { isPgCondition, pgIntrospection: table },\n fieldWithHooks,\n } = context;\n if (!isPgCondition || !table || table.kind !== \"class\") {\n return fields;\n }\n const compatibleComputedColumns = getCompatibleComputedColumns(\n build,\n table\n );\n return extend(\n fields,\n compatibleComputedColumns.reduce((memo, { proc, pseudoColumnName }) => {\n const fieldName = inflection.computedColumn(\n pseudoColumnName,\n proc,\n table\n );\n const Type = pgGetGqlInputTypeByTypeIdAndModifier(\n proc.returnTypeId,\n null\n );\n if (!Type) return memo;\n memo = build.extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n {\n description: build.wrapDescription(\n `Checks for equality with the object’s \\`${fieldName}\\` field.`,\n \"field\"\n ),\n type: Type,\n },\n {\n isPgConnectionConditionInputField: true,\n pgFieldIntrospection: proc,\n }\n ),\n },\n `Adding computed column condition argument for ${describePgEntity(\n proc\n )}`\n );\n return memo;\n }, {})\n );\n },\n [\"PgConditionComputedColumn\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n pgSql: sql,\n gql2pg,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n inflection,\n pgOmit: omit,\n graphql: { getNullableType },\n } = build;\n const {\n scope: {\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection,\n pgFieldIntrospectionTable,\n },\n addArgDataGenerator,\n } = context;\n\n const shouldAddCondition =\n isPgFieldConnection || isPgFieldSimpleCollection;\n if (!shouldAddCondition) return args;\n if (!args.condition) {\n return args;\n }\n const proc =\n pgFieldIntrospection.kind === \"procedure\" ? pgFieldIntrospection : null;\n const table =\n pgFieldIntrospection.kind === \"class\"\n ? pgFieldIntrospection\n : proc\n ? pgFieldIntrospectionTable\n : null;\n if (\n !table ||\n table.kind !== \"class\" ||\n !table.namespace ||\n omit(table, \"filter\")\n ) {\n return args;\n }\n const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);\n const TableConditionType = getTypeByName(\n inflection.conditionType(TableType.name)\n );\n if (!TableConditionType) {\n return args;\n }\n assert(\n getNullableType(args.condition.type) === TableConditionType,\n \"Condition is present, but doesn't match?\"\n );\n\n const compatibleComputedColumns = getCompatibleComputedColumns(\n build,\n table\n ).map(o => {\n const { proc, pseudoColumnName } = o;\n\n const fieldName = inflection.computedColumn(\n pseudoColumnName,\n proc,\n table\n );\n const sqlFnName = sql.identifier(proc.namespaceName, proc.name);\n return {\n ...o,\n fieldName,\n sqlFnName,\n };\n });\n addArgDataGenerator(function connectionCondition({ condition }) {\n return {\n pgQuery: queryBuilder => {\n if (condition != null) {\n compatibleComputedColumns.forEach(\n ({ fieldName, sqlFnName, returnType }) => {\n const val = condition[fieldName];\n const sqlCall = sql.fragment`${sqlFnName}(${queryBuilder.getTableAlias()})`;\n if (val != null) {\n queryBuilder.where(\n sql.fragment`${sqlCall} = ${gql2pg(\n val,\n returnType,\n null\n )}`\n );\n } else if (val === null) {\n queryBuilder.where(sql.fragment`${sqlCall} IS NULL`);\n }\n }\n );\n }\n },\n };\n });\n\n return args;\n },\n [\"PgConditionComputedColumn\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAEA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA4B,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAC5B,SAASG,4BAA4BA,CAACC,KAAK,EAAEC,KAAK,EAAE;EAClD,MAAM;IACJC,4BAA4B,EAAEC,0BAA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EACV,IACF,CAAE,EACJ,CAAC;cACH,CAAC,MAAM,IAAIgE,GAAG,KAAK,IAAI,EAAE;gBACvBF,YAAY,CAACM,KAAK,CAAC/B,GAAG,CAAC6B,QAAS,GAAED,OAAQ,UAAS,CAAC;cACtD;YACF,CACF,CAAC;UACH;QACF;MACF,CAAC;IACH,CAAC,CAAC;IAEF,OAAO9B,IAAI;EACb,CAAC,EACD,CAAC,2BAA2B,CAC9B,CAAC;AACH,CAAC;AAAAkC,OAAA,CAAA1F,OAAA,GAAAiC,+BAAA"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
9
8
  builder.hook("init", (_, build) => {
10
9
  const {
@@ -27,7 +26,6 @@ var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
27
26
  if (!table.namespace) return;
28
27
  const tableTypeName = inflection.tableType(table);
29
28
  /* const TableConditionType = */
30
-
31
29
  newWithHooks(GraphQLInputObjectType, {
32
30
  description: build.wrapDescription(`A condition to be used against \`${tableTypeName}\` object types. All fields are tested for equality and combined with a logical ‘and.’`, "type"),
33
31
  name: inflection.conditionType(inflection.tableType(table)),
@@ -60,6 +58,7 @@ var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
60
58
  }, true // Conditions might all be filtered
61
59
  );
62
60
  });
61
+
63
62
  return _;
64
63
  }, ["PgConnectionArgCondition"], [], ["PgTypes"]);
65
64
  builder.hook("GraphQLObjectType:fields:field:args", (args, build, context) => {
@@ -88,24 +87,19 @@ var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
88
87
  if (!shouldAddCondition) return args;
89
88
  const proc = pgFieldIntrospection.kind === "procedure" ? pgFieldIntrospection : null;
90
89
  const table = pgFieldIntrospection.kind === "class" ? pgFieldIntrospection : proc ? pgFieldIntrospectionTable : null;
91
-
92
90
  if (!table || table.kind !== "class" || !table.namespace || omit(table, "filter")) {
93
91
  return args;
94
92
  }
95
-
96
93
  if (proc) {
97
94
  if (!proc.tags.filterable) {
98
95
  return args;
99
96
  }
100
97
  }
101
-
102
98
  const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
103
99
  const TableConditionType = getTypeByName(inflection.conditionType(TableType.name));
104
-
105
100
  if (!TableConditionType) {
106
101
  return args;
107
102
  }
108
-
109
103
  const relevantAttributes = table.attributes.filter(attr => pgColumnFilter(attr, build, context) && !omit(attr, "filter"));
110
104
  addArgDataGenerator(function connectionCondition({
111
105
  condition
@@ -116,7 +110,6 @@ var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
116
110
  relevantAttributes.forEach(attr => {
117
111
  const fieldName = inflection.column(attr);
118
112
  const val = condition[fieldName];
119
-
120
113
  if (val != null) {
121
114
  queryBuilder.addLiveCondition(() => record => record[attr.name] === val);
122
115
  queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(attr.name)} = ${gql2pg(val, attr.type, attr.typeModifier)}`);
@@ -137,6 +130,5 @@ var PgConnectionArgCondition = function PgConnectionArgCondition(builder) {
137
130
  }, `Adding condition to connection field '${fieldName}' of '${Self.name}'`);
138
131
  }, ["PgConnectionArgCondition"]);
139
132
  };
140
-
141
133
  exports.default = PgConnectionArgCondition;
142
134
  //# sourceMappingURL=PgConnectionArgCondition.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgConnectionArgCondition.js"],"names":["PgConnectionArgCondition","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","pgGetGqlInputTypeByTypeIdAndModifier","graphql","GraphQLInputObjectType","GraphQLString","pgColumnFilter","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","class","forEach","table","isSelectable","namespace","tableTypeName","tableType","description","wrapDescription","name","conditionType","fields","context","fieldWithHooks","attributes","reduce","memo","attr","fieldName","column","extend","type","typeId","typeModifier","isPgConnectionConditionInputField","__origin","pgIntrospection","isPgCondition","args","pgSql","sql","gql2pg","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","scope","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","pgFieldIntrospectionTable","addArgDataGenerator","Self","shouldAddCondition","proc","kind","tags","filterable","TableType","id","TableConditionType","relevantAttributes","filter","connectionCondition","condition","pgQuery","queryBuilder","val","addLiveCondition","record","where","fragment","getTableAlias","identifier"],"mappings":";;;;;;;IAGyBA,wB,GAAT,SAASA,wBAAT,CAAkCC,OAAlC,EAA2C;AACzDA,EAAAA,OAAO,CAACC,IAAR,CACE,MADF,EAEE,CAACC,CAAD,EAAIC,KAAJ,KAAc;AACZ,UAAM;AACJC,MAAAA,YADI;AAEJC,MAAAA,4BAA4B,EAAEC,0BAF1B;AAGJC,MAAAA,oCAHI;AAIJC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,sBAAF;AAA0BC,QAAAA;AAA1B,OAJL;AAKJC,MAAAA,cALI;AAMJC,MAAAA,UANI;AAOJC,MAAAA,MAAM,EAAEC,IAPJ;AAQJC,MAAAA,gBARI;AASJC,MAAAA;AATI,QAUFb,KAVJ;AAWAG,IAAAA,0BAA0B,CAACW,KAA3B,CAAiCC,OAAjC,CAAyCC,KAAK,IAAI;AAChD;AACA,UAAI,CAACA,KAAK,CAACC,YAAP,IAAuBN,IAAI,CAACK,KAAD,EAAQ,QAAR,CAA/B,EAAkD;AAClD,UAAI,CAACA,KAAK,CAACE,SAAX,EAAsB;AAEtB,YAAMC,aAAa,GAAGV,UAAU,CAACW,SAAX,CAAqBJ,KAArB,CAAtB;AACA;;AACAf,MAAAA,YAAY,CACVK,sBADU,EAEV;AACEe,QAAAA,WAAW,EAAErB,KAAK,CAACsB,eAAN,CACV,oCAAmCH,aAAc,wFADvC,EAEX,MAFW,CADf;AAKEI,QAAAA,IAAI,EAAEd,UAAU,CAACe,aAAX,CAAyBf,UAAU,CAACW,SAAX,CAAqBJ,KAArB,CAAzB,CALR;AAMES,QAAAA,MAAM,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kB;AACvBD,gBAAAA,YAAY,CAACE,gBAAb,CACE,MAAMC,MAAM,IAAIA,MAAM,CAACxC,IAAI,CAACR,IAAN,CAAN,IAAqB,IADvC;AAGA6C,gBAAAA,YAAY,CAACI,KAAb,CACE5B,GAAG,CAAC6B,QAAS,GAAEL,YAAY,CAACM,aAAb,EAA6B,IAAG9B,GAAG,CAAC+B,UAAJ,CAC7C5C,IAAI,CAACR,IADwC,CAE7C,UAHJ;AAKD;AACF,aAtBD;AAuBD;AACF;AA3BI,OAAP;AA6BD,KA9BkB,CAAnB;AAgCA,WAAOW,MAAM,CACXQ,IADW,EAEX;AACEwB,MAAAA,SAAS,EAAE;AACT7C,QAAAA,WAAW,EAAErB,KAAK,CAACsB,eAAN,CACX,0FADW,EAEX,KAFW,CADJ;AAKTa,QAAAA,IAAI,EAAE2B;AALG;AADb,KAFW,EAWV,yCAAwC9B,SAAU,SAAQsB,IAAI,CAAC/B,IAAK,GAX1D,CAAb;AAaD,GA5GH,EA6GE,CAAC,0BAAD,CA7GF;AA+GD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nexport default (function PgConnectionArgCondition(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgGetGqlInputTypeByTypeIdAndModifier,\n graphql: { GraphQLInputObjectType, GraphQLString },\n pgColumnFilter,\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n } = build;\n introspectionResultsByKind.class.forEach(table => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.isSelectable || omit(table, \"filter\")) return;\n if (!table.namespace) return;\n\n const tableTypeName = inflection.tableType(table);\n /* const TableConditionType = */\n newWithHooks(\n GraphQLInputObjectType,\n {\n description: build.wrapDescription(\n `A condition to be used against \\`${tableTypeName}\\` object types. All fields are tested for equality and combined with a logical ‘and.’`,\n \"type\"\n ),\n name: inflection.conditionType(inflection.tableType(table)),\n fields: context => {\n const { fieldWithHooks } = context;\n return table.attributes.reduce((memo, attr) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!pgColumnFilter(attr, build, context)) return memo;\n if (omit(attr, \"filter\")) return memo;\n\n const fieldName = inflection.column(attr);\n memo = build.extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n {\n description: build.wrapDescription(\n `Checks for equality with the object’s \\`${fieldName}\\` field.`,\n \"field\"\n ),\n type:\n pgGetGqlInputTypeByTypeIdAndModifier(\n attr.typeId,\n attr.typeModifier\n ) || GraphQLString,\n },\n {\n isPgConnectionConditionInputField: true,\n }\n ),\n },\n `Adding condition argument for ${describePgEntity(attr)}`\n );\n return memo;\n }, {});\n },\n },\n {\n __origin: `Adding condition type for ${describePgEntity(\n table\n )}. You can rename the table's GraphQL type via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n table,\n {\n name: \"newNameHere\",\n }\n )}`,\n pgIntrospection: table,\n isPgCondition: true,\n },\n true // Conditions might all be filtered\n );\n });\n return _;\n },\n [\"PgConnectionArgCondition\"],\n [],\n [\"PgTypes\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n pgSql: sql,\n gql2pg,\n extend,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgColumnFilter,\n inflection,\n pgOmit: omit,\n } = build;\n const {\n scope: {\n fieldName,\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection,\n pgFieldIntrospectionTable,\n },\n addArgDataGenerator,\n Self,\n } = context;\n\n const shouldAddCondition =\n isPgFieldConnection || isPgFieldSimpleCollection;\n if (!shouldAddCondition) return args;\n\n const proc =\n pgFieldIntrospection.kind === \"procedure\" ? pgFieldIntrospection : null;\n const table =\n pgFieldIntrospection.kind === \"class\"\n ? pgFieldIntrospection\n : proc\n ? pgFieldIntrospectionTable\n : null;\n if (\n !table ||\n table.kind !== \"class\" ||\n !table.namespace ||\n omit(table, \"filter\")\n ) {\n return args;\n }\n if (proc) {\n if (!proc.tags.filterable) {\n return args;\n }\n }\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);\n const TableConditionType = getTypeByName(\n inflection.conditionType(TableType.name)\n );\n if (!TableConditionType) {\n return args;\n }\n\n const relevantAttributes = table.attributes.filter(\n attr => pgColumnFilter(attr, build, context) && !omit(attr, \"filter\")\n );\n\n addArgDataGenerator(function connectionCondition({ condition }) {\n return {\n pgQuery: queryBuilder => {\n if (condition != null) {\n relevantAttributes.forEach(attr => {\n const fieldName = inflection.column(attr);\n const val = condition[fieldName];\n if (val != null) {\n queryBuilder.addLiveCondition(\n () => record => record[attr.name] === val\n );\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n attr.name\n )} = ${gql2pg(val, attr.type, attr.typeModifier)}`\n );\n } else if (val === null) {\n queryBuilder.addLiveCondition(\n () => record => record[attr.name] == null\n );\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n attr.name\n )} IS NULL`\n );\n }\n });\n }\n },\n };\n });\n\n return extend(\n args,\n {\n condition: {\n description: build.wrapDescription(\n \"A condition to be used in determining which values should be returned by the collection.\",\n \"arg\"\n ),\n type: TableConditionType,\n },\n },\n `Adding condition to connection field '${fieldName}' of '${Self.name}'`\n );\n },\n [\"PgConnectionArgCondition\"]\n );\n}: Plugin);\n"],"file":"PgConnectionArgCondition.js"}
1
+ {"version":3,"file":"PgConnectionArgCondition.js","names":["PgConnectionArgCondition","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","pgGetGqlInputTypeByTypeIdAndModifier","graphql","GraphQLInputObjectType","GraphQLString","pgColumnFilter","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","class","forEach","table","isSelectable","namespace","tableTypeName","tableType","description","wrapDescription","name","conditionType","fields","context","fieldWithHooks","attributes","reduce","memo","attr","fieldName","column","extend","type","typeId","typeModifier","isPgConnectionConditionInputField","__origin","pgIntrospection","isPgCondition","args","pgSql","sql","gql2pg","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","scope","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","pgFieldIntrospectionTable","addArgDataGenerator","Self","shouldAddCondition","proc","kind","tags","filterable","TableType","id","TableConditionType","relevantAttributes","filter","connectionCondition","condition","pgQuery","queryBuilder","val","addLiveCondition","record","where","fragment","getTableAlias","identifier","exports","default"],"sources":["../../src/plugins/PgConnectionArgCondition.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nexport default (function PgConnectionArgCondition(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgGetGqlInputTypeByTypeIdAndModifier,\n graphql: { GraphQLInputObjectType, GraphQLString },\n pgColumnFilter,\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n } = build;\n introspectionResultsByKind.class.forEach(table => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.isSelectable || omit(table, \"filter\")) return;\n if (!table.namespace) return;\n\n const tableTypeName = inflection.tableType(table);\n /* const TableConditionType = */\n newWithHooks(\n GraphQLInputObjectType,\n {\n description: build.wrapDescription(\n `A condition to be used against \\`${tableTypeName}\\` object types. All fields are tested for equality and combined with a logical ‘and.’`,\n \"type\"\n ),\n name: inflection.conditionType(inflection.tableType(table)),\n fields: context => {\n const { fieldWithHooks } = context;\n return table.attributes.reduce((memo, attr) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!pgColumnFilter(attr, build, context)) return memo;\n if (omit(attr, \"filter\")) return memo;\n\n const fieldName = inflection.column(attr);\n memo = build.extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n {\n description: build.wrapDescription(\n `Checks for equality with the object’s \\`${fieldName}\\` field.`,\n \"field\"\n ),\n type:\n pgGetGqlInputTypeByTypeIdAndModifier(\n attr.typeId,\n attr.typeModifier\n ) || GraphQLString,\n },\n {\n isPgConnectionConditionInputField: true,\n }\n ),\n },\n `Adding condition argument for ${describePgEntity(attr)}`\n );\n return memo;\n }, {});\n },\n },\n {\n __origin: `Adding condition type for ${describePgEntity(\n table\n )}. You can rename the table's GraphQL type via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n table,\n {\n name: \"newNameHere\",\n }\n )}`,\n pgIntrospection: table,\n isPgCondition: true,\n },\n true // Conditions might all be filtered\n );\n });\n return _;\n },\n [\"PgConnectionArgCondition\"],\n [],\n [\"PgTypes\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n pgSql: sql,\n gql2pg,\n extend,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgColumnFilter,\n inflection,\n pgOmit: omit,\n } = build;\n const {\n scope: {\n fieldName,\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection,\n pgFieldIntrospectionTable,\n },\n addArgDataGenerator,\n Self,\n } = context;\n\n const shouldAddCondition =\n isPgFieldConnection || isPgFieldSimpleCollection;\n if (!shouldAddCondition) return args;\n\n const proc =\n pgFieldIntrospection.kind === \"procedure\" ? pgFieldIntrospection : null;\n const table =\n pgFieldIntrospection.kind === \"class\"\n ? pgFieldIntrospection\n : proc\n ? pgFieldIntrospectionTable\n : null;\n if (\n !table ||\n table.kind !== \"class\" ||\n !table.namespace ||\n omit(table, \"filter\")\n ) {\n return args;\n }\n if (proc) {\n if (!proc.tags.filterable) {\n return args;\n }\n }\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);\n const TableConditionType = getTypeByName(\n inflection.conditionType(TableType.name)\n );\n if (!TableConditionType) {\n return args;\n }\n\n const relevantAttributes = table.attributes.filter(\n attr => pgColumnFilter(attr, build, context) && !omit(attr, \"filter\")\n );\n\n addArgDataGenerator(function connectionCondition({ condition }) {\n return {\n pgQuery: queryBuilder => {\n if (condition != null) {\n relevantAttributes.forEach(attr => {\n const fieldName = inflection.column(attr);\n const val = condition[fieldName];\n if (val != null) {\n queryBuilder.addLiveCondition(\n () => record => record[attr.name] === val\n );\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n attr.name\n )} = ${gql2pg(val, attr.type, attr.typeModifier)}`\n );\n } else if (val === null) {\n queryBuilder.addLiveCondition(\n () => record => record[attr.name] == null\n );\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n attr.name\n )} IS NULL`\n );\n }\n });\n }\n },\n };\n });\n\n return extend(\n args,\n {\n condition: {\n description: build.wrapDescription(\n \"A condition to be used in determining which values should be returned by the collection.\",\n \"arg\"\n ),\n type: TableConditionType,\n },\n },\n `Adding condition to connection field '${fieldName}' of '${Self.name}'`\n );\n },\n [\"PgConnectionArgCondition\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;IAGyBA,wBAAwB,GAAjC,SAASA,wBAAwBA,CAACC,OAAO,EAAE;EACzDA,OAAO,CAACC,IAAI,CACV,MAAM,EACN,CAACC,CAAC,EAAEC,KAAK,KAAK;IACZ,MAAM;MACJC,YAAY;MACZC,4BAA4B,EAAEC,0BAA0B;MACxDC,oCAAoC;MACpCC,OAAO,EAAE;QAAEC,sBAAsB;QAAEC;MAAc,CAAC;MAClDC,cAAc;MACdC,UAAU;MACVC,MAAM,EAAEC,IAAI;MACZC,gBAAgB;MAChBC;IACF,CAAC,GAAGb,KAAK;IACTG,0BAA0B,CAACW,KAAK,CAACC,OAAO,CAACC,KAAK,IAAI;MAChD;MACA,IAAI,CAACA,KAAK,CAACC,YAAY,IAAIN,IAAI,CAACK,KAAK,EAAE,QAAQ,CAAC,EAAE;MAClD,IAAI,CAACA,KAAK,CAACE,SAAS,EAAE;MAEtB,MAAMC,aAAa,GAAGV,UAAU,CAACW,SAAS,CAACJ,KAAK,CAAC;MACjD;MACAf,YAAY,CACVK,sBAAsB,EACtB;QACEe,WAAW,EAAErB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I,KAAK,CAChB5B,GAAG,CAAC6B,QAAS,GAAEL,YAAY,CAACM,aAAa,CAAC,CAAE,IAAG9B,GAAG,CAAC+B,UAAU,CAC3D5C,IAAI,CAACR,IACP,CAAE,UACJ,CAAC;cACH;YACF,CAAC,CAAC;UACJ;QACF;MACF,CAAC;IACH,CAAC,CAAC;IAEF,OAAOW,MAAM,CACXQ,IAAI,EACJ;MACEwB,SAAS,EAAE;QACT7C,WAAW,EAAErB,KAAK,CAACsB,eAAe,CAChC,0FAA0F,EAC1F,KACF,CAAC;QACDa,IAAI,EAAE2B;MACR;IACF,CAAC,EACA,yCAAwC9B,SAAU,SAAQsB,IAAI,CAAC/B,IAAK,GACvE,CAAC;EACH,CAAC,EACD,CAAC,0BAA0B,CAC7B,CAAC;AACH,CAAC;AAAAqD,OAAA,CAAAC,OAAA,GAAAjF,wBAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  const base64Decode = str => Buffer.from(String(str), "base64").toString("utf8");
9
-
10
8
  var PgConnectionArgs = function PgConnectionArgs(builder) {
11
9
  builder.hook("GraphQLObjectType:fields:field:args", (args, build, context) => {
12
10
  const {
@@ -26,11 +24,9 @@ var PgConnectionArgs = function PgConnectionArgs(builder) {
26
24
  addArgDataGenerator,
27
25
  Self
28
26
  } = context;
29
-
30
27
  if (!(isPgFieldConnection || isPgFieldSimpleCollection) || !source || source.kind !== "class" && source.kind !== "procedure") {
31
28
  return args;
32
29
  }
33
-
34
30
  const Cursor = getTypeByName("Cursor");
35
31
  addArgDataGenerator(function connectionFirstLastBeforeAfter({
36
32
  first,
@@ -44,33 +40,26 @@ var PgConnectionArgs = function PgConnectionArgs(builder) {
44
40
  if (first != null) {
45
41
  queryBuilder.first(first);
46
42
  }
47
-
48
43
  if (offset != null) {
49
44
  queryBuilder.offset(offset);
50
45
  }
51
-
52
46
  if (isPgFieldConnection) {
53
47
  if (after != null) {
54
48
  addCursorConstraint(after, true);
55
49
  }
56
-
57
50
  if (before != null) {
58
51
  addCursorConstraint(before, false);
59
52
  }
60
-
61
53
  if (last != null) {
62
54
  if (first != null) {
63
55
  throw new Error("We don't support setting both first and last");
64
56
  }
65
-
66
57
  if (offset != null) {
67
58
  throw new Error("We don't support setting both offset and last");
68
59
  }
69
-
70
60
  queryBuilder.last(last);
71
61
  }
72
62
  }
73
-
74
63
  function addCursorConstraint(cursor, isAfter) {
75
64
  try {
76
65
  const cursorValues = JSON.parse(base64Decode(cursor));
@@ -110,6 +99,5 @@ var PgConnectionArgs = function PgConnectionArgs(builder) {
110
99
  }, isPgFieldConnection ? `Adding connection pagination args to field '${fieldName}' of '${Self.name}'` : `Adding simple collection args to field '${fieldName}' of '${Self.name}'`);
111
100
  }, ["PgConnectionArgFirstLastBeforeAfter"]);
112
101
  };
113
-
114
102
  exports.default = PgConnectionArgs;
115
103
  //# sourceMappingURL=PgConnectionArgFirstLastBeforeAfter.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgConnectionArgFirstLastBeforeAfter.js"],"names":["base64Decode","str","Buffer","from","String","toString","PgConnectionArgs","builder","hook","args","build","context","extend","getTypeByName","graphql","GraphQLInt","scope","fieldName","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","source","addArgDataGenerator","Self","kind","Cursor","connectionFirstLastBeforeAfter","first","offset","last","after","before","pgQuery","queryBuilder","addCursorConstraint","Error","cursor","isAfter","cursorValues","JSON","parse","addCursorCondition","e","description","wrapDescription","type","name"],"mappings":";;;;;;;AAGA,MAAMA,YAAY,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAP,CAAYC,MAAM,CAACH,GAAD,CAAlB,EAAyB,QAAzB,EAAmCI,QAAnC,CAA4C,MAA5C,CAA5B;;IAEyBC,gB,GAAT,SAASA,gBAAT,CAA0BC,OAA1B,EAAmC;AACjDA,EAAAA,OAAO,CAACC,IAAR,CACE,qCADF,EAEE,CAACC,IAAD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AW,EAAEjC,KAAK,CAACkC,eAAN,CACX,wDADW,EAEX,KAFW,CADP;AAKNC,UAAAA,IAAI,EAAEpB;AALA,SADV;AAQEK,QAAAA,KAAK,EAAE;AACLa,UAAAA,WAAW,EAAEjC,KAAK,CAACkC,eAAN,CACX,uDADW,EAEX,KAFW,CADR;AAKLC,UAAAA,IAAI,EAAEpB;AALD;AART,OADmB,GAiBnB,IAjBJ;AA5BF,KAFW,EAiDXP,mBAAmB,GACd,+CAA8CD,SAAU,SAAQM,IAAI,CAACuB,IAAK,GAD5D,GAEd,2CAA0C7B,SAAU,SAAQM,IAAI,CAACuB,IAAK,GAnDhE,CAAb;AAqDD,GApIH,EAqIE,CAAC,qCAAD,CArIF;AAuID,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nconst base64Decode = str => Buffer.from(String(str), \"base64\").toString(\"utf8\");\n\nexport default (function PgConnectionArgs(builder) {\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n extend,\n getTypeByName,\n graphql: { GraphQLInt },\n } = build;\n const {\n scope: {\n fieldName,\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection: source,\n },\n addArgDataGenerator,\n Self,\n } = context;\n\n if (\n !(isPgFieldConnection || isPgFieldSimpleCollection) ||\n !source ||\n (source.kind !== \"class\" && source.kind !== \"procedure\")\n ) {\n return args;\n }\n const Cursor = getTypeByName(\"Cursor\");\n\n addArgDataGenerator(function connectionFirstLastBeforeAfter({\n first,\n offset,\n last,\n after,\n before,\n }) {\n return {\n pgQuery: queryBuilder => {\n if (first != null) {\n queryBuilder.first(first);\n }\n if (offset != null) {\n queryBuilder.offset(offset);\n }\n if (isPgFieldConnection) {\n if (after != null) {\n addCursorConstraint(after, true);\n }\n if (before != null) {\n addCursorConstraint(before, false);\n }\n if (last != null) {\n if (first != null) {\n throw new Error(\n \"We don't support setting both first and last\"\n );\n }\n if (offset != null) {\n throw new Error(\n \"We don't support setting both offset and last\"\n );\n }\n queryBuilder.last(last);\n }\n }\n\n function addCursorConstraint(cursor, isAfter) {\n try {\n const cursorValues = JSON.parse(base64Decode(cursor));\n return queryBuilder.addCursorCondition(cursorValues, isAfter);\n } catch (e) {\n throw new Error(\n \"Invalid cursor, please enter a cursor from a previous request, or null.\"\n );\n }\n }\n },\n };\n });\n\n return extend(\n args,\n {\n first: {\n description: build.wrapDescription(\n \"Only read the first `n` values of the set.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n ...(isPgFieldConnection\n ? {\n last: {\n description: build.wrapDescription(\n \"Only read the last `n` values of the set.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n }\n : null),\n offset: {\n description: build.wrapDescription(\n isPgFieldConnection\n ? \"Skip the first `n` values from our `after` cursor, an alternative to cursor based pagination. May not be used with `last`.\"\n : \"Skip the first `n` values.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n ...(isPgFieldConnection\n ? {\n before: {\n description: build.wrapDescription(\n \"Read all values in the set before (above) this cursor.\",\n \"arg\"\n ),\n type: Cursor,\n },\n after: {\n description: build.wrapDescription(\n \"Read all values in the set after (below) this cursor.\",\n \"arg\"\n ),\n type: Cursor,\n },\n }\n : null),\n },\n isPgFieldConnection\n ? `Adding connection pagination args to field '${fieldName}' of '${Self.name}'`\n : `Adding simple collection args to field '${fieldName}' of '${Self.name}'`\n );\n },\n [\"PgConnectionArgFirstLastBeforeAfter\"]\n );\n}: Plugin);\n"],"file":"PgConnectionArgFirstLastBeforeAfter.js"}
1
+ {"version":3,"file":"PgConnectionArgFirstLastBeforeAfter.js","names":["base64Decode","str","Buffer","from","String","toString","PgConnectionArgs","builder","hook","args","build","context","extend","getTypeByName","graphql","GraphQLInt","scope","fieldName","isPgFieldConnection","isPgFieldSimpleCollection","pgFieldIntrospection","source","addArgDataGenerator","Self","kind","Cursor","connectionFirstLastBeforeAfter","first","offset","last","after","before","pgQuery","queryBuilder","addCursorConstraint","Error","cursor","isAfter","cursorValues","JSON","parse","addCursorCondition","e","description","wrapDescription","type","name","exports","default"],"sources":["../../src/plugins/PgConnectionArgFirstLastBeforeAfter.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nconst base64Decode = str => Buffer.from(String(str), \"base64\").toString(\"utf8\");\n\nexport default (function PgConnectionArgs(builder) {\n builder.hook(\n \"GraphQLObjectType:fields:field:args\",\n (args, build, context) => {\n const {\n extend,\n getTypeByName,\n graphql: { GraphQLInt },\n } = build;\n const {\n scope: {\n fieldName,\n isPgFieldConnection,\n isPgFieldSimpleCollection,\n pgFieldIntrospection: source,\n },\n addArgDataGenerator,\n Self,\n } = context;\n\n if (\n !(isPgFieldConnection || isPgFieldSimpleCollection) ||\n !source ||\n (source.kind !== \"class\" && source.kind !== \"procedure\")\n ) {\n return args;\n }\n const Cursor = getTypeByName(\"Cursor\");\n\n addArgDataGenerator(function connectionFirstLastBeforeAfter({\n first,\n offset,\n last,\n after,\n before,\n }) {\n return {\n pgQuery: queryBuilder => {\n if (first != null) {\n queryBuilder.first(first);\n }\n if (offset != null) {\n queryBuilder.offset(offset);\n }\n if (isPgFieldConnection) {\n if (after != null) {\n addCursorConstraint(after, true);\n }\n if (before != null) {\n addCursorConstraint(before, false);\n }\n if (last != null) {\n if (first != null) {\n throw new Error(\n \"We don't support setting both first and last\"\n );\n }\n if (offset != null) {\n throw new Error(\n \"We don't support setting both offset and last\"\n );\n }\n queryBuilder.last(last);\n }\n }\n\n function addCursorConstraint(cursor, isAfter) {\n try {\n const cursorValues = JSON.parse(base64Decode(cursor));\n return queryBuilder.addCursorCondition(cursorValues, isAfter);\n } catch (e) {\n throw new Error(\n \"Invalid cursor, please enter a cursor from a previous request, or null.\"\n );\n }\n }\n },\n };\n });\n\n return extend(\n args,\n {\n first: {\n description: build.wrapDescription(\n \"Only read the first `n` values of the set.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n ...(isPgFieldConnection\n ? {\n last: {\n description: build.wrapDescription(\n \"Only read the last `n` values of the set.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n }\n : null),\n offset: {\n description: build.wrapDescription(\n isPgFieldConnection\n ? \"Skip the first `n` values from our `after` cursor, an alternative to cursor based pagination. May not be used with `last`.\"\n : \"Skip the first `n` values.\",\n \"arg\"\n ),\n type: GraphQLInt,\n },\n ...(isPgFieldConnection\n ? {\n before: {\n description: build.wrapDescription(\n \"Read all values in the set before (above) this cursor.\",\n \"arg\"\n ),\n type: Cursor,\n },\n after: {\n description: build.wrapDescription(\n \"Read all values in the set after (below) this cursor.\",\n \"arg\"\n ),\n type: Cursor,\n },\n }\n : null),\n },\n isPgFieldConnection\n ? `Adding connection pagination args to field '${fieldName}' of '${Self.name}'`\n : `Adding simple collection args to field '${fieldName}' of '${Self.name}'`\n );\n },\n [\"PgConnectionArgFirstLastBeforeAfter\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAGA,MAAMA,YAAY,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACC,MAAM,CAACH,GAAG,CAAC,EAAE,QAAQ,CAAC,CAACI,QAAQ,CAAC,MAAM,CAAC;AAAC,IAEvDC,gBAAgB,GAAzB,SAASA,gBAAgBA,CAACC,OAAO,EAAE;EACjDA,OAAO,CAACC,IAAI,CACV,qCAAqC,EACrC,CAACC,IAAI,EAAEC,KAAK,EAAEC,OAAO,KAAK;IACxB,MAAM;MACJC,MAAM;MACNC,aAAa;MACbC,OAAO,EAAE;QAAEC;MAAW;IACxB,CAAC,GAAGL,KAAK;IACT,MAAM;MACJM,KAAK,EAAE;QACLC,SAAS;QACTC,mBAAmB;QACnBC,yBAAyB;QACzBC,oBAAoB,EAAEC;MACxB,CAAC;MACDC,mBAAmB;MACnBC;IACF,CAAC,GAAGZ,OAAO;IAEX,IACE,EAAEO,mBAAmB,IAAIC,yBAAyB,CAAC,IACnD,CAACE,MAAM,IACNA,MAAM,CAACG,IAAI,KAAK,OAAO,IAAIH,MAAM,CAACG,IAAI,KAAK,WAAY,EACx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