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,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _debugSql = _interopRequireDefault(require("./debugSql"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
13
10
  subscriptions
14
11
  }) {
@@ -35,51 +32,43 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
35
32
  },
36
33
  fieldWithHooks
37
34
  } = context;
38
-
39
35
  if (!isRootQuery) {
40
36
  return fields;
41
37
  }
42
-
43
38
  return extend(fields, introspectionResultsByKind.class.reduce((memo, table) => {
44
39
  // PERFORMANCE: These used to be .filter(...) calls
45
40
  if (!table.namespace) return memo;
46
41
  if (omit(table, "read")) return memo;
47
42
  const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
48
43
  const sqlFullTableName = sql.identifier(table.namespace.name, table.name);
49
-
50
44
  if (TableType) {
51
45
  const uniqueConstraints = table.constraints.filter(con => con.type === "u" || con.type === "p");
52
46
  uniqueConstraints.forEach(constraint => {
53
47
  if (omit(constraint, "read")) {
54
48
  return;
55
49
  }
56
-
57
50
  const keys = constraint.keyAttributes;
58
-
59
51
  if (keys.some(key => omit(key, "read"))) {
60
52
  return;
61
53
  }
62
-
63
54
  if (!keys.every(_ => _)) {
64
55
  throw new Error("Consistency error: could not find an attribute!");
65
56
  }
66
-
67
57
  const fieldName = inflection.rowByUniqueKeys(keys, table, constraint);
68
- const keysIncludingMeta = keys.map(key => ({ ...key,
58
+ const keysIncludingMeta = keys.map(key => ({
59
+ ...key,
69
60
  sqlIdentifier: sql.identifier(key.name),
70
61
  columnName: inflection.column(key)
71
- })); // Precomputation for performance
72
-
62
+ }));
63
+ // Precomputation for performance
73
64
  const queryFromResolveDataOptions = {
74
65
  useAsterisk: false // Because it's only a single relation, no need
75
-
76
66
  };
77
67
 
78
68
  const queryFromResolveDataCallback = (queryBuilder, args) => {
79
69
  if (subscriptions && table.primaryKeyConstraint) {
80
70
  queryBuilder.selectIdentifiers(table);
81
71
  }
82
-
83
72
  const sqlTableAlias = queryBuilder.getTableAlias();
84
73
  keysIncludingMeta.forEach(({
85
74
  sqlIdentifier,
@@ -90,7 +79,6 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
90
79
  queryBuilder.where(sql.fragment`${sqlTableAlias}.${sqlIdentifier} = ${gql2pg(args[columnName], type, typeModifier)}`);
91
80
  });
92
81
  };
93
-
94
82
  memo[fieldName] = fieldWithHooks(fieldName, ({
95
83
  getDataFromParsedResolveInfoFragment
96
84
  }) => {
@@ -103,17 +91,14 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
103
91
  name
104
92
  }) => {
105
93
  const InputType = pgGetGqlInputTypeByTypeIdAndModifier(typeId, typeModifier);
106
-
107
94
  if (!InputType) {
108
95
  throw new Error(`Could not find input type for key '${name}' on type '${TableType.name}'`);
109
96
  }
110
-
111
97
  memo[columnName] = {
112
98
  type: new GraphQLNonNull(InputType)
113
99
  };
114
100
  return memo;
115
101
  }, {}),
116
-
117
102
  async resolve(parent, args, resolveContext, resolveInfo) {
118
103
  const {
119
104
  pgClient
@@ -121,7 +106,6 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
121
106
  const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
122
107
  const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);
123
108
  parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin
124
-
125
109
  const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, TableType);
126
110
  const query = queryFromResolveData(sqlFullTableName, undefined, resolveData, queryFromResolveDataOptions, queryBuilder => queryFromResolveDataCallback(queryBuilder, args), resolveContext, resolveInfo.rootValue);
127
111
  const {
@@ -132,14 +116,11 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
132
116
  const {
133
117
  rows: [row]
134
118
  } = await pgPrepareAndRun(pgClient, text, values);
135
-
136
119
  if (subscriptions && liveRecord && row) {
137
120
  liveRecord("pg", table, row.__identifiers);
138
121
  }
139
-
140
122
  return row;
141
123
  }
142
-
143
124
  };
144
125
  }, {
145
126
  isPgRowByUniqueConstraintField: true,
@@ -147,11 +128,9 @@ var PgRowByUniqueConstraint = async function PgRowByUniqueConstraint(builder, {
147
128
  });
148
129
  });
149
130
  }
150
-
151
131
  return memo;
152
132
  }, {}), `Adding "row by unique constraint" fields to root Query type`);
153
133
  }, ["PgRowByUniqueConstraint"]);
154
134
  };
155
-
156
135
  exports.default = PgRowByUniqueConstraint;
