graphile-build-pg 4.9.1 → 4.11.2

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 (76) hide show
  1. package/README.md +1 -0
  2. package/node8plus/plugins/PageInfoStartEndCursor.js +2 -2
  3. package/node8plus/plugins/PageInfoStartEndCursor.js.flow +6 -2
  4. package/node8plus/plugins/PageInfoStartEndCursor.js.map +1 -1
  5. package/node8plus/plugins/PgAllRows.js +1 -1
  6. package/node8plus/plugins/PgAllRows.js.flow +6 -3
  7. package/node8plus/plugins/PgAllRows.js.map +1 -1
  8. package/node8plus/plugins/PgBackwardRelationPlugin.js +2 -2
  9. package/node8plus/plugins/PgBackwardRelationPlugin.js.flow +8 -2
  10. package/node8plus/plugins/PgBackwardRelationPlugin.js.map +1 -1
  11. package/node8plus/plugins/PgBasicsPlugin.js +1 -1
  12. package/node8plus/plugins/PgBasicsPlugin.js.flow +1 -1
  13. package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
  14. package/node8plus/plugins/PgConditionComputedColumnPlugin.js +1 -1
  15. package/node8plus/plugins/PgConditionComputedColumnPlugin.js.flow +4 -1
  16. package/node8plus/plugins/PgConditionComputedColumnPlugin.js.map +1 -1
  17. package/node8plus/plugins/PgConnectionArgCondition.js +3 -3
  18. package/node8plus/plugins/PgConnectionArgCondition.js.flow +11 -3
  19. package/node8plus/plugins/PgConnectionArgCondition.js.map +1 -1
  20. package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js +5 -5
  21. package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js.flow +20 -7
  22. package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js.map +1 -1
  23. package/node8plus/plugins/PgConnectionArgOrderBy.js +2 -2
  24. package/node8plus/plugins/PgConnectionArgOrderBy.js.flow +8 -2
  25. package/node8plus/plugins/PgConnectionArgOrderBy.js.map +1 -1
  26. package/node8plus/plugins/PgConnectionTotalCount.js +1 -1
  27. package/node8plus/plugins/PgConnectionTotalCount.js.flow +4 -1
  28. package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
  29. package/node8plus/plugins/PgForwardRelationPlugin.js +1 -1
  30. package/node8plus/plugins/PgForwardRelationPlugin.js.flow +4 -1
  31. package/node8plus/plugins/PgForwardRelationPlugin.js.map +1 -1
  32. package/node8plus/plugins/PgIntrospectionPlugin.d.ts +1 -0
  33. package/node8plus/plugins/PgIntrospectionPlugin.js +182 -159
  34. package/node8plus/plugins/PgIntrospectionPlugin.js.flow +218 -198
  35. package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
  36. package/node8plus/plugins/PgJWTPlugin.js +1 -1
  37. package/node8plus/plugins/PgJWTPlugin.js.flow +3 -1
  38. package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
  39. package/node8plus/plugins/PgMutationCreatePlugin.js +7 -7
  40. package/node8plus/plugins/PgMutationCreatePlugin.js.flow +26 -7
  41. package/node8plus/plugins/PgMutationCreatePlugin.js.map +1 -1
  42. package/node8plus/plugins/PgMutationPayloadEdgePlugin.js +2 -2
  43. package/node8plus/plugins/PgMutationPayloadEdgePlugin.js.flow +8 -2
  44. package/node8plus/plugins/PgMutationPayloadEdgePlugin.js.map +1 -1
  45. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +11 -11
  46. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +40 -11
  47. package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
  48. package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +6 -6
  49. package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.flow +24 -6
  50. package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
  51. package/node8plus/plugins/PgRecordReturnTypesPlugin.js +1 -1
  52. package/node8plus/plugins/PgRecordReturnTypesPlugin.js.flow +6 -3
  53. package/node8plus/plugins/PgRecordReturnTypesPlugin.js.map +1 -1
  54. package/node8plus/plugins/PgRowNode.js +2 -2
  55. package/node8plus/plugins/PgRowNode.js.flow +8 -2
  56. package/node8plus/plugins/PgRowNode.js.map +1 -1
  57. package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +6 -6
  58. package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.flow +24 -6
  59. package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
  60. package/node8plus/plugins/PgTablesPlugin.js +13 -13
  61. package/node8plus/plugins/PgTablesPlugin.js.flow +56 -20
  62. package/node8plus/plugins/PgTablesPlugin.js.map +1 -1
  63. package/node8plus/plugins/PgTypesPlugin.js +62 -78
  64. package/node8plus/plugins/PgTypesPlugin.js.flow +193 -76
  65. package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
  66. package/node8plus/plugins/makeProcField.js +3 -3
  67. package/node8plus/plugins/makeProcField.js.flow +16 -7
  68. package/node8plus/plugins/makeProcField.js.map +1 -1
  69. package/node8plus/plugins/viaTemporaryTable.js +1 -1
  70. package/node8plus/plugins/viaTemporaryTable.js.flow +8 -4
  71. package/node8plus/plugins/viaTemporaryTable.js.map +1 -1
  72. package/node8plus/postgresInterval.js +12 -33
  73. package/node8plus/postgresInterval.js.flow +22 -51
  74. package/node8plus/postgresInterval.js.map +1 -1
  75. package/package.json +9 -9
  76. package/res/watch-fixtures.sql +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PgTablesPlugin.js"],"names":["base64","str","Buffer","from","String","toString","hasNonNullKey","row","Array","isArray","__identifiers","every","i","k","Object","prototype","hasOwnProperty","call","PgTablesPlugin","builder","pgForbidSetofFunctionsToReturnNull","subscriptions","handleNullRow","_identifiers","identifiers","hook","_","build","getNodeIdForTypeAndIdentifiers","nodeIdFieldName","newWithHooks","getSafeAliasFromResolveInfo","pgSql","sql","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","pgRegisterGqlTypeByTypeId","pgRegisterGqlInputTypeByTypeId","pg2GqlMapper","gql2pg","graphql","GraphQLObjectType","GraphQLNonNull","GraphQLID","GraphQLList","GraphQLInputObjectType","inflection","describePgEntity","sqlCommentByAddingTags","pgField","nullableIf","condition","Type","Cursor","class","forEach","table","tags","enum","tablePgType","type","Error","arrayTablePgType","arrayType","primaryKeyConstraint","primaryKeys","keyAttributes","attributes","tableTypeName","tableType","shouldHaveNodeId","isSelectable","namespace","length","TableType","TablePatchType","TableBaseInputType","id","cb","description","name","interfaces","builtin","fields","addDataGeneratorForField","Self","pgQuery","queryBuilder","selectIdentifiers","resolve","data","finalIdentifiers","map","identifier","idx","key","domainBaseType","int","parseInt","Number","MAX_SAFE_INTEGER","__origin","pgIntrospection","isPgRowType","isPgCompoundType","isPgCompositeType","pgCreateInputFields","pgPatchInputFields","pgBaseInputFields","inputType","isInputType","pgAddSubfield","fieldName","attrName","pgType","spec","typeModifier","patchType","isPgPatch","baseInputType","isPgBaseInput","unmap","obj","modifier","fieldLookup","attr2sql","attr","column","inputField","v","fragment","namespaceName","null","join","EdgeType","edge","fieldWithHooks","cursor","addDataGenerator","usesCursor","__cursor","JSON","stringify","isCursorField","node","_args","resolveContext","resolveInfo","safeAlias","record","liveRecord","rootValue","withQueryBuilder","isEdgeType","isPgRowEdgeType","nodeType","PageInfo","connection","recurseDataGeneratorsForField","nodes","entry","edges","_context","hoistCursor","pageInfo","isConnectionType","isPgRowConnectionType","edgeType","_set","RelevantTableInputType"],"mappings":";;;;;;;AAEA,MAAMA,MAAM,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAP,CAAYC,MAAM,CAACH,GAAD,CAAlB,EAAyBI,QAAzB,CAAkC,QAAlC,CAAtB;;AAEA,MAAMC,aAAa,GAAGC,GAAG,IAAI;AAC3B,MACEC,KAAK,CAACC,OAAN,CAAcF,GAAG,CAACG,aAAlB,KACAH,GAAG,CAACG,aAAJ,CAAkBC,KAAlB,CAAwBC,CAAC,IAAIA,CAAC,IAAI,IAAlC,CAFF,E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AC2F,IAAD,EAAO7C,QAAP,KAAoB;AAClB,gBAAM8C,sBAAsB,GAAGtI,oCAAoC,CACjEwB,WAAW,CAACkB,EADqD,EAEjE8C,QAFiE,CAAnE;;AAIA,cAAI8C,sBAAJ,EAA4B;AAC1B,mBAAO,IAAI7H,WAAJ,CAAgB6H,sBAAhB,CAAP;AACD;AACF,SAV2B,EAW5B,IAX4B,CAA9B;AAaD;AACF,KAjiBD;AAkiBA,WAAOlJ,CAAP;AACD,GArkBH,EAskBE,CAAC,UAAD,CAtkBF,EAukBE,EAvkBF,EAwkBE,CAAC,SAAD,CAxkBF;AA0kBD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nconst base64 = str => Buffer.from(String(str)).toString(\"base64\");\n\nconst hasNonNullKey = row => {\n if (\n Array.isArray(row.__identifiers) &&\n row.__identifiers.every(i => i != null)\n ) {\n return true;\n }\n for (const k in row) {\n if (Object.prototype.hasOwnProperty.call(row, k)) {\n if ((k[0] !== \"_\" || k[1] !== \"_\") && row[k] !== null) {\n return true;\n }\n }\n }\n return false;\n};\n\nexport default (function PgTablesPlugin(\n builder,\n { pgForbidSetofFunctionsToReturnNull = false, subscriptions = false }\n) {\n const handleNullRow = pgForbidSetofFunctionsToReturnNull\n ? (row, _identifiers) => row\n : (row, identifiers) => {\n if ((identifiers && hasNonNullKey(identifiers)) || hasNonNullKey(row)) {\n return row;\n } else {\n return null;\n }\n };\n\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n getNodeIdForTypeAndIdentifiers,\n nodeIdFieldName,\n newWithHooks,\n getSafeAliasFromResolveInfo,\n pgSql: sql,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier,\n pgRegisterGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId,\n pg2GqlMapper,\n gql2pg,\n graphql: {\n GraphQLObjectType,\n GraphQLNonNull,\n GraphQLID,\n GraphQLList,\n GraphQLInputObjectType,\n },\n inflection,\n describePgEntity,\n sqlCommentByAddingTags,\n pgField,\n } = build;\n\n const nullableIf = (condition, Type) =>\n condition ? Type : new GraphQLNonNull(Type);\n const Cursor = getTypeByName(\"Cursor\");\n\n introspectionResultsByKind.class.forEach(table => {\n if (table.tags.enum) {\n return;\n }\n const tablePgType = table.type;\n if (!tablePgType) {\n throw new Error(\"Could not determine the type for this table\");\n }\n const arrayTablePgType = tablePgType.arrayType;\n const primaryKeyConstraint = table.primaryKeyConstraint;\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const attributes = table.attributes;\n const tableTypeName = inflection.tableType(table);\n const shouldHaveNodeId: boolean =\n nodeIdFieldName &&\n table.isSelectable &&\n table.namespace &&\n primaryKeys &&\n primaryKeys.length\n ? true\n : false;\n let TableType;\n let TablePatchType;\n let TableBaseInputType;\n pgRegisterGqlTypeByTypeId(\n tablePgType.id,\n cb => {\n if (TableType) {\n return TableType;\n }\n if (pg2GqlMapper[tablePgType.id]) {\n // Already handled\n throw new Error(\n `Register was called but there's already a mapper in place for '${tablePgType.id}'!`\n );\n }\n TableType = newWithHooks(\n GraphQLObjectType,\n {\n description: table.description || tablePgType.description,\n name: tableTypeName,\n interfaces: () => {\n if (shouldHaveNodeId) {\n return [getTypeByName(inflection.builtin(\"Node\"))];\n } else {\n return [];\n }\n },\n fields: ({ addDataGeneratorForField, Self }) => {\n const fields = {};\n if (shouldHaveNodeId) {\n // Enable nodeId interface\n addDataGeneratorForField(nodeIdFieldName, () => {\n return {\n pgQuery: queryBuilder => {\n queryBuilder.selectIdentifiers(table);\n },\n };\n });\n fields[nodeIdFieldName] = {\n description:\n \"A globally unique identifier. Can be used in various places throughout the system to identify this single value.\",\n type: new GraphQLNonNull(GraphQLID),\n resolve(data) {\n const identifiers = data.__identifiers;\n if (!identifiers) {\n return null;\n }\n /*\n * For bigint we want NodeIDs to be the same as int up\n * to the limits of int, and only to be strings after\n * that point.\n */\n const finalIdentifiers = identifiers.map(\n (identifier, idx) => {\n const key = primaryKeys[idx];\n const type = key.type.domainBaseType || key.type;\n if (type.id === \"20\" /* bigint */) {\n /*\n * When migrating from 'int' to 'bigint' we want\n * to maintain nodeIDs in the safe range before\n * moving to strings for larger numbers. Since we\n * can represent ints up to MAX_SAFE_INTEGER\n * (2^53 - 1) fine, we're using that as the\n * boundary.\n */\n const int = parseInt(identifier, 10);\n if (\n int >= -Number.MAX_SAFE_INTEGER &&\n int <= Number.MAX_SAFE_INTEGER\n ) {\n return int;\n }\n }\n return identifier;\n }\n );\n return getNodeIdForTypeAndIdentifiers(\n Self,\n ...finalIdentifiers\n );\n },\n };\n }\n return fields;\n },\n },\n {\n __origin: `Adding table 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable, // TODO:v5: remove - typo\n isPgCompositeType: !table.isSelectable,\n }\n );\n cb(TableType);\n const pgCreateInputFields = {};\n const pgPatchInputFields = {};\n const pgBaseInputFields = {};\n newWithHooks(\n GraphQLInputObjectType,\n {\n description: `An input for mutations affecting \\`${tableTypeName}\\``,\n name: inflection.inputType(TableType),\n },\n {\n __origin: `Adding table input 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 isInputType: true,\n isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n pgAddSubfield(fieldName, attrName, pgType, spec, typeModifier) {\n pgCreateInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n },\n true // If no fields, skip type automatically\n );\n\n if (table.isSelectable) {\n // XXX: these don't belong here; but we have to keep them here\n // because third-party code depends on `getTypeByName` to find\n // them; so we have to register them ahead of time. A better\n // approach is to use the modifier to specify the type you need,\n // 'patch' or 'base', so they can be registered just in time.\n TablePatchType = newWithHooks(\n GraphQLInputObjectType,\n {\n description: `Represents an update to a \\`${tableTypeName}\\`. Fields that are set will be updated.`,\n name: inflection.patchType(TableType),\n },\n {\n __origin: `Adding table patch 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n isPgPatch: true,\n pgAddSubfield(\n fieldName,\n attrName,\n pgType,\n spec,\n typeModifier\n ) {\n pgPatchInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n },\n true // Safe to skip this if no fields support updating\n );\n TableBaseInputType = newWithHooks(\n GraphQLInputObjectType,\n {\n description: `An input representation of \\`${tableTypeName}\\` with nullable fields.`,\n name: inflection.baseInputType(TableType),\n },\n {\n __origin: `Adding table base input 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n isPgBaseInput: true,\n pgAddSubfield(\n fieldName,\n attrName,\n pgType,\n spec,\n typeModifier\n ) {\n pgBaseInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n }\n );\n }\n\n pg2GqlMapper[tablePgType.id] = {\n map: _ => _,\n unmap: (obj, modifier) => {\n let fieldLookup;\n if (modifier === \"patch\") {\n fieldLookup = pgPatchInputFields;\n } else if (modifier === \"base\") {\n fieldLookup = pgBaseInputFields;\n } else {\n fieldLookup = pgCreateInputFields;\n }\n\n const attr2sql = attr => {\n // TODO: this should use `fieldInput[*].name` to find the attribute\n const fieldName = inflection.column(attr);\n const inputField = fieldLookup[fieldName];\n const v = obj[fieldName];\n if (inputField && v != null) {\n const { type, typeModifier } = inputField;\n return sql.fragment`${gql2pg(\n v,\n type,\n typeModifier\n )}::${sql.identifier(type.namespaceName, type.name)}`;\n } else {\n return sql.null; // TODO: return default instead.\n }\n };\n\n return sql.fragment`row(${sql.join(\n attributes.map(attr2sql),\n \",\"\n )})::${sql.identifier(\n tablePgType.namespaceName,\n tablePgType.name\n )}`;\n },\n };\n\n const EdgeType = newWithHooks(\n GraphQLObjectType,\n {\n description: `A \\`${tableTypeName}\\` edge in the connection.`,\n name: inflection.edge(TableType.name),\n fields: ({ fieldWithHooks }) => {\n return {\n cursor: fieldWithHooks(\n \"cursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({\n usesCursor: [true],\n pgQuery: queryBuilder => {\n if (primaryKeys) {\n queryBuilder.selectIdentifiers(table);\n }\n },\n }));\n return {\n description: \"A cursor for use in pagination.\",\n type: Cursor,\n resolve(data) {\n return (\n data.__cursor &&\n base64(JSON.stringify(data.__cursor))\n );\n },\n };\n },\n {\n isCursorField: true,\n }\n ),\n node: pgField(\n build,\n fieldWithHooks,\n \"node\",\n {\n description: `The \\`${tableTypeName}\\` at the end of the edge.`,\n type: nullableIf(\n !pgForbidSetofFunctionsToReturnNull,\n TableType\n ),\n resolve(data, _args, resolveContext, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n const record = handleNullRow(\n data[safeAlias],\n data.__identifiers\n );\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (\n record &&\n primaryKeys &&\n liveRecord &&\n data.__identifiers\n ) {\n liveRecord(\"pg\", table, data.__identifiers);\n }\n return record;\n },\n },\n {},\n false,\n {\n withQueryBuilder: queryBuilder => {\n if (subscriptions) {\n queryBuilder.selectIdentifiers(table);\n }\n },\n }\n ),\n };\n },\n },\n {\n __origin: `Adding table edge 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 isEdgeType: true,\n isPgRowEdgeType: true,\n nodeType: TableType,\n pgIntrospection: table,\n }\n );\n const PageInfo = getTypeByName(inflection.builtin(\"PageInfo\"));\n\n /*const ConnectionType = */\n newWithHooks(\n GraphQLObjectType,\n {\n description: `A connection to a list of \\`${tableTypeName}\\` values.`,\n name: inflection.connection(TableType.name),\n fields: ({ recurseDataGeneratorsForField, fieldWithHooks }) => {\n recurseDataGeneratorsForField(\"pageInfo\", true);\n return {\n nodes: pgField(\n build,\n fieldWithHooks,\n \"nodes\",\n {\n description: `A list of \\`${tableTypeName}\\` objects.`,\n type: new GraphQLNonNull(\n new GraphQLList(\n nullableIf(\n !pgForbidSetofFunctionsToReturnNull,\n TableType\n )\n )\n ),\n resolve(data, _args, resolveContext, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n return data.data.map(entry => {\n const record = handleNullRow(\n entry[safeAlias],\n entry[safeAlias].__identifiers\n );\n if (\n record &&\n liveRecord &&\n primaryKeys &&\n entry[safeAlias].__identifiers\n ) {\n liveRecord(\n \"pg\",\n table,\n entry[safeAlias].__identifiers\n );\n }\n\n return record;\n });\n },\n },\n {},\n false,\n {\n withQueryBuilder: queryBuilder => {\n if (subscriptions) {\n queryBuilder.selectIdentifiers(table);\n }\n },\n }\n ),\n edges: pgField(\n build,\n fieldWithHooks,\n \"edges\",\n {\n description: `A list of edges which contains the \\`${tableTypeName}\\` and cursor to aid in pagination.`,\n type: new GraphQLNonNull(\n new GraphQLList(new GraphQLNonNull(EdgeType))\n ),\n resolve(data, _args, _context, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n return data.data.map(entry => ({\n ...entry,\n ...entry[safeAlias],\n }));\n },\n },\n {},\n false,\n {\n hoistCursor: true,\n }\n ),\n pageInfo: PageInfo && {\n description: \"Information to aid in pagination.\",\n type: new GraphQLNonNull(PageInfo),\n resolve(data) {\n return data;\n },\n },\n };\n },\n },\n {\n __origin: `Adding table connection 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 isConnectionType: true,\n isPgRowConnectionType: true,\n edgeType: EdgeType,\n nodeType: TableType,\n pgIntrospection: table,\n }\n );\n },\n true\n );\n pgRegisterGqlInputTypeByTypeId(\n tablePgType.id,\n (_set, modifier) => {\n // This must come first, it triggers creation of all the types\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n tablePgType.id,\n null\n );\n // This must come after the pgGetGqlTypeByTypeIdAndModifier call\n if (modifier === \"patch\") {\n // TODO: v5: move the definition from above down here\n return TablePatchType;\n }\n if (modifier === \"base\") {\n // TODO: v5: move the definition from above down here\n return TableBaseInputType;\n }\n if (TableType) {\n return getTypeByName(inflection.inputType(TableType));\n }\n return null;\n },\n true\n );\n\n if (arrayTablePgType) {\n // Note: these do not return\n //\n // `new GraphQLList(new GraphQLNonNull(...))`\n //\n // because it's possible to return null entries from postgresql\n // functions. We should probably add a flag to instead export\n // the non-null version as that's more typical.\n pgRegisterGqlTypeByTypeId(\n arrayTablePgType.id,\n () => {\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n tablePgType.id,\n null\n );\n return new GraphQLList(TableType);\n },\n true\n );\n pgRegisterGqlInputTypeByTypeId(\n arrayTablePgType.id,\n (_set, modifier) => {\n const RelevantTableInputType = pgGetGqlInputTypeByTypeIdAndModifier(\n tablePgType.id,\n modifier\n );\n if (RelevantTableInputType) {\n return new GraphQLList(RelevantTableInputType);\n }\n },\n true\n );\n }\n });\n return _;\n },\n [\"PgTables\"],\n [],\n [\"PgTypes\"]\n );\n}: Plugin);\n"],"file":"PgTablesPlugin.js"}