157
136
  //# sourceMappingURL=PgRowByUniqueConstraint.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgRowByUniqueConstraint.js"],"names":["PgRowByUniqueConstraint","builder","subscriptions","hook","fields","build","context","extend","parseResolveInfo","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","gql2pg","pgIntrospectionResultsByKind","introspectionResultsByKind","pgSql","sql","graphql","GraphQLNonNull","inflection","pgQueryFromResolveData","queryFromResolveData","pgOmit","omit","pgPrepareAndRun","scope","isRootQuery","fieldWithHooks","class","reduce","memo","table","namespace","TableType","type","id","sqlFullTableName","identifier","name","uniqueConstraints","constraints","filter","con","forEach","constraint","keys","keyAttributes","some","key","every","_","Error","fieldName","rowByUniqueKeys","keysIncludingMeta","map","sqlIdentifier","columnName","column","queryFromResolveDataOptions","useAsterisk","queryFromResolveDataCallback","queryBuilder","args","primaryKeyConstraint","selectIdentifiers","sqlTableAlias","getTableAlias","typeModifier","where","fragment","getDataFromParsedResolveInfoFragment","typeId","InputType","resolve","parent","resolveContext","resolveInfo","pgClient","liveRecord","rootValue","parsedResolveInfoFragment","resolveData","query","undefined","text","values","compile","debugSql","enabled","rows","row","__identifiers","isPgRowByUniqueConstraintField","pgFieldIntrospection"],"mappings":";;;;;;;AAEA;;;;IAE+BA,uB,GAAf,eAAeA,uBAAf,CACdC,OADc,EAEd;AAAEC,EAAAA;AAAF,CAFc,EAGd;AACAD,EAAAA,OAAO,CAACE,IAAR,CACE,0BADF,EAEE,CAACC,MAAD,EAASC,KAAT,EAAgBC,OAAhB,KAA4B;AAC1B,UAAM;AACJC,MAAAA,MADI;AAEJC,MAAAA,gBAFI;AAGJC,MAAAA,+BAHI;AAIJC,MAAAA,oCAJI;AAKJC,MAAAA,MALI;AAMJC,MAAAA,4BAA4B,EAAEC,0BAN1B;AAOJC,MAAAA,KAAK,EAAEC,GAPH;AAQJC,MAAAA,OAAO,EAAE;AAAEC,QAAAA;AAAF,OARL;AASJC,MAAAA,UATI;AAUJC,MAAAA,sBAAsB,EAAEC,oBAVpB;AAWJC,MAAAA,MAAM,EAAEC,IAXJ;AAYJC,MAAAA;AAZI,QAaFlB,KAbJ;AAcA,UAAM;AACJmB,MAAAA,KAAK,EAAE;AAAEC,QAAAA;AAAF,OADH;AAEJC,MAAAA;AAFI,QAGFpB,OAHJ;;AAKA,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B,uBAASJ,IAAT;AACtB,sBAAM;AACJK,kBAAAA,IAAI,EAAE,CAACC,GAAD;AADF,oBAEF,MAAMnE,eAAe,CAACsD,QAAD,EAAWO,IAAX,EAAiBC,MAAjB,CAFzB;;AAGA,oBAAInF,aAAa,IAAI4E,UAAjB,IAA+BY,GAAnC,EAAwC;AACtCZ,kBAAAA,UAAU,CAAC,IAAD,EAAOhD,KAAP,EAAc4D,GAAG,CAACC,aAAlB,CAAV;AACD;;AACD,uBAAOD,GAAP;AACD;;AAnDI,aAAP;AAqDD,WAxD6B,EAyD9B;AACEE,YAAAA,8BAA8B,EAAE,IADlC;AAEEC,YAAAA,oBAAoB,EAAElD;AAFxB,WAzD8B,CAAhC;AA8DD,SA3GD;AA4GD;;AACD,aAAOd,IAAP;AACD,KA/HD,EA+HG,EA/HH,CAFW,EAkIV,6DAlIU,CAAb;AAoID,GA9JH,EA+JE,CAAC,yBAAD,CA/JF;AAiKD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgRowByUniqueConstraint(\n builder,\n { subscriptions }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n extend,\n parseResolveInfo,\n pgGetGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier,\n gql2pg,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgSql: sql,\n graphql: { GraphQLNonNull },\n inflection,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isRootQuery },\n fieldWithHooks,\n } = context;\n\n if (!isRootQuery) {\n return fields;\n }\n\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.namespace) return memo;\n if (omit(table, \"read\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n const sqlFullTableName = sql.identifier(\n table.namespace.name,\n table.name\n );\n if (TableType) {\n const uniqueConstraints = table.constraints.filter(\n con => con.type === \"u\" || con.type === \"p\"\n );\n uniqueConstraints.forEach(constraint => {\n if (omit(constraint, \"read\")) {\n return;\n }\n const keys = constraint.keyAttributes;\n if (keys.some(key => omit(key, \"read\"))) {\n return;\n }\n if (!keys.every(_ => _)) {\n throw new Error(\n \"Consistency error: could not find an attribute!\"\n );\n }\n const fieldName = inflection.rowByUniqueKeys(\n keys,\n table,\n constraint\n );\n const keysIncludingMeta = keys.map(key => ({\n ...key,\n sqlIdentifier: sql.identifier(key.name),\n columnName: inflection.column(key),\n }));\n // Precomputation for performance\n const queryFromResolveDataOptions = {\n useAsterisk: false, // Because it's only a single relation, no need\n };\n const queryFromResolveDataCallback = (queryBuilder, args) => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n const sqlTableAlias = queryBuilder.getTableAlias();\n keysIncludingMeta.forEach(\n ({ sqlIdentifier, columnName, type, typeModifier }) => {\n queryBuilder.where(\n sql.fragment`${sqlTableAlias}.${sqlIdentifier} = ${gql2pg(\n args[columnName],\n type,\n typeModifier\n )}`\n );\n }\n );\n };\n\n memo[fieldName] = fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n type: TableType,\n args: keysIncludingMeta.reduce(\n (memo, { typeId, typeModifier, columnName, name }) => {\n const InputType = pgGetGqlInputTypeByTypeIdAndModifier(\n typeId,\n typeModifier\n );\n if (!InputType) {\n throw new Error(\n `Could not find input type for key '${name}' on type '${TableType.name}'`\n );\n }\n memo[columnName] = {\n type: new GraphQLNonNull(InputType),\n };\n return memo;\n },\n {}\n ),\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData = getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n TableType\n );\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n queryFromResolveDataOptions,\n queryBuilder =>\n queryFromResolveDataCallback(queryBuilder, args),\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (subscriptions && liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n },\n };\n },\n {\n isPgRowByUniqueConstraintField: true,\n pgFieldIntrospection: constraint,\n }\n );\n });\n }\n return memo;\n }, {}),\n `Adding \"row by unique constraint\" fields to root Query type`\n );\n },\n [\"PgRowByUniqueConstraint\"]\n );\n}: Plugin);\n"],"file":"PgRowByUniqueConstraint.js"}
1
+ {"version":3,"file":"PgRowByUniqueConstraint.js","names":["_debugSql","_interopRequireDefault","require","obj","__esModule","default","PgRowByUniqueConstraint","builder","subscriptions","hook","fields","build","context","extend","parseResolveInfo","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","gql2pg","pgIntrospectionResultsByKind","introspectionResultsByKind","pgSql","sql","graphql","GraphQLNonNull","inflection","pgQueryFromResolveData","queryFromResolveData","pgOmit","omit","pgPrepareAndRun","scope","isRootQuery","fieldWithHooks","class","reduce","memo","table","namespace","TableType","type","id","sqlFullTableName","identifier","name","uniqueConstraints","constraints","filter","con","forEach","constraint","keys","keyAttributes","some","key","every","_","Error","fieldName","rowByUniqueKeys","keysIncludingMeta","map","sqlIdentifier","columnName","column","queryFromResolveDataOptions","useAsterisk","queryFromResolveDataCallback","queryBuilder","args","primaryKeyConstraint","selectIdentifiers","sqlTableAlias","getTableAlias","typeModifier","where","fragment","getDataFromParsedResolveInfoFragment","typeId","InputType","resolve","parent","resolveContext","resolveInfo","pgClient","liveRecord","rootValue","parsedResolveInfoFragment","resolveData","query","undefined","text","values","compile","debugSql","enabled","rows","row","__identifiers","isPgRowByUniqueConstraintField","pgFieldIntrospection","exports"],"sources":["../../src/plugins/PgRowByUniqueConstraint.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgRowByUniqueConstraint(\n builder,\n { subscriptions }\n) {\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n extend,\n parseResolveInfo,\n pgGetGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier,\n gql2pg,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgSql: sql,\n graphql: { GraphQLNonNull },\n inflection,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isRootQuery },\n fieldWithHooks,\n } = context;\n\n if (!isRootQuery) {\n return fields;\n }\n\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.namespace) return memo;\n if (omit(table, \"read\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n const sqlFullTableName = sql.identifier(\n table.namespace.name,\n table.name\n );\n if (TableType) {\n const uniqueConstraints = table.constraints.filter(\n con => con.type === \"u\" || con.type === \"p\"\n );\n uniqueConstraints.forEach(constraint => {\n if (omit(constraint, \"read\")) {\n return;\n }\n const keys = constraint.keyAttributes;\n if (keys.some(key => omit(key, \"read\"))) {\n return;\n }\n if (!keys.every(_ => _)) {\n throw new Error(\n \"Consistency error: could not find an attribute!\"\n );\n }\n const fieldName = inflection.rowByUniqueKeys(\n keys,\n table,\n constraint\n );\n const keysIncludingMeta = keys.map(key => ({\n ...key,\n sqlIdentifier: sql.identifier(key.name),\n columnName: inflection.column(key),\n }));\n // Precomputation for performance\n const queryFromResolveDataOptions = {\n useAsterisk: false, // Because it's only a single relation, no need\n };\n const queryFromResolveDataCallback = (queryBuilder, args) => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n const sqlTableAlias = queryBuilder.getTableAlias();\n keysIncludingMeta.forEach(\n ({ sqlIdentifier, columnName, type, typeModifier }) => {\n queryBuilder.where(\n sql.fragment`${sqlTableAlias}.${sqlIdentifier} = ${gql2pg(\n args[columnName],\n type,\n typeModifier\n )}`\n );\n }\n );\n };\n\n memo[fieldName] = fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n type: TableType,\n args: keysIncludingMeta.reduce(\n (memo, { typeId, typeModifier, columnName, name }) => {\n const InputType = pgGetGqlInputTypeByTypeIdAndModifier(\n typeId,\n typeModifier\n );\n if (!InputType) {\n throw new Error(\n `Could not find input type for key '${name}' on type '${TableType.name}'`\n );\n }\n memo[columnName] = {\n type: new GraphQLNonNull(InputType),\n };\n return memo;\n },\n {}\n ),\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData = getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n TableType\n );\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n queryFromResolveDataOptions,\n queryBuilder =>\n queryFromResolveDataCallback(queryBuilder, args),\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (subscriptions && liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n },\n };\n },\n {\n isPgRowByUniqueConstraintField: true,\n pgFieldIntrospection: constraint,\n }\n );\n });\n }\n return memo;\n }, {}),\n `Adding \"row by unique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IAAI,GAAGA,IAAI,CAAC,CAAC;gBACvC,MAAMmB,WAAW,GAAGX,oCAAoC,CACtDU,yBAAyB,EACzBhD,SACF,CAAC;gBACD,MAAMkD,KAAK,GAAG9D,oBAAoB,CAChCe,gBAAgB,EAChBgD,SAAS,EACTF,WAAW,EACXvB,2BAA2B,EAC3BG,YAAY,IACVD,4BAA4B,CAACC,YAAY,EAAEC,IAAI,CAAC,EAClDa,cAAc,EACdC,WAAW,CAACG,SACd,CAAC;gBACD,MAAM;kBAAEK,IAAI;kBAAEC;gBAAO,CAAC,GAAGtE,GAAG,CAACuE,OAAO,CAACJ,KAAK,CAAC;gBAC3C,IAAIK,iBAAQ,CAACC,OAAO,EAAE,IAAAD,iBAAQ,EAACH,IAAI,CAAC;gBACpC,MAAM;kBACJK,IAAI,EAAE,CAACC,GAAG;gBACZ,CAAC,GAAG,MAAMnE,eAAe,CAACsD,QAAQ,EAAEO,IAAI,EAAEC,MAAM,CAAC;gBACjD,IAAInF,aAAa,IAAI4E,UAAU,IAAIY,GAAG,EAAE;kBACtCZ,UAAU,CAAC,IAAI,EAAEhD,KAAK,EAAE4D,GAAG,CAACC,aAAa,CAAC;gBAC5C;gBACA,OAAOD,GAAG;cACZ;YACF,CAAC;UACH,CAAC,EACD;YACEE,8BAA8B,EAAE,IAAI;YACpCC,oBAAoB,EAAElD;UACxB,CACF,CAAC;QACH,CAAC,CAAC;MACJ;MACA,OAAOd,IAAI;IACb,CAAC,EAAE,CAAC,CAAC,CAAC,EACL,6DACH,CAAC;EACH,CAAC,EACD,CAAC,yBAAyB,CAC5B,CAAC;AACH,CAAC;AAAAiE,OAAA,CAAA/F,OAAA,GAAAC,uBAAA"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _debugSql = _interopRequireDefault(require("./debugSql"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  var PgRowNode = async function PgRowNode(builder, {
13
10
  subscriptions
14
11
  }) {
@@ -27,42 +24,33 @@ var PgRowNode = async function PgRowNode(builder, {
27
24
  pgIntrospection: table
28
25
  }
29
26
  } = context;
30
-
31
27
  if (!addNodeFetcherForTypeName) {
32
28
  // Node plugin must be disabled.
33
29
  return object;
34
30
  }
35
-
36
31
  if (!isPgRowType || !table.namespace || omit(table, "read")) {
37
32
  return object;
38
33
  }
39
-
40
34
  const sqlFullTableName = sql.identifier(table.namespace.name, table.name);
41
35
  const primaryKeyConstraint = table.primaryKeyConstraint;
42
-
43
36
  if (!primaryKeyConstraint) {
44
37
  return object;
45
38
  }
46
-
47
39
  const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributes;
48
40
  addNodeFetcherForTypeName(object.name, async (data, identifiers, resolveContext, parsedResolveInfoFragment, ReturnType, resolveData, resolveInfo) => {
49
41
  const {
50
42
  pgClient
51
43
  } = resolveContext;
52
44
  const liveRecord = resolveInfo && resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
53
-
54
45
  if (identifiers.length !== primaryKeys.length) {
55
46
  throw new Error("Invalid ID");
56
47
  }
57
-
58
48
  const query = queryFromResolveData(sqlFullTableName, undefined, resolveData, {
59
49
  useAsterisk: false // Because it's only a single relation, no need
60
-
61
50
  }, queryBuilder => {
62
51
  if (subscriptions && table.primaryKeyConstraint) {
63
52
  queryBuilder.selectIdentifiers(table);
64
53
  }
65
-
66
54
  primaryKeys.forEach((key, idx) => {
67
55
  queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type, primaryKeys[idx].typeModifier)}`);
68
56
  });
@@ -75,11 +63,9 @@ var PgRowNode = async function PgRowNode(builder, {
75
63
  const {
76
64
  rows: [row]
77
65
  } = await pgPrepareAndRun(pgClient, text, values);
78
-
79
66
  if (subscriptions && liveRecord && row) {
80
67
  liveRecord("pg", table, row.__identifiers);
81
68
  }
82
-
83
69
  return row;
84
70
  });
85
71
  return object;
@@ -111,25 +97,20 @@ var PgRowNode = async function PgRowNode(builder, {
111
97
  },
112
98
  fieldWithHooks
113
99
  } = context;
114
-
115
100
  if (!isRootQuery || !nodeIdFieldName) {
116
101
  return fields;
117
102
  }
118
-
119
103
  return extend(fields, introspectionResultsByKind.class.reduce((memo, table) => {
120
104
  // PERFORMANCE: These used to be .filter(...) calls
121
105
  if (!table.namespace) return memo;
122
106
  if (omit(table, "read")) return memo;
123
107
  const TableType = pgGetGqlTypeByTypeIdAndModifier(table.type.id, null);
124
108
  const sqlFullTableName = sql.identifier(table.namespace.name, table.name);
125
-
126
109
  if (TableType) {
127
110
  const primaryKeyConstraint = table.primaryKeyConstraint;
128
-
129
111
  if (!primaryKeyConstraint) {
130
112
  return memo;
131
113
  }
132
-
133
114
  const primaryKeys = primaryKeyConstraint && primaryKeyConstraint.keyAttributes;
134
115
  const fieldName = inflection.tableNode(table);
135
116
  memo = extend(memo, {
@@ -145,40 +126,32 @@ var PgRowNode = async function PgRowNode(builder, {
145
126
  type: new GraphQLNonNull(GraphQLID)
146
127
  }
147
128
  },
148
-
149
129
  async resolve(parent, args, resolveContext, resolveInfo) {
150
130
  const {
151
131
  pgClient
152
132
  } = resolveContext;
153
133
  const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
154
134
  const nodeId = args[nodeIdFieldName];
155
-
156
135
  try {
157
136
  const {
158
137
  Type,
159
138
  identifiers
160
139
  } = getTypeAndIdentifiersFromNodeId(nodeId);
161
-
162
140
  if (Type !== TableType) {
163
141
  throw new Error("Mismatched type");
164
142
  }
165
-
166
143
  if (identifiers.length !== primaryKeys.length) {
167
144
  throw new Error("Invalid ID");
168
145
  }
169
-
170
146
  const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);
171
147
  parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin
172
-
173
148
  const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, TableType);
174
149
  const query = queryFromResolveData(sqlFullTableName, undefined, resolveData, {
175
150
  useAsterisk: false // Because it's only a single relation, no need
176
-
177
151
  }, queryBuilder => {
178
152
  if (subscriptions && table.primaryKeyConstraint) {
179
153
  queryBuilder.selectIdentifiers(table);
180
154
  }
181
-
182
155
  primaryKeys.forEach((key, idx) => {
183
156
  queryBuilder.where(sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(key.name)} = ${gql2pg(identifiers[idx], primaryKeys[idx].type, primaryKeys[idx].typeModifier)}`);
184
157
  });
@@ -191,17 +164,14 @@ var PgRowNode = async function PgRowNode(builder, {
191
164
  const {
192
165
  rows: [row]
193
166
  } = await pgPrepareAndRun(pgClient, text, values);
194
-
195
167
  if (liveRecord && row) {
196
168
  liveRecord("pg", table, row.__identifiers);
197
169
  }
198
-
199
170
  return row;
200
171
  } catch (e) {
201
172
  return null;
202
173
  }
203
174
  }
204
-
205
175
  };
206
176
  }, {
207
177
  isPgNodeQuery: true,
@@ -211,11 +181,9 @@ var PgRowNode = async function PgRowNode(builder, {
211
181
  name: "newNameHere"
212
182
  })}`);
213
183
  }
214
-
215
184
  return memo;
216
185
  }, {}), `Adding "row by node ID" fields to root Query type`);
217
186
  }, ["PgRowNode"]);
218
187
  };
219
-
220
188
  exports.default = PgRowNode;
221
189
  //# sourceMappingURL=PgRowNode.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgRowNode.js"],"names":["PgRowNode","builder","subscriptions","hook","object","build","context","addNodeFetcherForTypeName","pgSql","sql","gql2pg","pgQueryFromResolveData","queryFromResolveData","pgOmit","omit","pgPrepareAndRun","scope","isPgRowType","pgIntrospection","table","namespace","sqlFullTableName","identifier","name","primaryKeyConstraint","primaryKeys","keyAttributes","data","identifiers","resolveContext","parsedResolveInfoFragment","ReturnType","resolveData","resolveInfo","pgClient","liveRecord","rootValue","length","Error","query","undefined","useAsterisk","queryBuilder","selectIdentifiers","forEach","key","idx","where","fragment","getTableAlias","type","typeModifier","text","values","compile","debugSql","enabled","rows","row","__identifiers","fields","nodeIdFieldName","getTypeAndIdentifiersFromNodeId","extend","parseResolveInfo","pgGetGqlTypeByTypeIdAndModifier","pgIntrospectionResultsByKind","introspectionResultsByKind","graphql","GraphQLNonNull","GraphQLID","inflection","describePgEntity","sqlCommentByAddingTags","isRootQuery","fieldWithHooks","class","reduce","memo","TableType","id","fieldName","tableNode","getDataFromParsedResolveInfoFragment","description","wrapDescription","args","resolve","parent","nodeId","Type","e","isPgNodeQuery","pgFieldIntrospection"],"mappings":";;;;;;;AAEA;;;;IAE+BA,S,GAAf,eAAeA,SAAf,CAAyBC,OAAzB,EAAkC;AAAEC,EAAAA;AAAF,CAAlC,EAAqD;AACnED,EAAAA,OAAO,CAACE,IAAR,CACE,mBADF,EAEE,CAACC,MAAD,EAASC,KAAT,EAAgBC,OAAhB,KAA4B;AAC1B,UAAM;AACJC,MAAAA,yBADI;AAEJC,MAAAA,KAAK,EAAEC,GAFH;AAGJC,MAAAA,MAHI;AAIJC,MAAAA,sBAAsB,EAAEC,oBAJpB;AAKJC,MAAAA,MAAM,EAAEC,IALJ;AAMJC,MAAAA;AANI,QAOFV,KAPJ;AAQA,UAAM;AACJW,MAAAA,KAAK,EAAE;AAAEC,QAAAA,WAAF;AAAeC,QAAAA,eAAe,EAAEC;AAAhC;AADH,QAEFb,OAFJ;;AAIA,QAAI,CAACC,yBAAL,EAAgC;AAC9B;AACA,aAAOH,MAAP;AACD;;AACD,QAAI,CAACa,WAAD,IAAgB,CAACE,KAAK,CAACC,SAAvB,IAAoCN,IAAI,CAACK,KAAD,EAAQ,MAAR,CAA5C,EAA6D;AAC3D,aAAOf,MAAP;AACD;;AACD,UAAMiB,gBAAgB,GAAGZ,GAAG,CAACa,UAAJ,CAAeH,KAAK,CAACC,SAAN,CAAgBG,IAA/B,EAAqCJ,KAAK,CAACI,IAA3C,CAAzB;AACA,UAAMC,oBAAoB,GAAGL,KAAK,CAACK,oBAAnC;;AACA,Q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FgF,CAGhF,EAjGS,CAAb;AAmGD;;AACD,aAAOuD,IAAP;AACD,KA1HD,EA0HG,EA1HH,CAFW,EA6HV,mDA7HU,CAAb;AA+HD,GA5JH,EA6JE,CAAC,WAAD,CA7JF;AA+JD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgRowNode(builder, { subscriptions }) {\n builder.hook(\n \"GraphQLObjectType\",\n (object, build, context) => {\n const {\n addNodeFetcherForTypeName,\n pgSql: sql,\n gql2pg,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isPgRowType, pgIntrospection: table },\n } = context;\n\n if (!addNodeFetcherForTypeName) {\n // Node plugin must be disabled.\n return object;\n }\n if (!isPgRowType || !table.namespace || omit(table, \"read\")) {\n return object;\n }\n const sqlFullTableName = sql.identifier(table.namespace.name, table.name);\n const primaryKeyConstraint = table.primaryKeyConstraint;\n if (!primaryKeyConstraint) {\n return object;\n }\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n\n addNodeFetcherForTypeName(\n object.name,\n async (\n data,\n identifiers,\n resolveContext,\n parsedResolveInfoFragment,\n ReturnType,\n resolveData,\n resolveInfo\n ) => {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo &&\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (identifiers.length !== primaryKeys.length) {\n throw new Error(\"Invalid ID\");\n }\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: false, // Because it's only a single relation, no need\n },\n queryBuilder => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n primaryKeys.forEach((key, idx) => {\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )} = ${gql2pg(\n identifiers[idx],\n primaryKeys[idx].type,\n primaryKeys[idx].typeModifier\n )}`\n );\n });\n },\n resolveContext,\n resolveInfo && resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (subscriptions && liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n }\n );\n return object;\n },\n [\"PgRowNode\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n nodeIdFieldName,\n getTypeAndIdentifiersFromNodeId,\n extend,\n parseResolveInfo,\n pgGetGqlTypeByTypeIdAndModifier,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgSql: sql,\n gql2pg,\n graphql: { GraphQLNonNull, GraphQLID },\n inflection,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isRootQuery },\n fieldWithHooks,\n } = context;\n\n if (!isRootQuery || !nodeIdFieldName) {\n return fields;\n }\n\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.namespace) return memo;\n if (omit(table, \"read\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n const sqlFullTableName = sql.identifier(\n table.namespace.name,\n table.name\n );\n if (TableType) {\n const primaryKeyConstraint = table.primaryKeyConstraint;\n if (!primaryKeyConstraint) {\n return memo;\n }\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const fieldName = inflection.tableNode(table);\n memo = extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n description: build.wrapDescription(\n `Reads a single \\`${TableType.name}\\` using its globally unique \\`ID\\`.`,\n \"field\"\n ),\n type: TableType,\n args: {\n [nodeIdFieldName]: {\n description: build.wrapDescription(\n `The globally unique \\`ID\\` to be used in selecting a single \\`${TableType.name}\\`.`,\n \"arg\"\n ),\n type: new GraphQLNonNull(GraphQLID),\n },\n },\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n const nodeId = args[nodeIdFieldName];\n try {\n const { Type, identifiers } =\n getTypeAndIdentifiersFromNodeId(nodeId);\n if (Type !== TableType) {\n throw new Error(\"Mismatched type\");\n }\n if (identifiers.length !== primaryKeys.length) {\n throw new Error(\"Invalid ID\");\n }\n\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData =\n getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n TableType\n );\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: false, // Because it's only a single relation, no need\n },\n queryBuilder => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n primaryKeys.forEach((key, idx) => {\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )} = ${gql2pg(\n identifiers[idx],\n primaryKeys[idx].type,\n primaryKeys[idx].typeModifier\n )}`\n );\n });\n },\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n } catch (e) {\n return null;\n }\n },\n };\n },\n {\n isPgNodeQuery: true,\n pgFieldIntrospection: table,\n }\n ),\n },\n `Adding row by globally unique identifier field for ${describePgEntity(\n table\n )}. You can rename this table via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n table,\n { name: \"newNameHere\" }\n )}`\n );\n }\n return memo;\n }, {}),\n `Adding \"row by node ID\" fields to root Query type`\n );\n },\n [\"PgRowNode\"]\n );\n}: Plugin);\n"],"file":"PgRowNode.js"}