1
+ {"version":3,"sources":["../../src/plugins/PgTablesPlugin.js"],"names":["base64","str","Buffer","from","String","toString","hasNonNullKey","row","Array","isArray","__identifiers","every","i","k","Object","prototype","hasOwnProperty","call","PgTablesPlugin","builder","pgForbidSetofFunctionsToReturnNull","subscriptions","handleNullRow","_identifiers","identifiers","hook","_","build","getNodeIdForTypeAndIdentifiers","nodeIdFieldName","newWithHooks","getSafeAliasFromResolveInfo","pgSql","sql","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","pgRegisterGqlTypeByTypeId","pgRegisterGqlInputTypeByTypeId","pg2GqlMapper","gql2pg","graphql","GraphQLObjectType","GraphQLNonNull","GraphQLID","GraphQLList","GraphQLInputObjectType","inflection","describePgEntity","sqlCommentByAddingTags","pgField","nullableIf","condition","Type","Cursor","class","forEach","table","tags","enum","tablePgType","type","Error","arrayTablePgType","arrayType","primaryKeyConstraint","primaryKeys","keyAttributes","attributes","tableTypeName","tableType","shouldHaveNodeId","isSelectable","namespace","length","TableType","TablePatchType","TableBaseInputType","id","cb","description","name","interfaces","builtin","fields","addDataGeneratorForField","Self","pgQuery","queryBuilder","selectIdentifiers","wrapDescription","resolve","data","finalIdentifiers","map","identifier","idx","key","domainBaseType","int","parseInt","Number","MAX_SAFE_INTEGER","__origin","pgIntrospection","isPgRowType","isPgCompoundType","isPgCompositeType","pgCreateInputFields","pgPatchInputFields","pgBaseInputFields","inputType","isInputType","pgAddSubfield","fieldName","attrName","pgType","spec","typeModifier","patchType","isPgPatch","baseInputType","isPgBaseInput","unmap","obj","modifier","fieldLookup","attr2sql","attr","column","inputField","v","fragment","isFake","namespaceName","null","join","EdgeType","edge","fieldWithHooks","cursor","addDataGenerator","usesCursor","__cursor","JSON","stringify","isCursorField","node","_args","resolveContext","resolveInfo","safeAlias","record","liveRecord","rootValue","withQueryBuilder","isEdgeType","isPgRowEdgeType","nodeType","PageInfo","connection","recurseDataGeneratorsForField","nodes","entry","edges","_context","hoistCursor","pageInfo","isConnectionType","isPgRowConnectionType","edgeType","_set","RelevantTableInputType"],"mappings":";;;;;;;AAEA,MAAMA,MAAM,GAAGC,GAAG,IAAIC,MAAM,CAACC,IAAP,CAAYC,MAAM,CAACH,GAAD,CAAlB,EAAyBI,QAAzB,CAAkC,QAAlC,CAAtB;;AAEA,MAAMC,aAAa,GAAGC,GAAG,IAAI;AAC3B,MACEC,KAAK,CAACC,OAAN,CAAcF,GAAG,CAACG,aAAlB,KACAH,GAAG,CAACG,aAAJ,CAAkBC,KAAlB,CAAwBC,CAAC,IAAIA,CAAC,IAAI,IAAlC,CAFF,EAGE;AACA,WAAO,IAAP;AACD;;AACD,OAAK,MAAMC,CAAX,IAAgBN,GAAhB,EAAqB;AACnB,QAAIO,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCV,GAArC,EAA0CM,CAA1C,CAAJ,EAAkD;AAChD,UAAI,CAACA,CAAC,CAAC,CAAD,CAAD,KAAS,GAAT,IAAgBA,CAAC,CAAC,CAAD,CAAD,KAAS,GAA1B,KAAkCN,GAAG,CAACM,CAAD,CAAH,KAAW,IAAjD,EAAuD;AACrD,eAAO,IAAP;AACD;AACF;AACF;;AACD,SAAO,KAAP;AACD,CAfD;;IAiByBK,c,GAAT,SAASA,cAAT,CACdC,OADc,EAEd;AAAEC,EAAAA,kCAAkC,GAAG,KAAvC;AAA8CC,EAAAA,aAAa,GAAG;AAA9D,CAFc,EAGd;AACA,QAAMC,aAAa,GAAGF,kCAAkC,GACpD,CAACb,GAAD,EAAMgB,YAAN,KAAuBhB,GAD6B,GAEpD,CAACA,GAAD,EAAMiB,WAAN,KAAsB;AACpB,QAAKA,WAAW,IAAIlB,aAAa,CAACkB,WAAD,CAA7B,IAA+ClB,aAAa,CAACC,GAAD,CAAhE,EAAuE;AACrE,aAAOA,GAAP;AACD,KAFD,MAEO;AACL,aAAO,IAAP;AACD;AACF,GARL;AAUAY,EAAAA,OAAO,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D;AACF,SAV2B,EAW5B,IAX4B,CAA9B;AAaD;AACF,KArkBD;AAskBA,WAAOpJ,CAAP;AACD,GAzmBH,EA0mBE,CAAC,UAAD,CA1mBF,EA2mBE,EA3mBF,EA4mBE,CAAC,SAAD,CA5mBF;AA8mBD,C","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\nconst base64 = str => Buffer.from(String(str)).toString(\"base64\");\n\nconst hasNonNullKey = row => {\n if (\n Array.isArray(row.__identifiers) &&\n row.__identifiers.every(i => i != null)\n ) {\n return true;\n }\n for (const k in row) {\n if (Object.prototype.hasOwnProperty.call(row, k)) {\n if ((k[0] !== \"_\" || k[1] !== \"_\") && row[k] !== null) {\n return true;\n }\n }\n }\n return false;\n};\n\nexport default (function PgTablesPlugin(\n builder,\n { pgForbidSetofFunctionsToReturnNull = false, subscriptions = false }\n) {\n const handleNullRow = pgForbidSetofFunctionsToReturnNull\n ? (row, _identifiers) => row\n : (row, identifiers) => {\n if ((identifiers && hasNonNullKey(identifiers)) || hasNonNullKey(row)) {\n return row;\n } else {\n return null;\n }\n };\n\n builder.hook(\n \"init\",\n (_, build) => {\n const {\n getNodeIdForTypeAndIdentifiers,\n nodeIdFieldName,\n newWithHooks,\n getSafeAliasFromResolveInfo,\n pgSql: sql,\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgGetGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier,\n pgRegisterGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId,\n pg2GqlMapper,\n gql2pg,\n graphql: {\n GraphQLObjectType,\n GraphQLNonNull,\n GraphQLID,\n GraphQLList,\n GraphQLInputObjectType,\n },\n inflection,\n describePgEntity,\n sqlCommentByAddingTags,\n pgField,\n } = build;\n\n const nullableIf = (condition, Type) =>\n condition ? Type : new GraphQLNonNull(Type);\n const Cursor = getTypeByName(\"Cursor\");\n\n introspectionResultsByKind.class.forEach(table => {\n if (table.tags.enum) {\n return;\n }\n const tablePgType = table.type;\n if (!tablePgType) {\n throw new Error(\"Could not determine the type for this table\");\n }\n const arrayTablePgType = tablePgType.arrayType;\n const primaryKeyConstraint = table.primaryKeyConstraint;\n const primaryKeys =\n primaryKeyConstraint && primaryKeyConstraint.keyAttributes;\n const attributes = table.attributes;\n const tableTypeName = inflection.tableType(table);\n const shouldHaveNodeId: boolean =\n nodeIdFieldName &&\n table.isSelectable &&\n table.namespace &&\n primaryKeys &&\n primaryKeys.length\n ? true\n : false;\n let TableType;\n let TablePatchType;\n let TableBaseInputType;\n pgRegisterGqlTypeByTypeId(\n tablePgType.id,\n cb => {\n if (TableType) {\n return TableType;\n }\n if (pg2GqlMapper[tablePgType.id]) {\n // Already handled\n throw new Error(\n `Register was called but there's already a mapper in place for '${tablePgType.id}'!`\n );\n }\n TableType = newWithHooks(\n GraphQLObjectType,\n {\n description: table.description || tablePgType.description,\n name: tableTypeName,\n interfaces: () => {\n if (shouldHaveNodeId) {\n return [getTypeByName(inflection.builtin(\"Node\"))];\n } else {\n return [];\n }\n },\n fields: ({ addDataGeneratorForField, Self }) => {\n const fields = {};\n if (shouldHaveNodeId) {\n // Enable nodeId interface\n addDataGeneratorForField(nodeIdFieldName, () => {\n return {\n pgQuery: queryBuilder => {\n queryBuilder.selectIdentifiers(table);\n },\n };\n });\n fields[nodeIdFieldName] = {\n description: build.wrapDescription(\n \"A globally unique identifier. Can be used in various places throughout the system to identify this single value.\",\n \"field\"\n ),\n type: new GraphQLNonNull(GraphQLID),\n resolve(data) {\n const identifiers = data.__identifiers;\n if (!identifiers) {\n return null;\n }\n /*\n * For bigint we want NodeIDs to be the same as int up\n * to the limits of int, and only to be strings after\n * that point.\n */\n const finalIdentifiers = identifiers.map(\n (identifier, idx) => {\n const key = primaryKeys[idx];\n const type = key.type.domainBaseType || key.type;\n if (type.id === \"20\" /* bigint */) {\n /*\n * When migrating from 'int' to 'bigint' we want\n * to maintain nodeIDs in the safe range before\n * moving to strings for larger numbers. Since we\n * can represent ints up to MAX_SAFE_INTEGER\n * (2^53 - 1) fine, we're using that as the\n * boundary.\n */\n const int = parseInt(identifier, 10);\n if (\n int >= -Number.MAX_SAFE_INTEGER &&\n int <= Number.MAX_SAFE_INTEGER\n ) {\n return int;\n }\n }\n return identifier;\n }\n );\n return getNodeIdForTypeAndIdentifiers(\n Self,\n ...finalIdentifiers\n );\n },\n };\n }\n return fields;\n },\n },\n {\n __origin: `Adding table 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable, // TODO:v5: remove - typo\n isPgCompositeType: !table.isSelectable,\n }\n );\n cb(TableType);\n const pgCreateInputFields = {};\n const pgPatchInputFields = {};\n const pgBaseInputFields = {};\n newWithHooks(\n GraphQLInputObjectType,\n {\n description: build.wrapDescription(\n `An input for mutations affecting \\`${tableTypeName}\\``,\n \"type\"\n ),\n name: inflection.inputType(TableType),\n },\n {\n __origin: `Adding table input 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 isInputType: true,\n isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n pgAddSubfield(fieldName, attrName, pgType, spec, typeModifier) {\n pgCreateInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n },\n true // If no fields, skip type automatically\n );\n\n if (table.isSelectable) {\n // XXX: these don't belong here; but we have to keep them here\n // because third-party code depends on `getTypeByName` to find\n // them; so we have to register them ahead of time. A better\n // approach is to use the modifier to specify the type you need,\n // 'patch' or 'base', so they can be registered just in time.\n TablePatchType = newWithHooks(\n GraphQLInputObjectType,\n {\n description: build.wrapDescription(\n `Represents an update to a \\`${tableTypeName}\\`. Fields that are set will be updated.`,\n \"type\"\n ),\n name: inflection.patchType(TableType),\n },\n {\n __origin: `Adding table patch 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n isPgPatch: true,\n pgAddSubfield(\n fieldName,\n attrName,\n pgType,\n spec,\n typeModifier\n ) {\n pgPatchInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n },\n true // Safe to skip this if no fields support updating\n );\n TableBaseInputType = newWithHooks(\n GraphQLInputObjectType,\n {\n description: build.wrapDescription(\n `An input representation of \\`${tableTypeName}\\` with nullable fields.`,\n \"type\"\n ),\n name: inflection.baseInputType(TableType),\n },\n {\n __origin: `Adding table base input 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 isPgRowType: table.isSelectable,\n isPgCompoundType: !table.isSelectable,\n isPgBaseInput: true,\n pgAddSubfield(\n fieldName,\n attrName,\n pgType,\n spec,\n typeModifier\n ) {\n pgBaseInputFields[fieldName] = {\n name: attrName,\n type: pgType,\n typeModifier,\n };\n return spec;\n },\n }\n );\n }\n\n pg2GqlMapper[tablePgType.id] = {\n map: _ => _,\n unmap: (obj, modifier) => {\n let fieldLookup;\n if (modifier === \"patch\") {\n fieldLookup = pgPatchInputFields;\n } else if (modifier === \"base\") {\n fieldLookup = pgBaseInputFields;\n } else {\n fieldLookup = pgCreateInputFields;\n }\n\n const attr2sql = attr => {\n // TODO: this should use `fieldInput[*].name` to find the attribute\n const fieldName = inflection.column(attr);\n const inputField = fieldLookup[fieldName];\n const v = obj[fieldName];\n if (inputField && v != null) {\n const { type, typeModifier } = inputField;\n return sql.fragment`${gql2pg(v, type, typeModifier)}::${\n type.isFake\n ? sql.identifier(\"unknown\")\n : sql.identifier(type.namespaceName, type.name)\n }`;\n } else {\n return sql.null; // TODO: return default instead.\n }\n };\n\n return sql.fragment`row(${sql.join(\n attributes.map(attr2sql),\n \",\"\n )})::${\n tablePgType.isFake\n ? sql.identifier(\"unknown\")\n : sql.identifier(\n tablePgType.namespaceName,\n tablePgType.name\n )\n }`;\n },\n };\n\n const EdgeType = newWithHooks(\n GraphQLObjectType,\n {\n description: build.wrapDescription(\n `A \\`${tableTypeName}\\` edge in the connection.`,\n \"type\"\n ),\n name: inflection.edge(TableType.name),\n fields: ({ fieldWithHooks }) => {\n return {\n cursor: fieldWithHooks(\n \"cursor\",\n ({ addDataGenerator }) => {\n addDataGenerator(() => ({\n usesCursor: [true],\n pgQuery: queryBuilder => {\n if (primaryKeys) {\n queryBuilder.selectIdentifiers(table);\n }\n },\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 (\n data.__cursor &&\n base64(JSON.stringify(data.__cursor))\n );\n },\n };\n },\n {\n isCursorField: true,\n }\n ),\n node: pgField(\n build,\n fieldWithHooks,\n \"node\",\n {\n description: build.wrapDescription(\n `The \\`${tableTypeName}\\` at the end of the edge.`,\n \"field\"\n ),\n type: nullableIf(\n !pgForbidSetofFunctionsToReturnNull,\n TableType\n ),\n resolve(data, _args, resolveContext, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n const record = handleNullRow(\n data[safeAlias],\n data.__identifiers\n );\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n if (\n record &&\n primaryKeys &&\n liveRecord &&\n data.__identifiers\n ) {\n liveRecord(\"pg\", table, data.__identifiers);\n }\n return record;\n },\n },\n {},\n false,\n {\n withQueryBuilder: queryBuilder => {\n if (subscriptions) {\n queryBuilder.selectIdentifiers(table);\n }\n },\n }\n ),\n };\n },\n },\n {\n __origin: `Adding table edge 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 isEdgeType: true,\n isPgRowEdgeType: true,\n nodeType: TableType,\n pgIntrospection: table,\n }\n );\n const PageInfo = getTypeByName(inflection.builtin(\"PageInfo\"));\n\n /*const ConnectionType = */\n newWithHooks(\n GraphQLObjectType,\n {\n description: build.wrapDescription(\n `A connection to a list of \\`${tableTypeName}\\` values.`,\n \"type\"\n ),\n name: inflection.connection(TableType.name),\n fields: ({ recurseDataGeneratorsForField, fieldWithHooks }) => {\n recurseDataGeneratorsForField(\"pageInfo\", true);\n return {\n nodes: pgField(\n build,\n fieldWithHooks,\n \"nodes\",\n {\n description: build.wrapDescription(\n `A list of \\`${tableTypeName}\\` objects.`,\n \"field\"\n ),\n type: new GraphQLNonNull(\n new GraphQLList(\n nullableIf(\n !pgForbidSetofFunctionsToReturnNull,\n TableType\n )\n )\n ),\n resolve(data, _args, resolveContext, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n const liveRecord =\n resolveInfo.rootValue &&\n resolveInfo.rootValue.liveRecord;\n return data.data.map(entry => {\n const record = handleNullRow(\n entry[safeAlias],\n entry[safeAlias].__identifiers\n );\n if (\n record &&\n liveRecord &&\n primaryKeys &&\n entry[safeAlias].__identifiers\n ) {\n liveRecord(\n \"pg\",\n table,\n entry[safeAlias].__identifiers\n );\n }\n\n return record;\n });\n },\n },\n {},\n false,\n {\n withQueryBuilder: queryBuilder => {\n if (subscriptions) {\n queryBuilder.selectIdentifiers(table);\n }\n },\n }\n ),\n edges: pgField(\n build,\n fieldWithHooks,\n \"edges\",\n {\n description: build.wrapDescription(\n `A list of edges which contains the \\`${tableTypeName}\\` and cursor to aid in pagination.`,\n \"field\"\n ),\n type: new GraphQLNonNull(\n new GraphQLList(new GraphQLNonNull(EdgeType))\n ),\n resolve(data, _args, _context, resolveInfo) {\n const safeAlias = getSafeAliasFromResolveInfo(\n resolveInfo\n );\n return data.data.map(entry => ({\n ...entry,\n ...entry[safeAlias],\n }));\n },\n },\n {},\n false,\n {\n hoistCursor: true,\n }\n ),\n pageInfo: PageInfo && {\n description: build.wrapDescription(\n \"Information to aid in pagination.\",\n \"field\"\n ),\n type: new GraphQLNonNull(PageInfo),\n resolve(data) {\n return data;\n },\n },\n };\n },\n },\n {\n __origin: `Adding table connection 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 isConnectionType: true,\n isPgRowConnectionType: true,\n edgeType: EdgeType,\n nodeType: TableType,\n pgIntrospection: table,\n }\n );\n },\n true\n );\n pgRegisterGqlInputTypeByTypeId(\n tablePgType.id,\n (_set, modifier) => {\n // This must come first, it triggers creation of all the types\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n tablePgType.id,\n null\n );\n // This must come after the pgGetGqlTypeByTypeIdAndModifier call\n if (modifier === \"patch\") {\n // TODO: v5: move the definition from above down here\n return TablePatchType;\n }\n if (modifier === \"base\") {\n // TODO: v5: move the definition from above down here\n return TableBaseInputType;\n }\n if (TableType) {\n return getTypeByName(inflection.inputType(TableType));\n }\n return null;\n },\n true\n );\n\n if (arrayTablePgType) {\n // Note: these do not return\n //\n // `new GraphQLList(new GraphQLNonNull(...))`\n //\n // because it's possible to return null entries from postgresql\n // functions. We should probably add a flag to instead export\n // the non-null version as that's more typical.\n pgRegisterGqlTypeByTypeId(\n arrayTablePgType.id,\n () => {\n const TableType = pgGetGqlTypeByTypeIdAndModifier(\n tablePgType.id,\n null\n );\n return new GraphQLList(TableType);\n },\n true\n );\n pgRegisterGqlInputTypeByTypeId(\n arrayTablePgType.id,\n (_set, modifier) => {\n const RelevantTableInputType = pgGetGqlInputTypeByTypeIdAndModifier(\n tablePgType.id,\n modifier\n );\n if (RelevantTableInputType) {\n return new GraphQLList(RelevantTableInputType);\n }\n },\n true\n );\n }\n });\n return _;\n },\n [\"PgTables\"],\n [],\n [\"PgTypes\"]\n );\n}: Plugin);\n"],"file":"PgTablesPlugin.js"}
@@ -9,8 +9,6 @@ var _GraphQLJSON = _interopRequireDefault(require("../GraphQLJSON"));
9
9
 