1
+ {"version":3,"file":"PgRowNode.js","names":["_debugSql","_interopRequireDefault","require","obj","__esModule","default","PgRowNode","builder","subscriptions","hook","object","build","context","addNodeFetcherForTypeName","pgSql","sql","gql2pg","pgQueryFromResolveData","queryFromResolveData","pgOmit","omit","pgPrepareAndRun","scope","isPgRowType","pgIntrospection","table","namespace","sqlFullTableName","identifier","name","primaryKeyConstraint","primaryKeys","keyAttributes","data","identifiers","resolveContext","parsedResolveInfoFragment","ReturnType","resolveData","resolveInfo","pgClient","liveRecord","rootValue","length","Error","query","undefined","useAsterisk","queryBuilder","selectIdentifiers","forEach","key","idx","where","fragment","getTableAlias","type","typeModifier","text","values","compile","debugSql","enabled","rows","row","__identifiers","fields","nodeIdFieldName","getTypeAndIdentifiersFromNodeId","extend","parseResolveInfo","pgGetGqlTypeByTypeIdAndModifier","pgIntrospectionResultsByKind","introspectionResultsByKind","graphql","GraphQLNonNull","GraphQLID","inflection","describePgEntity","sqlCommentByAddingTags","isRootQuery","fieldWithHooks","class","reduce","memo","TableType","id","fieldName","tableNode","getDataFromParsedResolveInfoFragment","description","wrapDescription","args","resolve","parent","nodeId","Type","e","isPgNodeQuery","pgFieldIntrospection","exports"],"sources":["../../src/plugins/PgRowNode.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nimport debugSql from \"./debugSql\";\n\nexport default (async function PgRowNode(builder, { subscriptions }) {\n builder.hook(\n \"GraphQLObjectType\",\n (object, build, context) => {\n const {\n addNodeFetcherForTypeName,\n pgSql: sql,\n gql2pg,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isPgRowType, pgIntrospection: table },\n } = context;\n\n if (!addNodeFetcherForTypeName) {\n // Node plugin must be disabled.\n return object;\n }\n if (!isPgRowType || !table.namespace || omit(table, \"read\")) {\n return object;\n }\n const sqlFullTableName = sql.identifier(table.namespace.name, table.name);\n const primaryKeyConstraint = table.primaryKeyConstraint;\n if (!primaryKeyConstraint) {\n return object;\n }\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n\n addNodeFetcherForTypeName(\n object.name,\n async (\n data,\n identifiers,\n resolveContext,\n parsedResolveInfoFragment,\n ReturnType,\n resolveData,\n resolveInfo\n ) => {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo &&\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (identifiers.length !== primaryKeys.length) {\n throw new Error(\"Invalid ID\");\n }\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: false, // Because it's only a single relation, no need\n },\n queryBuilder => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n primaryKeys.forEach((key, idx) => {\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )} = ${gql2pg(\n identifiers[idx],\n primaryKeys[idx].type,\n primaryKeys[idx].typeModifier\n )}`\n );\n });\n },\n resolveContext,\n resolveInfo && resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (subscriptions && liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n }\n );\n return object;\n },\n [\"PgRowNode\"]\n );\n\n builder.hook(\n \"GraphQLObjectType:fields\",\n (fields, build, context) => {\n const {\n nodeIdFieldName,\n getTypeAndIdentifiersFromNodeId,\n extend,\n parseResolveInfo,\n pgGetGqlTypeByTypeIdAndModifier,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgSql: sql,\n gql2pg,\n graphql: { GraphQLNonNull, GraphQLID },\n inflection,\n pgQueryFromResolveData: queryFromResolveData,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgPrepareAndRun,\n } = build;\n const {\n scope: { isRootQuery },\n fieldWithHooks,\n } = context;\n\n if (!isRootQuery || !nodeIdFieldName) {\n return fields;\n }\n\n return extend(\n fields,\n introspectionResultsByKind.class.reduce((memo, table) => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!table.namespace) return memo;\n if (omit(table, \"read\")) return memo;\n\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n table.type.id,\n null\n );\n const sqlFullTableName = sql.identifier(\n table.namespace.name,\n table.name\n );\n if (TableType) {\n const primaryKeyConstraint = table.primaryKeyConstraint;\n if (!primaryKeyConstraint) {\n return memo;\n }\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const fieldName = inflection.tableNode(table);\n memo = extend(\n memo,\n {\n [fieldName]: fieldWithHooks(\n fieldName,\n ({ getDataFromParsedResolveInfoFragment }) => {\n return {\n description: build.wrapDescription(\n `Reads a single \\`${TableType.name}\\` using its globally unique \\`ID\\`.`,\n \"field\"\n ),\n type: TableType,\n args: {\n [nodeIdFieldName]: {\n description: build.wrapDescription(\n `The globally unique \\`ID\\` to be used in selecting a single \\`${TableType.name}\\`.`,\n \"arg\"\n ),\n type: new GraphQLNonNull(GraphQLID),\n },\n },\n async resolve(parent, args, resolveContext, resolveInfo) {\n const { pgClient } = resolveContext;\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n const nodeId = args[nodeIdFieldName];\n try {\n const { Type, identifiers } =\n getTypeAndIdentifiersFromNodeId(nodeId);\n if (Type !== TableType) {\n throw new Error(\"Mismatched type\");\n }\n if (identifiers.length !== primaryKeys.length) {\n throw new Error(\"Invalid ID\");\n }\n\n const parsedResolveInfoFragment =\n parseResolveInfo(resolveInfo);\n parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin\n const resolveData =\n getDataFromParsedResolveInfoFragment(\n parsedResolveInfoFragment,\n TableType\n );\n const query = queryFromResolveData(\n sqlFullTableName,\n undefined,\n resolveData,\n {\n useAsterisk: false, // Because it's only a single relation, no need\n },\n queryBuilder => {\n if (subscriptions && table.primaryKeyConstraint) {\n queryBuilder.selectIdentifiers(table);\n }\n primaryKeys.forEach((key, idx) => {\n queryBuilder.where(\n sql.fragment`${queryBuilder.getTableAlias()}.${sql.identifier(\n key.name\n )} = ${gql2pg(\n identifiers[idx],\n primaryKeys[idx].type,\n primaryKeys[idx].typeModifier\n )}`\n );\n });\n },\n resolveContext,\n resolveInfo.rootValue\n );\n const { text, values } = sql.compile(query);\n if (debugSql.enabled) debugSql(text);\n const {\n rows: [row],\n } = await pgPrepareAndRun(pgClient, text, values);\n if (liveRecord && row) {\n liveRecord(\"pg\", table, row.__identifiers);\n }\n return row;\n } catch (e) {\n return null;\n }\n },\n };\n },\n {\n isPgNodeQuery: true,\n pgFieldIntrospection: table,\n }\n ),\n },\n `Adding row by globally unique identifier field for ${describePgEntity(\n table\n )}. You can rename this table via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n table,\n { name: \"newNameHere\" }\n )}`\n );\n }\n return memo;\n }, {}),\n `Adding \"row by node ID\" fields to root Query type`\n );\n },\n [\"PgRowNode\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAkC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAEHG,SAAS,GAAxB,eAAeA,SAASA,CAACC,OAAO,EAAE;EAAEC;AAAc,CAAC,EAAE;EACnED,OAAO,CAACE,IAAI,CACV,mBAAmB,EACnB,CAACC,MAAM,EAAEC,KAAK,EAAEC,OAAO,KAAK;IAC1B,MAAM;MACJC,yBAAyB;MACzBC,KAAK,EAAEC,GAAG;MACVC,MAAM;MACNC,sBAAsB,EAAEC,oBAAoB;MAC5CC,MAAM,EAAEC,IAAI;MACZC;IACF,CAAC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IAAI,EAAE;QAAc,CACxB,CAAE,EACJ,CAAC;MACH;MACA,OAAOuD,IAAI;IACb,CAAC,EAAE,CAAC,CAAC,CAAC,EACL,mDACH,CAAC;EACH,CAAC,EACD,CAAC,WAAW,CACd,CAAC;AACH,CAAC;AAAAgB,OAAA,CAAA/F,OAAA,GAAAC,SAAA"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  const base64 = str => Buffer.from(String(str)).toString("base64");
9
-
10
8
  var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin(builder) {
11
9
  builder.hook("init", (_, build) => {
12
10
  const {
@@ -34,20 +32,17 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
34
32
  if (omit(proc, "execute")) return;
35
33
  const returnType = introspectionResultsByKind.typeById[proc.returnTypeId];
36
34
  const returnTypeTable = introspectionResultsByKind.classById[returnType.classId];
37
-
38
35
  if (returnTypeTable) {
39
36
  // Just use the standard table connection from PgTablesPlugin
40
37
  return;
41
38
  }
42
-
43
39
  if (returnType.id === "2249") {
44
40
  // Defer handling to PgRecordFunctionConnectionPlugin
45
41
  return;
46
- } // TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod
42
+ }
43
+ // TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod
47
44
  // on function arguments and return types, however maybe a later
48
45
  // version of PG will?
49
-
50
-
51
46
  const NodeType = pgGetGqlTypeByTypeIdAndModifier(returnType.id, null) || GraphQLString;
52
47
  const EdgeType = newWithHooks(GraphQLObjectType, {
53
48
  name: inflection.scalarFunctionEdge(proc),
@@ -65,11 +60,9 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
65
60
  return {
66
61
  description: build.wrapDescription("A cursor for use in pagination.", "field"),
67
62
  type: Cursor,
68
-
69
63
  resolve(data) {
70
64
  return base64(JSON.stringify(data.__cursor));
71
65
  }
72
-
73
66
  };
74
67
  }, {
75
68
  isCursorField: true
@@ -77,11 +70,9 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
77
70
  node: {
78
71
  description: build.wrapDescription(`The \`${NodeType.name}\` at the end of the edge.`, "field"),
79
72
  type: NodeType,
80
-
81
73
  resolve(data) {
82
74
  return data.value;
83
75
  }
84
-
85
76
  }
86
77
  };
87
78
  }
@@ -93,8 +84,8 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
93
84
  nodeType: NodeType,
94
85
  pgIntrospection: proc
95
86
  });
96
- /*const ConnectionType = */
97
87
 
88
+ /*const ConnectionType = */
98
89
  newWithHooks(GraphQLObjectType, {
99
90
  name: inflection.scalarFunctionConnection(proc),
100
91
  description: build.wrapDescription(`A connection to a list of \`${NodeType.name}\` values.`, "type"),
@@ -105,20 +96,16 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
105
96
  nodes: pgField(build, fieldWithHooks, "nodes", {
106
97
  description: build.wrapDescription(`A list of \`${NodeType.name}\` objects.`, "field"),
107
98
  type: new GraphQLNonNull(new GraphQLList(NodeType)),
108
-
109
99
  resolve(data) {
110
100
  return data.data.map(entry => entry.value);
111
101
  }
112
-
113
102
  }),
114
103
  edges: pgField(build, fieldWithHooks, "edges", {
115
104
  description: build.wrapDescription(`A list of edges which contains the \`${NodeType.name}\` and cursor to aid in pagination.`, "field"),
116
105
  type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(EdgeType))),
117
-
118
106
  resolve(data) {
119
107
  return data.data;
120
108
  }
121
-
122
109
  }, {}, false, {
123
110
  hoistCursor: true
124
111
  })
@@ -138,6 +125,5 @@ var PgScalarFunctionConnectionPlugin = function PgScalarFunctionConnectionPlugin
138
125
  return _;
139
126
  }, ["PgScalarFunctionConnection"], [], ["PgTypes"]);
140
127
  };
141
-
142
128
  exports.default = PgScalarFunctionConnectionPlugin;
143
129
  //# sourceMappingURL=PgScalarFunctionConnectionPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgScalarFunctionConnectionPlugin.js"],"names":["base64","str","Buffer","from","String","toString","PgScalarFunctionConnectionPlugin","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","graphql","GraphQLObjectType","GraphQLNonNull","GraphQLList","GraphQLString","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","pgField","Cursor","procedure","forEach","proc","returnsSet","namespace","returnType","typeById","returnTypeId","returnTypeTable","classById","classId","id","NodeType","EdgeType","name","scalarFunctionEdge","description","wrapDescription","fields","fieldWithHooks","cursor","addDataGenerator","usesCursor","type","resolve","data","JSON","stringify","__cursor","isCursorField","node","value","__origin","isEdgeType","nodeType","pgIntrospection","scalarFunctionConnection","nodes","map","entry","edges","hoistCursor","isConnectionType","isPgRowConnectionType","edgeType"],"mappings":";;;;;;;AAGA,MAAMA,MAAM,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAP,CAAYC,MAAM,CAACH,GAAD,CAAlB,EAAyBI,QAAzB,CAAkC,QAAlC,CAAtB;;IAEyBC,gC,GAAT,SAASA,gCAAT,CAA0CC,OAA1C,EAAmD;AACjEA,EAAAA,OAAO,CAACC,IAAR,CACE,MADF,EAEE,CAACC,CAAD,EAAIC,KAAJ,KAAc;AACZ,UAAM;AACJC,MAAAA,YADI;AAEJC,MAAAA,4BAA4B,EAAEC,0BAF1B;AAGJC,MAAAA,aAHI;AAIJC,MAAAA,+BAJI;AAKJC,MAAAA,OAAO,EAAE;AACPC,QAAAA,iBADO;AAEPC,QAAAA,cAFO;AAGPC,QAAAA,WAHO;AAIPC,QAAAA;AAJO,OALL;AAWJC,MAAAA,UAXI;AAYJC,MAAAA,MAAM,EAAEC,IAZJ;AAaJC,MAAAA,gBAbI;AAcJC,MAAAA,sBAdI;AAeJC,MAAAA;AAfI,QAgBFhB,KAhBJ;AAkBA,UAAMiB,MAAM,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AAOrB,CAAP;AACD,GAxKH,EAyKE,CAAC,4BAAD,CAzKF,EA0KE,EA1KF,EA2KE,CAAC,SAAD,CA3KF;AA6KD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nconst base64 = str => Buffer.from(String(str)).toString(\"base64\");\n\nexport default (function PgScalarFunctionConnectionPlugin(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n graphql: {\n GraphQLObjectType,\n GraphQLNonNull,\n GraphQLList,\n GraphQLString,\n },\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgField,\n } = build;\n\n const Cursor = getTypeByName(\"Cursor\");\n introspectionResultsByKind.procedure.forEach(proc => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!proc.returnsSet) return;\n if (!proc.namespace) return;\n if (omit(proc, \"execute\")) return;\n\n const returnType =\n introspectionResultsByKind.typeById[proc.returnTypeId];\n const returnTypeTable =\n introspectionResultsByKind.classById[returnType.classId];\n if (returnTypeTable) {\n // Just use the standard table connection from PgTablesPlugin\n return;\n }\n if (returnType.id === \"2249\") {\n // Defer handling to PgRecordFunctionConnectionPlugin\n return;\n }\n // TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod\n // on function arguments and return types, however maybe a later\n // version of PG will?\n const NodeType =\n pgGetGqlTypeByTypeIdAndModifier(returnType.id, null) || GraphQLString;\n const EdgeType = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.scalarFunctionEdge(proc),\n description: build.wrapDescription(\n `A \\`${NodeType.name}\\` edge in the connection.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return {\n cursor: fieldWithHooks(\n \"cursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({\n usesCursor: [true],\n }));\n return {\n description: build.wrapDescription(\n \"A cursor for use in pagination.\",\n \"field\"\n ),\n type: Cursor,\n resolve(data) {\n return base64(JSON.stringify(data.__cursor));\n },\n };\n },\n {\n isCursorField: true,\n }\n ),\n node: {\n description: build.wrapDescription(\n `The \\`${NodeType.name}\\` at the end of the edge.`,\n \"field\"\n ),\n type: NodeType,\n resolve(data) {\n return data.value;\n },\n },\n };\n },\n },\n {\n __origin: `Adding function result edge type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}`,\n isEdgeType: true,\n nodeType: NodeType,\n pgIntrospection: proc,\n }\n );\n\n /*const ConnectionType = */\n newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.scalarFunctionConnection(proc),\n description: build.wrapDescription(\n `A connection to a list of \\`${NodeType.name}\\` values.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return {\n nodes: pgField(build, fieldWithHooks, \"nodes\", {\n description: build.wrapDescription(\n `A list of \\`${NodeType.name}\\` objects.`,\n \"field\"\n ),\n type: new GraphQLNonNull(new GraphQLList(NodeType)),\n resolve(data) {\n return data.data.map(entry => entry.value);\n },\n }),\n edges: pgField(\n build,\n fieldWithHooks,\n \"edges\",\n {\n description: build.wrapDescription(\n `A list of edges which contains the \\`${NodeType.name}\\` and cursor to aid in pagination.`,\n \"field\"\n ),\n type: new GraphQLNonNull(\n new GraphQLList(new GraphQLNonNull(EdgeType))\n ),\n resolve(data) {\n return data.data;\n },\n },\n {},\n false,\n {\n hoistCursor: true,\n }\n ),\n };\n },\n },\n {\n __origin: `Adding function connection type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}`,\n isConnectionType: true,\n isPgRowConnectionType: true,\n edgeType: EdgeType,\n nodeType: NodeType,\n pgIntrospection: proc,\n }\n );\n });\n return _;\n },\n [\"PgScalarFunctionConnection\"],\n [],\n [\"PgTypes\"]\n );\n}: Plugin);\n"],"file":"PgScalarFunctionConnectionPlugin.js"}