10
10
  var _postgresInterval = require("../postgresInterval");
11
11
 
12
- var _lru = _interopRequireDefault(require("@graphile/lru"));
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
14
  function indent(str) {
@@ -21,22 +19,6 @@ function identity(value) {
21
19
  return value;
22
20
  }
23
21
 
24
- const parseCache = new _lru.default({
25
- maxLength: 500
26
- });
27
-
28
- function parseInterval(str) {
29
- let result = parseCache.get(str);
30
-
31
- if (!result) {
32
- result = (0, _postgresInterval.parseInterval)(str);
33
- Object.freeze(result);
34
- parseCache.set(str, result);
35
- }
36
-
37
- return result;
38
- }
39
-
40
22
  var PgTypesPlugin = function PgTypesPlugin(builder, {
41
23
  pgExtendedTypes = true,
42
24
  // Adding hstore support is technically a breaking change; this allows people to opt out easily:
@@ -154,7 +136,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
154
136
  throw new Error(`Expected array when converting GraphQL data into PostgreSQL data; failing type: '${type.namespaceName}.${type.name}' (type: ${type === null ? "null" : typeof type})`);
155
137
  }
156
138
 
157
- return sql.fragment`array[${sql.join(val.map(v => gql2pg(v, type.arrayItemType, modifier)), ", ")}]::${sql.identifier(type.namespaceName)}.${sql.identifier(type.name)}`;
139
+ return sql.fragment`array[${sql.join(val.map(v => gql2pg(v, type.arrayItemType, modifier)), ", ")}]::${type.isFake ? sql.identifier("unknown") : sql.identifier(type.namespaceName, type.name)}`;
158
140
  } else {
159
141
  return sql.value(val);
160
142
  }
@@ -163,27 +145,27 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
163
145
  const makeIntervalFields = () => {
164
146
  return {
165
147
  seconds: {
166
- description: "A quantity of seconds. This is the only non-integer field, as all the other fields will dump their overflow into a smaller unit of time. Intervals don’t have a smaller unit than seconds.",
148
+ description: build.wrapDescription("A quantity of seconds. This is the only non-integer field, as all the other fields will dump their overflow into a smaller unit of time. Intervals don’t have a smaller unit than seconds.", "field"),
167
149
  type: GraphQLFloat
168
150
  },
169
151
  minutes: {
170
- description: "A quantity of minutes.",
152
+ description: build.wrapDescription("A quantity of minutes.", "field"),
171
153
  type: GraphQLInt
172
154
  },
173
155
  hours: {
174
- description: "A quantity of hours.",
156
+ description: build.wrapDescription("A quantity of hours.", "field"),
175
157
  type: GraphQLInt
176
158
  },
177
159
  days: {
178
- description: "A quantity of days.",
160
+ description: build.wrapDescription("A quantity of days.", "field"),
179
161
  type: GraphQLInt
180
162
  },
181
163
  months: {
182
- description: "A quantity of months.",
164
+ description: build.wrapDescription("A quantity of months.", "field"),
183
165
  type: GraphQLInt
184
166
  },
185
167
  years: {
186
- description: "A quantity of years.",
168
+ description: build.wrapDescription("A quantity of years.", "field"),
187
169
  type: GraphQLInt
188
170
  }
189
171
  };
@@ -191,7 +173,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
191
173
 
192
174
  const GQLInterval = newWithHooks(GraphQLObjectType, {
193
175
  name: inflection.builtin("Interval"),
194
- description: "An interval of time that has passed where the smallest distinct unit is a second.",
176
+ description: build.wrapDescription("An interval of time that has passed where the smallest distinct unit is a second.", "type"),
195
177
  fields: makeIntervalFields()
196
178
  }, {
197
179
  isIntervalType: true
@@ -199,7 +181,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
199
181
  addType(GQLInterval, "graphile-build-pg built-in");
200
182
  const GQLIntervalInput = newWithHooks(GraphQLInputObjectType, {
201
183
  name: inflection.inputType(inflection.builtin("Interval")),
202
- description: "An interval of time that has passed where the smallest distinct unit is a second.",
184
+ description: build.wrapDescription("An interval of time that has passed where the smallest distinct unit is a second.", "type"),
203
185
  fields: makeIntervalFields()
204
186
  }, {
205
187
  isIntervalInputType: true
@@ -224,8 +206,8 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
224
206
  }
225
207
  });
226
208
 
227
- const BigFloat = stringType(inflection.builtin("BigFloat"), "A floating point number that requires more precision than IEEE 754 binary 64");
228
- const BitString = stringType(inflection.builtin("BitString"), "A string representing a series of binary bits");
209
+ const BigFloat = stringType(inflection.builtin("BigFloat"), build.wrapDescription("A floating point number that requires more precision than IEEE 754 binary 64", "type"));
210
+ const BitString = stringType(inflection.builtin("BitString"), build.wrapDescription("A string representing a series of binary bits", "type"));
229
211
  addType(BigFloat, "graphile-build-pg built-in");
230
212
  addType(BitString, "graphile-build-pg built-in");
231
213
  const rawTypes = [1186, // interval
@@ -336,31 +318,31 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
336
318
  */
337
319
 
338
320
 
339
- const SimpleDate = stringType(inflection.builtin("Date"), "The day, does not include a time.");
340
- const SimpleDatetime = stringType(inflection.builtin("Datetime"), "A point in time as described by the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard. May or may not include a timezone.");
341
- const SimpleTime = stringType(inflection.builtin("Time"), "The exact time of day, does not include the date. May or may not have a timezone offset.");
342
- const SimpleJSON = stringType(inflection.builtin("JSON"), "A JavaScript object encoded in the JSON format as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).");
343
- const SimpleUUID = stringType(inflection.builtin("UUID"), "A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).", string => {
321
+ const SimpleDate = stringType(inflection.builtin("Date"), build.wrapDescription("The day, does not include a time.", "type"));
322
+ const SimpleDatetime = stringType(inflection.builtin("Datetime"), build.wrapDescription("A point in time as described by the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard. May or may not include a timezone.", "type"));
323
+ const SimpleTime = stringType(inflection.builtin("Time"), build.wrapDescription("The exact time of day, does not include the date. May or may not have a timezone offset.", "type"));
324
+ const SimpleJSON = stringType(inflection.builtin("JSON"), build.wrapDescription("A JavaScript object encoded in the JSON format as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).", "type"));
325
+ const SimpleUUID = stringType(inflection.builtin("UUID"), build.wrapDescription("A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).", "type"), string => {
344
326
  if (!/^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i.test(string)) {
345
327
  throw new Error("Invalid UUID, expected 32 hexadecimal characters, optionally with hypens");
346
328
  }
347
329
 
348
330
  return string;
349
331
  });
350
- const InetType = stringType(inflection.builtin("InternetAddress"), "An IPv4 or IPv6 host address, and optionally its subnet.");
351
- const RegProcType = stringType(inflection.builtin("RegProc"), "A builtin object identifier type for a function name");
352
- const RegProcedureType = stringType(inflection.builtin("RegProcedure"), "A builtin object identifier type for a function with argument types");
353
- const RegOperType = stringType(inflection.builtin("RegOper"), "A builtin object identifier type for an operator");
354
- const RegOperatorType = stringType(inflection.builtin("RegOperator"), "A builtin object identifier type for an operator with argument types");
355
- const RegClassType = stringType(inflection.builtin("RegClass"), "A builtin object identifier type for a relation name");
356
- const RegTypeType = stringType(inflection.builtin("RegType"), "A builtin object identifier type for a data type name");
357
- const RegRoleType = stringType(inflection.builtin("RegRole"), "A builtin object identifier type for a role name");
358
- const RegNamespaceType = stringType(inflection.builtin("RegNamespace"), "A builtin object identifier type for a namespace name");
359
- const RegConfigType = stringType(inflection.builtin("RegConfig"), "A builtin object identifier type for a text search configuration");
360
- const RegDictionaryType = stringType(inflection.builtin("RegDictionary"), "A builtin object identifier type for a text search dictionary");
361
- const CidrType = pgUseCustomNetworkScalars ? stringType(inflection.builtin("CidrAddress"), "An IPv4 or IPv6 CIDR address.") : GraphQLString;
362
- const MacAddrType = pgUseCustomNetworkScalars ? stringType(inflection.builtin("MacAddress"), "A 6-byte MAC address.") : GraphQLString;
363
- const MacAddr8Type = pgUseCustomNetworkScalars ? stringType(inflection.builtin("MacAddress8"), "An 8-byte MAC address.") : GraphQLString; // pgExtendedTypes might change what types we use for things
332
+ const InetType = stringType(inflection.builtin("InternetAddress"), build.wrapDescription("An IPv4 or IPv6 host address, and optionally its subnet.", "type"));
333
+ const RegProcType = stringType(inflection.builtin("RegProc"), build.wrapDescription("A builtin object identifier type for a function name", "type"));
334
+ const RegProcedureType = stringType(inflection.builtin("RegProcedure"), build.wrapDescription("A builtin object identifier type for a function with argument types", "type"));
335
+ const RegOperType = stringType(inflection.builtin("RegOper"), build.wrapDescription("A builtin object identifier type for an operator", "type"));
336
+ const RegOperatorType = stringType(inflection.builtin("RegOperator"), build.wrapDescription("A builtin object identifier type for an operator with argument types", "type"));
337
+ const RegClassType = stringType(inflection.builtin("RegClass"), build.wrapDescription("A builtin object identifier type for a relation name", "type"));
338
+ const RegTypeType = stringType(inflection.builtin("RegType"), build.wrapDescription("A builtin object identifier type for a data type name", "type"));
339
+ const RegRoleType = stringType(inflection.builtin("RegRole"), build.wrapDescription("A builtin object identifier type for a role name", "type"));
340
+ const RegNamespaceType = stringType(inflection.builtin("RegNamespace"), build.wrapDescription("A builtin object identifier type for a namespace name", "type"));
341
+ const RegConfigType = stringType(inflection.builtin("RegConfig"), build.wrapDescription("A builtin object identifier type for a text search configuration", "type"));
342
+ const RegDictionaryType = stringType(inflection.builtin("RegDictionary"), build.wrapDescription("A builtin object identifier type for a text search dictionary", "type"));
343
+ const CidrType = pgUseCustomNetworkScalars ? stringType(inflection.builtin("CidrAddress"), build.wrapDescription("An IPv4 or IPv6 CIDR address.", "type")) : GraphQLString;
344
+ const MacAddrType = pgUseCustomNetworkScalars ? stringType(inflection.builtin("MacAddress"), build.wrapDescription("A 6-byte MAC address.", "type")) : GraphQLString;
345
+ const MacAddr8Type = pgUseCustomNetworkScalars ? stringType(inflection.builtin("MacAddress8"), build.wrapDescription("An 8-byte MAC address.", "type")) : GraphQLString; // pgExtendedTypes might change what types we use for things
364
346
 
365
347
  const JSONType = pgExtendedTypes ? (0, _GraphQLJSON.default)(graphql, inflection.builtin("JSON")) : SimpleJSON;
366
348
  const UUIDType = SimpleUUID; // GraphQLUUID
@@ -415,7 +397,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
415
397
  addType(RegConfigType, "graphile-build-pg built-in");
416
398
  addType(RegDictionaryType, "graphile-build-pg built-in");
417
399
  const oidLookup = {
418
- 20: stringType(inflection.builtin("BigInt"), "A signed eight-byte integer. The upper big integer values are greater than the max value for a JavaScript number. Therefore all big integers will be output as strings and not numbers."),
400
+ 20: stringType(inflection.builtin("BigInt"), build.wrapDescription("A signed eight-byte integer. The upper big integer values are greater than the max value for a JavaScript number. Therefore all big integers will be output as strings and not numbers.", "type")),
419
401
  // bitint - even though this is int8, it's too big for JS int, so cast to string.
420
402
  21: GraphQLInt,
421
403
  // int2
@@ -499,7 +481,7 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
499
481
  // interval
500
482
 
501
483
  pg2GqlMapper[1186] = {
502
- map: str => parseInterval(str),
484
+ map: str => (0, _postgresInterval.parseInterval)(str),
503
485
  unmap: o => {
504
486
  const keys = ["seconds", "minutes", "hours", "days", "months", "years"];
505
487
  const parts = [];
@@ -627,14 +609,14 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
627
609
  if (!Range) {
628
610
  const RangeBound = newWithHooks(GraphQLObjectType, {
629
611
  name: inflection.rangeBoundType(gqlRangeSubType.name),
630
- description: "The value at one end of a range. A range can either include this value, or not.",
612
+ description: build.wrapDescription("The value at one end of a range. A range can either include this value, or not.", "type"),
631
613
  fields: {
632
614
  value: {
633
- description: "The value at one end of our range.",
615
+ description: build.wrapDescription("The value at one end of our range.", "field"),
634
616
  type: new GraphQLNonNull(gqlRangeSubType)
635
617
  },
636
618
  inclusive: {
637
- description: "Whether or not the value of this bound is included in the range.",
619
+ description: build.wrapDescription("Whether or not the value of this bound is included in the range.", "field"),
638
620
  type: new GraphQLNonNull(GraphQLBoolean)
639
621
  }
640
622
  }
@@ -646,14 +628,14 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
646
628
  });
647
629
  const RangeBoundInput = newWithHooks(GraphQLInputObjectType, {
648
630
  name: inflection.inputType(RangeBound.name),
649
- description: "The value at one end of a range. A range can either include this value, or not.",
631
+ description: build.wrapDescription("The value at one end of a range. A range can either include this value, or not.", "type"),
650
632
  fields: {
651
633
  value: {
652
- description: "The value at one end of our range.",
634
+ description: build.wrapDescription("The value at one end of our range.", "field"),
653
635
  type: new GraphQLNonNull(gqlRangeInputSubType)
654
636
  },
655
637
  inclusive: {
656
- description: "Whether or not the value of this bound is included in the range.",
638
+ description: build.wrapDescription("Whether or not the value of this bound is included in the range.", "field"),
657
639
  type: new GraphQLNonNull(GraphQLBoolean)
658
640
  }
659
641
  }
@@ -665,14 +647,14 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
665
647
  });
666
648
  Range = newWithHooks(GraphQLObjectType, {
667
649
  name: inflection.rangeType(gqlRangeSubType.name),
668
- description: `A range of \`${gqlRangeSubType.name}\`.`,
650
+ description: build.wrapDescription(`A range of \`${gqlRangeSubType.name}\`.`, "type"),
669
651
  fields: {
670
652
  start: {
671
- description: "The starting bound of our range.",
653
+ description: build.wrapDescription("The starting bound of our range.", "field"),
672
654
  type: RangeBound
673
655
  },
674
656
  end: {
675
- description: "The ending bound of our range.",
657
+ description: build.wrapDescription("The ending bound of our range.", "field"),
676
658
  type: RangeBound
677
659
  }
678
660
  }
@@ -684,14 +666,14 @@ var PgTypesPlugin = function PgTypesPlugin(builder, {
684
666
  });
685
667
  RangeInput = newWithHooks(GraphQLInputObjectType, {
686
668
  name: inflection.inputType(Range.name),
687
- description: `A range of \`${gqlRangeSubType.name}\`.`,
669
+ description: build.wrapDescription(`A range of \`${gqlRangeSubType.name}\`.`, "type"),
688
670
  fields: {
689
671
  start: {
690
- description: "The starting bound of our range.",
672
+ description: build.wrapDescription("The starting bound of our range.", "field"),
691
673
  type: RangeBoundInput
692
674
  },
693
675
  end: {
694
- description: "The ending bound of our range.",
676
+ description: build.wrapDescription("The ending bound of our range.", "field"),
695
677
  type: RangeBoundInput
696
678
  }
697
679
  }
@@ -748,7 +730,7 @@ end`;
748
730
 
749
731
  if (!gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] && type.type === "d" && type.domainBaseTypeId) {
750
732
  const baseType = getGqlTypeByTypeIdAndModifier(type.domainBaseTypeId, typeModifier);
751
- const baseInputType = gqlInputTypeByTypeIdAndModifier[type.domainBaseTypeId][typeModifierKey]; // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16
733
+ const baseInputType = getGqlInputTypeByTypeIdAndModifier(type.domainBaseTypeId, typeModifier); // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16
752
734
 
753
735
  gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Object.assign(Object.create(baseType), {
754
736
  name: inflection.domainType(type),
@@ -1004,8 +986,7 @@ end`;
1004
986
  pgRegisterGqlTypeByTypeId,
1005
987
  pgRegisterGqlInputTypeByTypeId,
1006
988
  pg2GqlMapper,
1007
- pgSql: sql,
1008
- graphql
989
+ pgSql: sql
1009
990
  } = build; // Check we have the hstore extension
1010
991
 
1011
992
  const hstoreExtension = introspectionResultsByKind.extension.find(e => e.name === "hstore");
@@ -1025,7 +1006,7 @@ end`;
1025
1006
  // better validation; but you could just as easily use JSON directly if you
1026
1007
  // wanted to.
1027
1008
 
1028
- const GraphQLHStoreType = makeGraphQLHstoreType(graphql, hstoreTypeName); // Now register the hstore type with the type system for both output and input.
1009
+ const GraphQLHStoreType = makeGraphQLHstoreType(build, hstoreTypeName); // Now register the hstore type with the type system for both output and input.
1029
1010
 
1030
1011
  pgRegisterGqlTypeByTypeId(hstoreType.id, () => GraphQLHStoreType);
1031
1012
  pgRegisterGqlInputTypeByTypeId(hstoreType.id, () => GraphQLHStoreType); // Finally we must tell the system how to translate the data between PG-land and JS-land:
@@ -1078,7 +1059,7 @@ end`;
1078
1059
 
1079
1060
  return new GraphQLObjectType({
1080
1061
  name: inflection.builtin("Line"),
1081
- description: "An infinite line that passes through points 'a' and 'b'.",
1062
+ description: build.wrapDescription("An infinite line that passes through points 'a' and 'b'.", "type"),
1082
1063
  fields: {
1083
1064
  a: {
1084
1065
  type: Point
@@ -1093,7 +1074,7 @@ end`;
1093
1074
  const PointInput = pgGetGqlInputTypeByTypeIdAndModifier("600", null);
1094
1075
  return new GraphQLInputObjectType({
1095
1076
  name: inflection.builtin("LineInput"),
1096
- description: "An infinite line that passes through points 'a' and 'b'.",
1077
+ description: build.wrapDescription("An infinite line that passes through points 'a' and 'b'.", "type"),
1097
1078
  fields: {
1098
1079
  a: {
1099
1080
  type: PointInput
@@ -1129,7 +1110,7 @@ end`;
1129
1110
  const Point = pgGetGqlTypeByTypeIdAndModifier("600", null);
1130
1111
  return new GraphQLObjectType({
1131
1112
  name: inflection.builtin("LineSegment"),
1132
- description: "An finite line between points 'a' and 'b'.",
1113
+ description: build.wrapDescription("An finite line between points 'a' and 'b'.", "type"),
1133
1114
  fields: {
1134
1115
  a: {
1135
1116
  type: Point
@@ -1144,7 +1125,7 @@ end`;
1144
1125
  const PointInput = pgGetGqlInputTypeByTypeIdAndModifier("600", null);
1145
1126
  return new GraphQLInputObjectType({
1146
1127
  name: inflection.builtin("LineSegmentInput"),
1147
- description: "An finite line between points 'a' and 'b'.",
1128
+ description: build.wrapDescription("An finite line between points 'a' and 'b'.", "type"),
1148
1129
  fields: {
1149
1130
  a: {
1150
1131
  type: PointInput
@@ -1177,7 +1158,7 @@ end`;
1177
1158
  const Point = pgGetGqlTypeByTypeIdAndModifier("600", null);
1178
1159
  return new GraphQLObjectType({
1179
1160
  name: inflection.builtin("Box"),
1180
- description: "A rectangular box defined by two opposite corners 'a' and 'b'",
1161
+ description: build.wrapDescription("A rectangular box defined by two opposite corners 'a' and 'b'", "type"),
1181
1162
  fields: {
1182
1163
  a: {
1183
1164
  type: Point
@@ -1192,7 +1173,7 @@ end`;
1192
1173
  const PointInput = pgGetGqlInputTypeByTypeIdAndModifier("600", null);
1193
1174
  return new GraphQLInputObjectType({
1194
1175
  name: inflection.builtin("BoxInput"),
1195
- description: "A rectangular box defined by two opposite corners 'a' and 'b'",
1176
+ description: build.wrapDescription("A rectangular box defined by two opposite corners 'a' and 'b'", "type"),
1196
1177
  fields: {
1197
1178
  a: {
1198
1179
  type: PointInput
@@ -1225,13 +1206,13 @@ end`;
1225
1206
  const Point = pgGetGqlTypeByTypeIdAndModifier("600", null);
1226
1207
  return new GraphQLObjectType({
1227
1208
  name: inflection.builtin("Path"),
1228
- description: "A path (open or closed) made up of points",
1209
+ description: build.wrapDescription("A path (open or closed) made up of points", "type"),
1229
1210
  fields: {
1230
1211
  points: {
1231
1212
  type: new GraphQLList(Point)
1232
1213
  },
1233
1214
  isOpen: {
1234
- description: "True if this is a closed path (similar to a polygon), false otherwise.",
1215
+ description: build.wrapDescription("True if this is a closed path (similar to a polygon), false otherwise.", "field"),
1235
1216
  type: GraphQLBoolean
1236
1217
  }
1237
1218
  }
@@ -1241,13 +1222,13 @@ end`;
1241
1222
  const PointInput = pgGetGqlInputTypeByTypeIdAndModifier("600", null);
1242
1223
  return new GraphQLInputObjectType({
1243
1224
  name: inflection.builtin("PathInput"),
1244
- description: "A path (open or closed) made up of points",
1225
+ description: build.wrapDescription("A path (open or closed) made up of points", "type"),
1245
1226
  fields: {
1246
1227
  points: {
1247
1228
  type: new GraphQLList(PointInput)
1248
1229
  },
1249
1230
  isOpen: {
1250
- description: "True if this is a closed path (similar to a polygon), false otherwise.",
1231
+ description: build.wrapDescription("True if this is a closed path (similar to a polygon), false otherwise.", "field"),
1251
1232
  type: GraphQLBoolean
1252
1233
  }
1253
1234
  }
@@ -1393,7 +1374,10 @@ end`;
1393
1374
 
1394
1375
  exports.default = PgTypesPlugin;
1395
1376
 
1396
- function makeGraphQLHstoreType(graphql, hstoreTypeName) {
1377
+ function makeGraphQLHstoreType(build, hstoreTypeName) {
1378
+ const {
1379
+ graphql
1380
+ } = build;
1397
1381
  const {
1398
1382
  GraphQLScalarType,
1399
1383
  Kind
@@ -1506,7 +1490,7 @@ function makeGraphQLHstoreType(graphql, hstoreTypeName) {
1506
1490
 
1507
1491
  const GraphQLHStore = new GraphQLScalarType({
1508
1492
  name: hstoreTypeName,
1509
- description: "A set of key/value pairs, keys are strings, values may be a string or null. Exposed as a JSON object.",
1493
+ description: build.wrapDescription("A set of key/value pairs, keys are strings, values may be a string or null. Exposed as a JSON object.", "type"),
1510
1494
  serialize: identity,
1511
1495
  parseValue: identityWithCheck,
1512
1496
  parseLiteral