1
+ {"version":3,"file":"PgScalarFunctionConnectionPlugin.js","names":["base64","str","Buffer","from","String","toString","PgScalarFunctionConnectionPlugin","builder","hook","_","build","newWithHooks","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","graphql","GraphQLObjectType","GraphQLNonNull","GraphQLList","GraphQLString","inflection","pgOmit","omit","describePgEntity","sqlCommentByAddingTags","pgField","Cursor","procedure","forEach","proc","returnsSet","namespace","returnType","typeById","returnTypeId","returnTypeTable","classById","classId","id","NodeType","EdgeType","name","scalarFunctionEdge","description","wrapDescription","fields","fieldWithHooks","cursor","addDataGenerator","usesCursor","type","resolve","data","JSON","stringify","__cursor","isCursorField","node","value","__origin","isEdgeType","nodeType","pgIntrospection","scalarFunctionConnection","nodes","map","entry","edges","hoistCursor","isConnectionType","isPgRowConnectionType","edgeType","exports","default"],"sources":["../../src/plugins/PgScalarFunctionConnectionPlugin.js"],"sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nconst base64 = str => Buffer.from(String(str)).toString(\"base64\");\n\nexport default (function PgScalarFunctionConnectionPlugin(builder) {\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n newWithHooks,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n graphql: {\n GraphQLObjectType,\n GraphQLNonNull,\n GraphQLList,\n GraphQLString,\n },\n inflection,\n pgOmit: omit,\n describePgEntity,\n sqlCommentByAddingTags,\n pgField,\n } = build;\n\n const Cursor = getTypeByName(\"Cursor\");\n introspectionResultsByKind.procedure.forEach(proc => {\n // PERFORMANCE: These used to be .filter(...) calls\n if (!proc.returnsSet) return;\n if (!proc.namespace) return;\n if (omit(proc, \"execute\")) return;\n\n const returnType =\n introspectionResultsByKind.typeById[proc.returnTypeId];\n const returnTypeTable =\n introspectionResultsByKind.classById[returnType.classId];\n if (returnTypeTable) {\n // Just use the standard table connection from PgTablesPlugin\n return;\n }\n if (returnType.id === \"2249\") {\n // Defer handling to PgRecordFunctionConnectionPlugin\n return;\n }\n // TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod\n // on function arguments and return types, however maybe a later\n // version of PG will?\n const NodeType =\n pgGetGqlTypeByTypeIdAndModifier(returnType.id, null) || GraphQLString;\n const EdgeType = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.scalarFunctionEdge(proc),\n description: build.wrapDescription(\n `A \\`${NodeType.name}\\` edge in the connection.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return {\n cursor: fieldWithHooks(\n \"cursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({\n usesCursor: [true],\n }));\n return {\n description: build.wrapDescription(\n \"A cursor for use in pagination.\",\n \"field\"\n ),\n type: Cursor,\n resolve(data) {\n return base64(JSON.stringify(data.__cursor));\n },\n };\n },\n {\n isCursorField: true,\n }\n ),\n node: {\n description: build.wrapDescription(\n `The \\`${NodeType.name}\\` at the end of the edge.`,\n \"field\"\n ),\n type: NodeType,\n resolve(data) {\n return data.value;\n },\n },\n };\n },\n },\n {\n __origin: `Adding function result edge type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}`,\n isEdgeType: true,\n nodeType: NodeType,\n pgIntrospection: proc,\n }\n );\n\n /*const ConnectionType = */\n newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.scalarFunctionConnection(proc),\n description: build.wrapDescription(\n `A connection to a list of \\`${NodeType.name}\\` values.`,\n \"type\"\n ),\n fields: ({ fieldWithHooks }) => {\n return {\n nodes: pgField(build, fieldWithHooks, \"nodes\", {\n description: build.wrapDescription(\n `A list of \\`${NodeType.name}\\` objects.`,\n \"field\"\n ),\n type: new GraphQLNonNull(new GraphQLList(NodeType)),\n resolve(data) {\n return data.data.map(entry => entry.value);\n },\n }),\n edges: pgField(\n build,\n fieldWithHooks,\n \"edges\",\n {\n description: build.wrapDescription(\n `A list of edges which contains the \\`${NodeType.name}\\` and cursor to aid in pagination.`,\n \"field\"\n ),\n type: new GraphQLNonNull(\n new GraphQLList(new GraphQLNonNull(EdgeType))\n ),\n resolve(data) {\n return data.data;\n },\n },\n {},\n false,\n {\n hoistCursor: true,\n }\n ),\n };\n },\n },\n {\n __origin: `Adding function connection type for ${describePgEntity(\n proc\n )}. You can rename the function's GraphQL field (and its dependent types) via a 'Smart Comment':\\n\\n ${sqlCommentByAddingTags(\n proc,\n {\n name: \"newNameHere\",\n }\n )}`,\n isConnectionType: true,\n isPgRowConnectionType: true,\n edgeType: EdgeType,\n nodeType: NodeType,\n pgIntrospection: proc,\n }\n );\n });\n return _;\n },\n [\"PgScalarFunctionConnection\"],\n [],\n [\"PgTypes\"]\n );\n}: Plugin);\n"],"mappings":";;;;;;AAGA,MAAMA,MAAM,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACC,MAAM,CAACH,GAAG,CAAC,CAAC,CAACI,QAAQ,CAAC,QAAQ,CAAC;AAAC,IAEzCC,gCAAgC,GAAzC,SAASA,gCAAgCA,CAACC,OAAO,EAAE;EACjEA,OAAO,CAACC,IAAI,CACV,MAAM,EACN,CAACC,CAAC,EAAEC,KAAK,KAAK;IACZ,MAAM;MACJC,YAAY;MACZC,4BAA4B,EAAEC,0BAA0B;MACxDC,aAAa;MACbC,+BAA+B;MAC/BC,OAAO,EAAE;QACPC,iBAAiB;QACjBC,cAAc;QACdC,WAAW;QACXC;MACF,CAAC;MACDC,UAAU;MACVC,MAAM,EAAEC,IAAI;MACZC,gBAAgB;MAChBC,sBAAsB;MACtBC;IACF,CAAC,GAAGhB,KAAK;IAET,MAAMiB,MAAM,GAAGb,aAAa,CAAC,QAAQ,CAAC;IACtCD,0BAA0B,CAACe,SAAS,CAACC,OAAO,CAACC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