graphile-build-pg 4.4.5 → 4.5.3
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.
- package/README.md +2 -1
- package/node8plus/QueryBuilder.d.ts +10 -2
- package/node8plus/QueryBuilder.js +80 -1
- package/node8plus/QueryBuilder.js.flow +75 -2
- package/node8plus/QueryBuilder.js.map +1 -1
- package/node8plus/index.d.ts +8 -0
- package/node8plus/index.js +7 -1
- package/node8plus/index.js.flow +6 -1
- package/node8plus/index.js.map +1 -1
- package/node8plus/plugins/PgBasicsPlugin.js +5 -3
- package/node8plus/plugins/PgBasicsPlugin.js.flow +2 -0
- package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
- package/node8plus/plugins/PgConnectionTotalCount.js +10 -4
- package/node8plus/plugins/PgConnectionTotalCount.js.flow +13 -9
- package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
- package/node8plus/plugins/PgIntrospectionPlugin.d.ts +48 -11
- package/node8plus/plugins/PgIntrospectionPlugin.js +53 -23
- package/node8plus/plugins/PgIntrospectionPlugin.js.flow +81 -25
- package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgJWTPlugin.js +6 -1
- package/node8plus/plugins/PgJWTPlugin.js.flow +7 -1
- package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +2 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +3 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +1 -0
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.flow +1 -0
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +1 -0
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.flow +1 -0
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgTypesPlugin.js +9 -2
- package/node8plus/plugins/PgTypesPlugin.js.flow +19 -0
- package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
- package/node8plus/plugins/introspectionQuery.js +1 -0
- package/node8plus/plugins/introspectionQuery.js.flow +1 -0
- package/node8plus/plugins/introspectionQuery.js.map +1 -1
- package/node8plus/queryFromResolveDataFactory.js +8 -1
- package/node8plus/queryFromResolveDataFactory.js.flow +13 -1
- package/node8plus/queryFromResolveDataFactory.js.map +1 -1
- package/package.json +7 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/PgTypesPlugin.js"],"names":["indent","str","replace","identity","value","parseCache","LRU","maxLength","parseInterval","result","get","Object","freeze","set","PgTypesPlugin","builder","pgExtendedTypes","pgSkipHstore","disableIssue390Fix","hook","build","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgSql","sql","inflection","graphql","newWithHooks","args","addType","GraphQLNonNull","GraphQLString","GraphQLInt","GraphQLFloat","GraphQLBoolean","GraphQLList","GraphQLEnumType","GraphQLObjectType","GraphQLInputObjectType","GraphQLScalarType","isInputType","getNamedType","Kind","gqlTypeByTypeIdGenerator","gqlInputTypeByTypeIdGenerator","pgGqlTypeByTypeId","pgGqlInputTypeByTypeId","Error","gqlTypeByTypeIdAndModifier","pgGqlTypeByTypeIdAndModifier","gqlInputTypeByTypeIdAndModifier","pgGqlInputTypeByTypeIdAndModifier","isNull","val","__isNull","pg2GqlMapper","pg2gqlForType","type","id","map","domainBaseType","isPgArray","elementHandler","arrayItemType","Array","isArray","namespaceName","name","pg2gql","gql2pg","modifier","undefined","stack","e","console","warn","null","unmap","domainTypeModifier","fragment","join","v","identifier","makeIntervalFields","seconds","description","minutes","hours","days","months","years","GQLInterval","builtin","fields","isIntervalType","GQLIntervalInput","inputType","isIntervalInputType","stringType","serialize","String","parseValue","parseLiteral","ast","kind","STRING","BigFloat","BitString","rawTypes","tweakToJson","tweakToText","tweakToNumericText","pgTweaksByTypeIdAndModifer","pgTweaksByTypeId","reduce","memo","typeId","pgTweakFragmentForTypeAndModifier","typeModifier","resolveData","typeModifierKey","tweaker","domainBaseTypeModifier","error","process","env","NODE_ENV","SimpleDate","SimpleDatetime","SimpleTime","SimpleJSON","SimpleUUID","InetType","JSONType","UUIDType","DateType","DateTimeType","TimeType","Point","x","y","isPointType","PointInput","isPointInputType","oidLookup","oidInputLookup","jsonStringify","o","JSON","stringify","keys","parts","key","push","_","f","length","substr","split","parseFloat","depth","enforceGqlTypeByPgTypeId","find","t","reallyEnforceGqlTypeByPgTypeAndModifier","message","originalError","gqlType","gqlInputType","enumType","values","enumVariants","enumName","pgIntrospection","isPgEnumType","subtype","typeById","rangeSubTypeId","gqlRangeSubType","getGqlTypeByTypeIdAndModifier","Range","rangeType","RangeInput","RangeBound","rangeBoundType","inclusive","isPgRangeBoundType","pgSubtypeIntrospection","pgTypeModifier","RangeBoundInput","isPgRangeBoundInputType","start","end","isPgRangeType","isPgRangeInputType","lower","upper","lowerInclusive","upperInclusive","literal","domainBaseTypeId","baseType","baseInputType","assign","create","domainType","category","arrayEntryOutputType","arrayItemTypeId","arrayEntryInputType","getGqlInputTypeByTypeIdAndModifier","useFallback","gen","Type","fallback","registerGqlTypeByTypeId","yieldToExisting","registerGqlInputTypeByTypeId","getGqlTypeByTypeId","getGqlInputTypeByTypeId","pgTweakFragmentForType","extend","pgRegisterGqlTypeByTypeId","pgRegisterGqlInputTypeByTypeId","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","pgGetGqlTypeByTypeId","pgGetGqlInputTypeByTypeId","hstoreType","hstoreExtension","extension","namespaceId","hstoreTypeName","GraphQLHStoreType","makeGraphQLHstoreType","hstoreStringify","isValidHstoreObject","obj","identityWithCheck","TypeError","parseValueLiteral","variables","INT","FLOAT","NULL","VARIABLE","OBJECT","field","GraphQLHStore","toHstoreString","encodeKeyValue"],"mapp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,IAAI,EAAEqK,cADoC;AAE1CnJ,IAAAA,WAAW,EACT,uGAHwC;AAI1Cc,IAAAA,SAAS,EAAEjG,QAJ+B;AAK1CmG,IAAAA,UAAU,EAAEyI,iBAL8B;AAM1CxI,IAAAA;AAN0C,GAAtB,CAAtB;AAQA,SAAOkJ,aAAP;AACD,C,CAED;AACA;AACA;;;AACA,SAASC,cAAT,CAAwBzP,GAAxB,EAA6B;AAC3B,SAAO,MAAMA,GAAG,CAACC,OAAJ,CAAY,UAAZ,EAAwB,MAAxB,CAAN,GAAwC,GAA/C;AACD;;AAED,SAAS0O,eAAT,CAAyBxF,CAAzB,EAA4B;AAC1B,MAAIA,CAAC,KAAK,IAAV,EAAgB;AACd,WAAO,IAAP;AACD;;AACD,MAAI,OAAOA,CAAP,KAAa,QAAjB,EAA2B;AACzB,UAAM,IAAI4F,SAAJ,CAAc,2BAAd,CAAN;AACD;;AACD,QAAMzF,IAAI,GAAG5I,MAAM,CAAC4I,IAAP,CAAYH,CAAZ,CAAb;;AACA,QAAMuG,cAAc,GAAGlG,GAAG,IAAI;AAC5B,UAAMrJ,KAAK,GAAGgJ,CAAC,CAACK,GAAD,CAAf;;AACA,QAAIrJ,KAAK,KAAK,IAAd,EAAoB;AAClB,aAAQ,GAAEsP,cAAc,CAACjG,GAAD,CAAM,UAA9B;AACD,KAFD,MAEO;AACL,aAAQ,GAAEiG,cAAc,CAACjG,GAAD,CAAM,OAAMiG,cAAc,CAACrJ,MAAM,CAACjG,KAAD,CAAP,CAAgB,EAAlE;AACD;AACF,GAPD;;AAQA,SAAOmJ,IAAI,CAAC3F,GAAL,CAAS+L,cAAT,EAAyB1K,IAAzB,CAA8B,IAA9B,CAAP;AACD","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nimport makeGraphQLJSONType from \"../GraphQLJSON\";\n\nimport rawParseInterval from \"postgres-interval\";\nimport LRU from \"@graphile/lru\";\n\nfunction indent(str) {\n return \" \" + str.replace(/\\n/g, \"\\n \");\n}\n\nfunction identity(value) {\n return value;\n}\n\nconst parseCache = new LRU({ maxLength: 500 });\nfunction parseInterval(str) {\n let result = parseCache.get(str);\n if (!result) {\n result = rawParseInterval(str);\n Object.freeze(result);\n parseCache.set(str, result);\n }\n return result;\n}\n\nexport default (function PgTypesPlugin(\n builder,\n {\n pgExtendedTypes = true,\n // Adding hstore support is technically a breaking change; this allows people to opt out easily:\n pgSkipHstore = false,\n disableIssue390Fix = false,\n }\n) {\n // XXX: most of this should be in an \"init\" hook, not a \"build\" hook\n builder.hook(\n \"build\",\n build => {\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgSql: sql,\n inflection,\n graphql,\n } = build;\n\n /*\n * Note these do not do `foo.bind(build)` because they want to reference\n * the *latest* value of foo (i.e. after all the build hooks run) rather\n * than the current value of foo in this current hook.\n *\n * Also don't use this in your own code, only construct types *after* the\n * build hook has completed (i.e. 'init' or later).\n *\n * TODO:v5: move this to the 'init' hook.\n */\n const newWithHooks = (...args) => build.newWithHooks(...args);\n const addType = (...args) => build.addType(...args);\n\n const {\n GraphQLNonNull,\n GraphQLString,\n GraphQLInt,\n GraphQLFloat,\n GraphQLBoolean,\n GraphQLList,\n GraphQLEnumType,\n GraphQLObjectType,\n GraphQLInputObjectType,\n GraphQLScalarType,\n isInputType,\n getNamedType,\n Kind,\n } = graphql;\n\n const gqlTypeByTypeIdGenerator = {};\n const gqlInputTypeByTypeIdGenerator = {};\n if (build.pgGqlTypeByTypeId || build.pgGqlInputTypeByTypeId) {\n // I don't expect anyone to receive this error, because I don't think anyone uses this interface.\n throw new Error(\n \"Sorry! This interface is no longer supported because it is not granular enough. It's not hard to port it to the new system - please contact Benjie and he'll walk you through it.\"\n );\n }\n const gqlTypeByTypeIdAndModifier = {\n ...build.pgGqlTypeByTypeIdAndModifier,\n };\n const gqlInputTypeByTypeIdAndModifier = {\n ...build.pgGqlInputTypeByTypeIdAndModifier,\n };\n const isNull = val => val == null || val.__isNull;\n const pg2GqlMapper = {};\n const pg2gqlForType = type => {\n if (pg2GqlMapper[type.id]) {\n const map = pg2GqlMapper[type.id].map;\n return val => (isNull(val) ? null : map(val));\n } else if (type.domainBaseType) {\n return pg2gqlForType(type.domainBaseType);\n } else if (type.isPgArray) {\n const elementHandler = pg2gqlForType(type.arrayItemType);\n return val => {\n if (isNull(val)) return null;\n if (!Array.isArray(val)) {\n throw new Error(\n `Expected array when converting PostgreSQL data into GraphQL; failing type: '${type.namespaceName}.${type.name}'`\n );\n }\n return val.map(elementHandler);\n };\n } else {\n return identity;\n }\n };\n const pg2gql = (val, type) => pg2gqlForType(type)(val);\n const gql2pg = (val, type, modifier) => {\n if (modifier === undefined) {\n let stack;\n try {\n throw new Error();\n } catch (e) {\n stack = e.stack;\n }\n // eslint-disable-next-line no-console\n console.warn(\n \"gql2pg should be called with three arguments, the third being the type modifier (or `null`); \" +\n (stack || \"\")\n );\n // Hack for backwards compatibility:\n modifier = null;\n }\n if (val == null) {\n return sql.null;\n }\n if (pg2GqlMapper[type.id]) {\n return pg2GqlMapper[type.id].unmap(val, modifier);\n } else if (type.domainBaseType) {\n return gql2pg(val, type.domainBaseType, type.domainTypeModifier);\n } else if (type.isPgArray) {\n if (!Array.isArray(val)) {\n throw new Error(\n `Expected array when converting GraphQL data into PostgreSQL data; failing type: '${\n type.namespaceName\n }.${type.name}' (type: ${type === null ? \"null\" : typeof type})`\n );\n }\n return sql.fragment`array[${sql.join(\n val.map(v => gql2pg(v, type.arrayItemType, modifier)),\n \", \"\n )}]::${sql.identifier(type.namespaceName)}.${sql.identifier(\n type.name\n )}`;\n } else {\n return sql.value(val);\n }\n };\n\n const makeIntervalFields = () => {\n return {\n seconds: {\n description:\n \"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.\",\n type: GraphQLFloat,\n },\n minutes: {\n description: \"A quantity of minutes.\",\n type: GraphQLInt,\n },\n hours: {\n description: \"A quantity of hours.\",\n type: GraphQLInt,\n },\n days: {\n description: \"A quantity of days.\",\n type: GraphQLInt,\n },\n months: {\n description: \"A quantity of months.\",\n type: GraphQLInt,\n },\n years: {\n description: \"A quantity of years.\",\n type: GraphQLInt,\n },\n };\n };\n const GQLInterval = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.builtin(\"Interval\"),\n description:\n \"An interval of time that has passed where the smallest distinct unit is a second.\",\n fields: makeIntervalFields(),\n },\n {\n isIntervalType: true,\n }\n );\n addType(GQLInterval, \"graphile-build-pg built-in\");\n\n const GQLIntervalInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(inflection.builtin(\"Interval\")),\n description:\n \"An interval of time that has passed where the smallest distinct unit is a second.\",\n fields: makeIntervalFields(),\n },\n {\n isIntervalInputType: true,\n }\n );\n addType(GQLIntervalInput, \"graphile-build-pg built-in\");\n\n const stringType = (name, description) =>\n new GraphQLScalarType({\n name,\n description,\n serialize: value => String(value),\n parseValue: value => String(value),\n parseLiteral: ast => {\n if (ast.kind !== Kind.STRING) {\n throw new Error(\"Can only parse string values\");\n }\n return ast.value;\n },\n });\n\n const BigFloat = stringType(\n inflection.builtin(\"BigFloat\"),\n \"A floating point number that requires more precision than IEEE 754 binary 64\"\n );\n const BitString = stringType(\n inflection.builtin(\"BitString\"),\n \"A string representing a series of binary bits\"\n );\n addType(BigFloat, \"graphile-build-pg built-in\");\n addType(BitString, \"graphile-build-pg built-in\");\n\n const rawTypes = [\n 1186, // interval\n 1082, // date\n 1114, // timestamp\n 1184, // timestamptz\n 1083, // time\n 1266, // timetz\n ];\n\n const tweakToJson = fragment => fragment; // Since everything is to_json'd now, just pass through\n const tweakToText = fragment => sql.fragment`(${fragment})::text`;\n const tweakToNumericText = fragment =>\n sql.fragment`(${fragment})::numeric::text`;\n const pgTweaksByTypeIdAndModifer = {};\n const pgTweaksByTypeId = {\n // '::text' rawTypes\n ...rawTypes.reduce((memo, typeId) => {\n memo[typeId] = tweakToText;\n return memo;\n }, {}),\n\n // cast numbers above our ken to strings to avoid loss of precision\n \"20\": tweakToText,\n \"1700\": tweakToText,\n // to_json all dates to make them ISO (overrides rawTypes above)\n \"1082\": tweakToJson,\n \"1114\": tweakToJson,\n \"1184\": tweakToJson,\n \"1083\": tweakToJson,\n \"1266\": tweakToJson,\n \"790\": tweakToNumericText,\n };\n\n const pgTweakFragmentForTypeAndModifier = (\n fragment,\n type,\n typeModifier = null,\n resolveData\n ) => {\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n const tweaker =\n (pgTweaksByTypeIdAndModifer[type.id] &&\n pgTweaksByTypeIdAndModifer[type.id][typeModifierKey]) ||\n pgTweaksByTypeId[type.id];\n if (tweaker) {\n return tweaker(fragment, resolveData);\n } else if (type.domainBaseType) {\n // TODO: check that domains don't support atttypemod\n return pgTweakFragmentForTypeAndModifier(\n fragment,\n type.domainBaseType,\n type.domainBaseTypeModifier,\n resolveData\n );\n } else if (type.isPgArray) {\n const error = new Error(\n `Internal graphile-build-pg error: should not attempt to tweak an array, please process array before tweaking (type: \"${type.namespaceName}.${type.name}\")`\n );\n if (process.env.NODE_ENV === \"test\") {\n // This is to ensure that Graphile core does not introduce these problems\n throw error;\n }\n // eslint-disable-next-line no-console\n console.error(error);\n return fragment;\n } else {\n return fragment;\n }\n };\n /*\n Determined by running:\n\n select oid, typname, typarray, typcategory, typtype from pg_catalog.pg_type where typtype = 'b' order by oid;\n\n We only need to add oidLookups for types that don't have the correct fallback\n */\n const SimpleDate = stringType(\n inflection.builtin(\"Date\"),\n \"The day, does not include a time.\"\n );\n const SimpleDatetime = stringType(\n inflection.builtin(\"Datetime\"),\n \"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.\"\n );\n const SimpleTime = stringType(\n inflection.builtin(\"Time\"),\n \"The exact time of day, does not include the date. May or may not have a timezone offset.\"\n );\n const SimpleJSON = stringType(\n inflection.builtin(\"JSON\"),\n \"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).\"\n );\n const SimpleUUID = stringType(\n inflection.builtin(\"UUID\"),\n \"A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).\"\n );\n const InetType = stringType(\n inflection.builtin(\"InternetAddress\"),\n \"An IPv4 or IPv6 host address, and optionally its subnet.\"\n );\n\n // pgExtendedTypes might change what types we use for things\n const JSONType = pgExtendedTypes\n ? makeGraphQLJSONType(graphql, inflection.builtin(\"JSON\"))\n : SimpleJSON;\n const UUIDType = SimpleUUID; // GraphQLUUID\n const DateType = SimpleDate; // GraphQLDate\n const DateTimeType = SimpleDatetime; // GraphQLDateTime\n const TimeType = SimpleTime; // GraphQLTime\n\n // 'point' in PostgreSQL is a 16-byte type that's comprised of two 8-byte floats.\n const Point = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.builtin(\"Point\"),\n fields: {\n x: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n y: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n },\n },\n {\n isPointType: true,\n }\n );\n const PointInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(inflection.builtin(\"Point\")),\n fields: {\n x: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n y: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n },\n },\n {\n isPointInputType: true,\n }\n );\n\n // Other plugins might want to use JSON\n addType(JSONType, \"graphile-build-pg built-in\");\n addType(UUIDType, \"graphile-build-pg built-in\");\n addType(DateType, \"graphile-build-pg built-in\");\n addType(DateTimeType, \"graphile-build-pg built-in\");\n addType(TimeType, \"graphile-build-pg built-in\");\n\n const oidLookup = {\n \"20\": stringType(\n inflection.builtin(\"BigInt\"),\n \"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.\"\n ), // bitint - even though this is int8, it's too big for JS int, so cast to string.\n \"21\": GraphQLInt, // int2\n \"23\": GraphQLInt, // int4\n \"700\": GraphQLFloat, // float4\n \"701\": GraphQLFloat, // float8\n \"1700\": BigFloat, // numeric\n \"790\": GraphQLFloat, // money\n\n \"1186\": GQLInterval, // interval\n \"1082\": DateType, // date\n \"1114\": DateTimeType, // timestamp\n \"1184\": DateTimeType, // timestamptz\n \"1083\": TimeType, // time\n \"1266\": TimeType, // timetz\n\n \"114\": JSONType, // json\n \"3802\": JSONType, // jsonb\n \"2950\": UUIDType, // uuid\n\n \"1560\": BitString, // bit\n \"1562\": BitString, // varbit\n\n \"18\": GraphQLString, // char\n \"25\": GraphQLString, // text\n \"1043\": GraphQLString, // varchar\n\n \"600\": Point, // point\n\n \"869\": InetType,\n };\n const oidInputLookup = {\n \"1186\": GQLIntervalInput, // interval\n \"600\": PointInput, // point\n };\n const jsonStringify = o => JSON.stringify(o);\n if (pgExtendedTypes) {\n pg2GqlMapper[114] = {\n map: identity,\n unmap: o => sql.value(jsonStringify(o)),\n };\n } else {\n pg2GqlMapper[114] = {\n map: jsonStringify,\n unmap: str => sql.value(str),\n };\n }\n pg2GqlMapper[3802] = pg2GqlMapper[114]; // jsonb\n\n // interval\n pg2GqlMapper[1186] = {\n map: str => parseInterval(str),\n unmap: o => {\n const keys = [\n \"seconds\",\n \"minutes\",\n \"hours\",\n \"days\",\n \"months\",\n \"years\",\n ];\n const parts = [];\n for (const key of keys) {\n if (o[key]) {\n parts.push(`${o[key]} ${key}`);\n }\n }\n return sql.value(parts.join(\" \") || \"0 seconds\");\n },\n };\n\n pg2GqlMapper[790] = {\n map: _ => _,\n unmap: val => sql.fragment`(${sql.value(val)})::money`,\n };\n\n // point\n pg2GqlMapper[600] = {\n map: f => {\n if (f[0] === \"(\" && f[f.length - 1] === \")\") {\n const [x, y] = f\n .substr(1, f.length - 2)\n .split(\",\")\n .map(f => parseFloat(f));\n return { x, y };\n }\n },\n unmap: o => sql.fragment`point(${sql.value(o.x)}, ${sql.value(o.y)})`,\n };\n\n // TODO: add more support for geometric types\n\n let depth = 0;\n\n /*\n * Enforce: this is the fallback when we can't find a specific GraphQL type\n * for a specific PG type. Use the generators from\n * `pgRegisterGqlTypeByTypeId` first, this is a last resort.\n */\n const enforceGqlTypeByPgTypeId = (typeId, typeModifier) => {\n const type = introspectionResultsByKind.type.find(t => t.id === typeId);\n depth++;\n if (depth > 50) {\n throw new Error(\"Type enforcement went too deep - infinite loop?\");\n }\n try {\n return reallyEnforceGqlTypeByPgTypeAndModifier(type, typeModifier);\n } catch (e) {\n const error = new Error(\n `Error occurred when processing database type '${\n type.namespaceName\n }.${type.name}' (type=${type.type}):\\n${indent(e.message)}`\n );\n // $FlowFixMe\n error.originalError = e;\n throw error;\n } finally {\n depth--;\n }\n };\n const reallyEnforceGqlTypeByPgTypeAndModifier = (type, typeModifier) => {\n if (!type.id) {\n throw new Error(\n `Invalid argument to enforceGqlTypeByPgTypeId - expected a full type, received '${type}'`\n );\n }\n if (!gqlTypeByTypeIdAndModifier[type.id]) {\n gqlTypeByTypeIdAndModifier[type.id] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[type.id]) {\n gqlInputTypeByTypeIdAndModifier[type.id] = {};\n }\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n // Explicit overrides\n if (!gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n const gqlType = oidLookup[type.id];\n if (gqlType) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = gqlType;\n }\n }\n if (!gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n const gqlInputType = oidInputLookup[type.id];\n if (gqlInputType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = gqlInputType;\n }\n }\n // Enums\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"e\"\n ) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = newWithHooks(\n GraphQLEnumType,\n {\n name: inflection.enumType(type),\n description: type.description,\n values: type.enumVariants.reduce((memo, value) => {\n memo[inflection.enumName(value)] = {\n value: value,\n };\n return memo;\n }, {}),\n },\n {\n pgIntrospection: type,\n isPgEnumType: true,\n }\n );\n }\n // Ranges\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"r\"\n ) {\n const subtype =\n introspectionResultsByKind.typeById[type.rangeSubTypeId];\n const gqlRangeSubType = getGqlTypeByTypeIdAndModifier(\n subtype.id,\n typeModifier\n );\n if (!gqlRangeSubType) {\n throw new Error(\"Range of unsupported\");\n }\n let Range = getTypeByName(inflection.rangeType(gqlRangeSubType.name));\n let RangeInput;\n if (!Range) {\n const RangeBound = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.rangeBoundType(gqlRangeSubType.name),\n description:\n \"The value at one end of a range. A range can either include this value, or not.\",\n fields: {\n value: {\n description: \"The value at one end of our range.\",\n type: new GraphQLNonNull(gqlRangeSubType),\n },\n inclusive: {\n description:\n \"Whether or not the value of this bound is included in the range.\",\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n },\n {\n isPgRangeBoundType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n const RangeBoundInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(RangeBound.name),\n description:\n \"The value at one end of a range. A range can either include this value, or not.\",\n fields: {\n value: {\n description: \"The value at one end of our range.\",\n type: new GraphQLNonNull(gqlRangeSubType),\n },\n inclusive: {\n description:\n \"Whether or not the value of this bound is included in the range.\",\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n },\n {\n isPgRangeBoundInputType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n Range = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.rangeType(gqlRangeSubType.name),\n description: `A range of \\`${gqlRangeSubType.name}\\`.`,\n fields: {\n start: {\n description: \"The starting bound of our range.\",\n type: RangeBound,\n },\n end: {\n description: \"The ending bound of our range.\",\n type: RangeBound,\n },\n },\n },\n {\n isPgRangeType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n RangeInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(Range.name),\n description: `A range of \\`${gqlRangeSubType.name}\\`.`,\n fields: {\n start: {\n description: \"The starting bound of our range.\",\n type: RangeBoundInput,\n },\n end: {\n description: \"The ending bound of our range.\",\n type: RangeBoundInput,\n },\n },\n },\n {\n isPgRangeInputType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n addType(Range, \"graphile-build-pg built-in\");\n addType(RangeInput, \"graphile-build-pg built-in\");\n } else {\n RangeInput = getTypeByName(inflection.inputType(Range.name));\n }\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Range;\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = RangeInput;\n if (pgTweaksByTypeIdAndModifer[type.id] === undefined) {\n pgTweaksByTypeIdAndModifer[type.id] = {};\n }\n pgTweaksByTypeIdAndModifer[type.id][\n typeModifierKey\n ] = fragment => sql.fragment`\\\ncase\nwhen (${fragment}) is null then null\nelse json_build_object(\n 'start',\n case when lower(${fragment}) is null then null\n else json_build_object('value', ${pgTweakFragmentForTypeAndModifier(\n sql.fragment`lower(${fragment})`,\n subtype,\n typeModifier,\n {}\n )}, 'inclusive', lower_inc(${fragment}))\n end,\n 'end',\n case when upper(${fragment}) is null then null\n else json_build_object('value', ${pgTweakFragmentForTypeAndModifier(\n sql.fragment`upper(${fragment})`,\n subtype,\n typeModifier,\n {}\n )}, 'inclusive', upper_inc(${fragment}))\n end\n)\nend`;\n pg2GqlMapper[type.id] = {\n map: identity,\n unmap: ({ start, end }) => {\n // Ref: https://www.postgresql.org/docs/9.6/static/rangetypes.html#RANGETYPES-CONSTRUCT\n const lower =\n (start && gql2pg(start.value, subtype, null)) || sql.null;\n const upper =\n (end && gql2pg(end.value, subtype, null)) || sql.null;\n const lowerInclusive = start && !start.inclusive ? \"(\" : \"[\";\n const upperInclusive = end && !end.inclusive ? \")\" : \"]\";\n return sql.fragment`${sql.identifier(\n type.namespaceName,\n type.name\n )}(${lower}, ${upper}, ${sql.literal(\n lowerInclusive + upperInclusive\n )})`;\n },\n };\n }\n\n // Domains\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"d\" &&\n type.domainBaseTypeId\n ) {\n const baseType = getGqlTypeByTypeIdAndModifier(\n type.domainBaseTypeId,\n typeModifier\n );\n const baseInputType =\n gqlInputTypeByTypeIdAndModifier[type.domainBaseTypeId][\n typeModifierKey\n ];\n // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Object.assign(\n Object.create(baseType),\n {\n name: inflection.domainType(type),\n description: type.description,\n }\n );\n if (baseInputType && baseInputType !== baseType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = Object.assign(Object.create(baseInputType), {\n name: inflection.inputType(\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]\n ),\n description: type.description,\n });\n }\n }\n\n // Arrays\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"A\"\n ) {\n const arrayEntryOutputType = getGqlTypeByTypeIdAndModifier(\n type.arrayItemTypeId,\n typeModifier\n );\n gqlTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = new GraphQLList(arrayEntryOutputType);\n if (!disableIssue390Fix) {\n const arrayEntryInputType = getGqlInputTypeByTypeIdAndModifier(\n type.arrayItemTypeId,\n typeModifier\n );\n if (arrayEntryInputType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = new GraphQLList(arrayEntryInputType);\n }\n }\n }\n\n // Booleans\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"B\"\n ) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = GraphQLBoolean;\n }\n\n // Numbers may be too large for GraphQL/JS to handle, so stringify by\n // default.\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"N\"\n ) {\n pgTweaksByTypeId[type.id] = tweakToText;\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = BigFloat;\n }\n\n // Nothing else worked; pass through as string!\n if (!gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n // XXX: consider using stringType(upperFirst(camelCase(`fallback_${type.name}`)), type.description)?\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = GraphQLString;\n }\n // Now for input types, fall back to output types if possible\n if (!gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n if (\n isInputType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])\n ) {\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] =\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];\n }\n }\n addType(\n getNamedType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])\n );\n return gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];\n };\n\n function getGqlTypeByTypeIdAndModifier(\n typeId,\n typeModifier = null,\n useFallback = true\n ) {\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n if (!gqlTypeByTypeIdAndModifier[typeId]) {\n gqlTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[typeId]) {\n gqlInputTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlTypeByTypeIdAndModifier[typeId][typeModifierKey]) {\n const type = introspectionResultsByKind.type.find(\n t => t.id === typeId\n );\n if (!type) {\n throw new Error(\n `Type '${typeId}' not present in introspection results`\n );\n }\n const gen = gqlTypeByTypeIdGenerator[type.id];\n if (gen) {\n const set = Type => {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Type;\n };\n const result = gen(set, typeModifier);\n if (result) {\n if (\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] !== result\n ) {\n throw new Error(\n `Callback and return types differ when defining type for '${type.id}'`\n );\n }\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = result;\n }\n }\n }\n if (\n !gqlTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n typeModifierKey > -1\n ) {\n // Fall back to `null` modifier, but if that still doesn't work, we\n // still want to pass the modifier to enforceGqlTypeByPgTypeId.\n const fallback = getGqlTypeByTypeIdAndModifier(typeId, null, false);\n if (fallback) {\n return fallback;\n }\n }\n if (\n useFallback &&\n !gqlTypeByTypeIdAndModifier[typeId][typeModifierKey]\n ) {\n return enforceGqlTypeByPgTypeId(typeId, typeModifier);\n }\n return gqlTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n\n function getGqlInputTypeByTypeIdAndModifier(typeId, typeModifier = null) {\n // First, load the OUTPUT type (it might register an input type)\n getGqlTypeByTypeIdAndModifier(typeId, typeModifier);\n\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n if (!gqlInputTypeByTypeIdAndModifier[typeId]) {\n gqlInputTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey]) {\n const type = introspectionResultsByKind.typeById[typeId];\n\n if (!type) {\n throw new Error(\n `Type '${typeId}' not present in introspection results`\n );\n }\n const gen = gqlInputTypeByTypeIdGenerator[type.id];\n if (gen) {\n const set = Type => {\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] = Type;\n };\n const result = gen(set, typeModifier);\n if (result) {\n if (\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] !==\n result\n ) {\n throw new Error(\n `Callback and return types differ when defining type for '${type.id}'`\n );\n }\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = result;\n }\n }\n }\n // Use the same type as the output type if it's valid input\n if (\n !gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n gqlTypeByTypeIdAndModifier[typeId] &&\n gqlTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n isInputType(gqlTypeByTypeIdAndModifier[typeId][typeModifierKey])\n ) {\n gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] =\n gqlTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n if (\n !gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n typeModifierKey > -1\n ) {\n // Fall back to default\n return getGqlInputTypeByTypeIdAndModifier(typeId, null);\n }\n return gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n function registerGqlTypeByTypeId(typeId, gen, yieldToExisting = false) {\n if (gqlTypeByTypeIdGenerator[typeId]) {\n if (yieldToExisting) {\n return;\n }\n throw new Error(\n `There's already a type generator registered for '${typeId}'`\n );\n }\n gqlTypeByTypeIdGenerator[typeId] = gen;\n }\n function registerGqlInputTypeByTypeId(\n typeId,\n gen,\n yieldToExisting = false\n ) {\n if (gqlInputTypeByTypeIdGenerator[typeId]) {\n if (yieldToExisting) {\n return;\n }\n throw new Error(\n `There's already an input type generator registered for '${typeId}'`\n );\n }\n gqlInputTypeByTypeIdGenerator[typeId] = gen;\n }\n\n // DEPRECATIONS!\n function getGqlTypeByTypeId(typeId, typeModifier) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: getGqlTypeByTypeId should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the second parameter (or null if it's not available).\"\n );\n }\n return getGqlTypeByTypeIdAndModifier(typeId, typeModifier);\n }\n function getGqlInputTypeByTypeId(typeId, typeModifier) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: getGqlInputTypeByTypeId should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the second parameter (or null if it's not available).\"\n );\n }\n return getGqlInputTypeByTypeIdAndModifier(typeId, typeModifier);\n }\n function pgTweakFragmentForType(\n fragment,\n type,\n typeModifier,\n resolveData\n ) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: pgTweakFragmentForType should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the third parameter (or null if it's not available).\"\n );\n }\n return pgTweakFragmentForTypeAndModifier(\n fragment,\n type,\n typeModifier,\n resolveData\n );\n }\n // END OF DEPRECATIONS!\n\n return build.extend(build, {\n pgRegisterGqlTypeByTypeId: registerGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId: registerGqlInputTypeByTypeId,\n pgGetGqlTypeByTypeIdAndModifier: getGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier: getGqlInputTypeByTypeIdAndModifier,\n pg2GqlMapper,\n pg2gql,\n pg2gqlForType,\n gql2pg,\n pgTweakFragmentForTypeAndModifier,\n pgTweaksByTypeId,\n pgTweaksByTypeIdAndModifer,\n\n // DEPRECATED METHODS:\n pgGetGqlTypeByTypeId: getGqlTypeByTypeId, // DEPRECATED, replaced by getGqlTypeByTypeIdAndModifier\n pgGetGqlInputTypeByTypeId: getGqlInputTypeByTypeId, // DEPRECATED, replaced by getGqlInputTypeByTypeIdAndModifier\n pgTweakFragmentForType, // DEPRECATED, replaced by pgTweakFragmentForTypeAndModifier\n });\n },\n [\"PgTypes\"],\n [],\n [\"PgIntrospection\", \"StandardTypes\"]\n );\n\n /* Start of hstore type */\n builder.hook(\n \"inflection\",\n (inflection, build) => {\n // This hook allows you to append a plugin which renames the KeyValueHash\n // (hstore) type name.\n if (pgSkipHstore) return build;\n return build.extend(inflection, {\n hstoreType() {\n return \"KeyValueHash\";\n },\n });\n },\n [\"PgTypesHstore\"]\n );\n builder.hook(\n \"build\",\n build => {\n // This hook tells graphile-build-pg about the hstore database type so it\n // knows how to express it in input/output.\n if (pgSkipHstore) return build;\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgRegisterGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId,\n pg2GqlMapper,\n pgSql: sql,\n graphql,\n } = build;\n\n // Check we have the hstore extension\n const hstoreExtension = introspectionResultsByKind.extension.find(\n e => e.name === \"hstore\"\n );\n if (!hstoreExtension) {\n return build;\n }\n\n // Get the 'hstore' type itself:\n const hstoreType = introspectionResultsByKind.type.find(\n t =>\n t.name === \"hstore\" && t.namespaceId === hstoreExtension.namespaceId\n );\n if (!hstoreType) {\n return build;\n }\n\n const hstoreTypeName = build.inflection.hstoreType();\n\n // We're going to use our own special HStore type for this so that we get\n // better validation; but you could just as easily use JSON directly if you\n // wanted to.\n const GraphQLHStoreType = makeGraphQLHstoreType(graphql, hstoreTypeName);\n\n // Now register the hstore type with the type system for both output and input.\n pgRegisterGqlTypeByTypeId(hstoreType.id, () => GraphQLHStoreType);\n pgRegisterGqlInputTypeByTypeId(hstoreType.id, () => GraphQLHStoreType);\n\n // Finally we must tell the system how to translate the data between PG-land and JS-land:\n pg2GqlMapper[hstoreType.id] = {\n // node-postgres parses hstore for us, no action required on map\n map: identity,\n // When unmapping we need to convert back to hstore\n unmap: o =>\n sql.fragment`(${sql.value(hstoreStringify(o))}::${sql.identifier(\n hstoreType.namespaceName,\n hstoreType.name\n )})`,\n };\n\n return build;\n },\n [\"PgTypesHstore\"],\n [],\n [\"PgTypes\"]\n );\n /* End of hstore type */\n}: Plugin);\n\nfunction makeGraphQLHstoreType(graphql, hstoreTypeName) {\n const { GraphQLScalarType, Kind } = graphql;\n\n function isValidHstoreObject(obj) {\n if (obj === null) {\n // Null is okay\n return true;\n } else if (typeof obj === \"object\") {\n // A hash with string/null values is also okay\n const keys = Object.keys(obj);\n for (const key of keys) {\n const val = obj[key];\n if (val === null) {\n // Null is okay\n } else if (typeof val === \"string\") {\n // String is okay\n } else {\n // Everything else is invalid.\n return false;\n }\n }\n return true;\n } else {\n // Everything else is invalid.\n return false;\n }\n }\n\n function identityWithCheck(obj) {\n if (isValidHstoreObject(obj)) {\n return obj;\n }\n throw new TypeError(\n `This is not a valid ${hstoreTypeName} object, it must be a key/value hash where keys and values are both strings (or null).`\n );\n }\n\n function parseValueLiteral(ast, variables) {\n switch (ast.kind) {\n case Kind.INT:\n case Kind.FLOAT:\n // Number isn't really okay, but we'll coerce it to a string anyway.\n return String(parseFloat(ast.value));\n case Kind.STRING:\n // String is okay.\n return String(ast.value);\n case Kind.NULL:\n // Null is okay.\n return null;\n case Kind.VARIABLE: {\n // Variable is okay if that variable is either a string or null.\n const name = ast.name.value;\n const value = variables ? variables[name] : undefined;\n if (value === null || typeof value === \"string\") {\n return value;\n }\n return undefined;\n }\n default:\n // Everything else is invalid.\n return undefined;\n }\n }\n\n function parseLiteral(ast, variables) {\n switch (ast.kind) {\n case Kind.OBJECT: {\n const value = ast.fields.reduce((memo, field) => {\n memo[field.name.value] = parseValueLiteral(field.value, variables);\n return memo;\n }, Object.create(null));\n\n if (!isValidHstoreObject(value)) {\n return undefined;\n }\n return value;\n }\n\n case Kind.NULL:\n return null;\n\n case Kind.VARIABLE: {\n const name = ast.name.value;\n const value = variables ? variables[name] : undefined;\n\n if (!isValidHstoreObject(value)) {\n return undefined;\n }\n return value;\n }\n\n default:\n return undefined;\n }\n }\n\n // TODO: use newWithHooks instead\n const GraphQLHStore = new GraphQLScalarType({\n name: hstoreTypeName,\n description:\n \"A set of key/value pairs, keys are strings, values may be a string or null. Exposed as a JSON object.\",\n serialize: identity,\n parseValue: identityWithCheck,\n parseLiteral,\n });\n return GraphQLHStore;\n}\n\n// To include a double quote or a backslash in a key or value, escape it\n// with a backslash.\n// -- https://www.postgresql.org/docs/10/static/hstore.html\nfunction toHstoreString(str) {\n return '\"' + str.replace(/([\"\\\\])/g, \"\\\\$1\") + '\"';\n}\n\nfunction hstoreStringify(o) {\n if (o === null) {\n return null;\n }\n if (typeof o !== \"object\") {\n throw new TypeError(\"Expected an hstore object\");\n }\n const keys = Object.keys(o);\n const encodeKeyValue = key => {\n const value = o[key];\n if (value === null) {\n return `${toHstoreString(key)} => NULL`;\n } else {\n return `${toHstoreString(key)} => ${toHstoreString(String(value))}`;\n }\n };\n return keys.map(encodeKeyValue).join(\", \");\n}\n"],"file":"PgTypesPlugin.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/PgTypesPlugin.js"],"names":["indent","str","replace","identity","value","parseCache","LRU","maxLength","parseInterval","result","get","Object","freeze","set","PgTypesPlugin","builder","pgExtendedTypes","pgSkipHstore","pgUseCustomNetworkScalars","disableIssue390Fix","hook","build","pgIntrospectionResultsByKind","introspectionResultsByKind","getTypeByName","pgSql","sql","inflection","graphql","newWithHooks","args","addType","GraphQLNonNull","GraphQLString","GraphQLInt","GraphQLFloat","GraphQLBoolean","GraphQLList","GraphQLEnumType","GraphQLObjectType","GraphQLInputObjectType","GraphQLScalarType","isInputType","getNamedType","Kind","gqlTypeByTypeIdGenerator","gqlInputTypeByTypeIdGenerator","pgGqlTypeByTypeId","pgGqlInputTypeByTypeId","Error","gqlTypeByTypeIdAndModifier","pgGqlTypeByTypeIdAndModifier","gqlInputTypeByTypeIdAndModifier","pgGqlInputTypeByTypeIdAndModifier","isNull","val","__isNull","pg2GqlMapper","pg2gqlForType","type","id","map","domainBaseType","isPgArray","elementHandler","arrayItemType","Array","isArray","namespaceName","name","pg2gql","gql2pg","modifier","undefined","stack","e","console","warn","null","unmap","domainTypeModifier","fragment","join","v","identifier","makeIntervalFields","seconds","description","minutes","hours","days","months","years","GQLInterval","builtin","fields","isIntervalType","GQLIntervalInput","inputType","isIntervalInputType","stringType","serialize","String","parseValue","parseLiteral","ast","kind","STRING","BigFloat","BitString","rawTypes","tweakToJson","tweakToText","tweakToNumericText","pgTweaksByTypeIdAndModifer","pgTweaksByTypeId","reduce","memo","typeId","pgTweakFragmentForTypeAndModifier","typeModifier","resolveData","typeModifierKey","tweaker","domainBaseTypeModifier","error","process","env","NODE_ENV","SimpleDate","SimpleDatetime","SimpleTime","SimpleJSON","SimpleUUID","InetType","CidrType","MacAddrType","MacAddr8Type","JSONType","UUIDType","DateType","DateTimeType","TimeType","Point","x","y","isPointType","PointInput","isPointInputType","oidLookup","oidInputLookup","jsonStringify","o","JSON","stringify","keys","parts","key","push","_","f","length","substr","split","parseFloat","depth","enforceGqlTypeByPgTypeId","find","t","reallyEnforceGqlTypeByPgTypeAndModifier","message","originalError","gqlType","gqlInputType","enumType","values","enumVariants","enumName","pgIntrospection","isPgEnumType","subtype","typeById","rangeSubTypeId","gqlRangeSubType","getGqlTypeByTypeIdAndModifier","Range","rangeType","RangeInput","RangeBound","rangeBoundType","inclusive","isPgRangeBoundType","pgSubtypeIntrospection","pgTypeModifier","RangeBoundInput","isPgRangeBoundInputType","start","end","isPgRangeType","isPgRangeInputType","lower","upper","lowerInclusive","upperInclusive","literal","domainBaseTypeId","baseType","baseInputType","assign","create","domainType","category","arrayEntryOutputType","arrayItemTypeId","arrayEntryInputType","getGqlInputTypeByTypeIdAndModifier","useFallback","gen","Type","fallback","registerGqlTypeByTypeId","yieldToExisting","registerGqlInputTypeByTypeId","getGqlTypeByTypeId","getGqlInputTypeByTypeId","pgTweakFragmentForType","extend","pgRegisterGqlTypeByTypeId","pgRegisterGqlInputTypeByTypeId","pgGetGqlTypeByTypeIdAndModifier","pgGetGqlInputTypeByTypeIdAndModifier","pgGetGqlTypeByTypeId","pgGetGqlInputTypeByTypeId","hstoreType","hstoreExtension","extension","namespaceId","hstoreTypeName","GraphQLHStoreType","makeGraphQLHstoreType","hstoreStringify","isValidHstoreObject","obj","identityWithCheck","TypeError","parseValueLiteral","variables","INT","FLOAT","NULL","VARIABLE","OBJECT","field","GraphQLHStore","toHstoreString","encodeKeyValue"],"mappings":";;;;;;;AAGA;;AAEA;;AACA;;;;AAEA,SAASA,MAAT,CA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AAc,CAACjG,GAAD,CAAM,UAA9B;AACD,KAFD,MAEO;AACL,aAAQ,GAAEiG,cAAc,CAACjG,GAAD,CAAM,OAAMiG,cAAc,CAACxJ,MAAM,CAAClG,KAAD,CAAP,CAAgB,EAAlE;AACD;AACF,GAPD;;AAQA,SAAOuJ,IAAI,CAAC9F,GAAL,CAASkM,cAAT,EAAyB7K,IAAzB,CAA8B,IAA9B,CAAP;AACD","sourcesContent":["// @flow\nimport type { Plugin } from \"graphile-build\";\n\nimport makeGraphQLJSONType from \"../GraphQLJSON\";\n\nimport rawParseInterval from \"postgres-interval\";\nimport LRU from \"@graphile/lru\";\n\nfunction indent(str) {\n return \" \" + str.replace(/\\n/g, \"\\n \");\n}\n\nfunction identity(value) {\n return value;\n}\n\nconst parseCache = new LRU({ maxLength: 500 });\nfunction parseInterval(str) {\n let result = parseCache.get(str);\n if (!result) {\n result = rawParseInterval(str);\n Object.freeze(result);\n parseCache.set(str, result);\n }\n return result;\n}\n\nexport default (function PgTypesPlugin(\n builder,\n {\n pgExtendedTypes = true,\n // Adding hstore support is technically a breaking change; this allows people to opt out easily:\n pgSkipHstore = false,\n pgUseCustomNetworkScalars = false,\n disableIssue390Fix = false,\n }\n) {\n // XXX: most of this should be in an \"init\" hook, not a \"build\" hook\n builder.hook(\n \"build\",\n build => {\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n getTypeByName,\n pgSql: sql,\n inflection,\n graphql,\n } = build;\n\n /*\n * Note these do not do `foo.bind(build)` because they want to reference\n * the *latest* value of foo (i.e. after all the build hooks run) rather\n * than the current value of foo in this current hook.\n *\n * Also don't use this in your own code, only construct types *after* the\n * build hook has completed (i.e. 'init' or later).\n *\n * TODO:v5: move this to the 'init' hook.\n */\n const newWithHooks = (...args) => build.newWithHooks(...args);\n const addType = (...args) => build.addType(...args);\n\n const {\n GraphQLNonNull,\n GraphQLString,\n GraphQLInt,\n GraphQLFloat,\n GraphQLBoolean,\n GraphQLList,\n GraphQLEnumType,\n GraphQLObjectType,\n GraphQLInputObjectType,\n GraphQLScalarType,\n isInputType,\n getNamedType,\n Kind,\n } = graphql;\n\n const gqlTypeByTypeIdGenerator = {};\n const gqlInputTypeByTypeIdGenerator = {};\n if (build.pgGqlTypeByTypeId || build.pgGqlInputTypeByTypeId) {\n // I don't expect anyone to receive this error, because I don't think anyone uses this interface.\n throw new Error(\n \"Sorry! This interface is no longer supported because it is not granular enough. It's not hard to port it to the new system - please contact Benjie and he'll walk you through it.\"\n );\n }\n const gqlTypeByTypeIdAndModifier = {\n ...build.pgGqlTypeByTypeIdAndModifier,\n };\n const gqlInputTypeByTypeIdAndModifier = {\n ...build.pgGqlInputTypeByTypeIdAndModifier,\n };\n const isNull = val => val == null || val.__isNull;\n const pg2GqlMapper = {};\n const pg2gqlForType = type => {\n if (pg2GqlMapper[type.id]) {\n const map = pg2GqlMapper[type.id].map;\n return val => (isNull(val) ? null : map(val));\n } else if (type.domainBaseType) {\n return pg2gqlForType(type.domainBaseType);\n } else if (type.isPgArray) {\n const elementHandler = pg2gqlForType(type.arrayItemType);\n return val => {\n if (isNull(val)) return null;\n if (!Array.isArray(val)) {\n throw new Error(\n `Expected array when converting PostgreSQL data into GraphQL; failing type: '${type.namespaceName}.${type.name}'`\n );\n }\n return val.map(elementHandler);\n };\n } else {\n return identity;\n }\n };\n const pg2gql = (val, type) => pg2gqlForType(type)(val);\n const gql2pg = (val, type, modifier) => {\n if (modifier === undefined) {\n let stack;\n try {\n throw new Error();\n } catch (e) {\n stack = e.stack;\n }\n // eslint-disable-next-line no-console\n console.warn(\n \"gql2pg should be called with three arguments, the third being the type modifier (or `null`); \" +\n (stack || \"\")\n );\n // Hack for backwards compatibility:\n modifier = null;\n }\n if (val == null) {\n return sql.null;\n }\n if (pg2GqlMapper[type.id]) {\n return pg2GqlMapper[type.id].unmap(val, modifier);\n } else if (type.domainBaseType) {\n return gql2pg(val, type.domainBaseType, type.domainTypeModifier);\n } else if (type.isPgArray) {\n if (!Array.isArray(val)) {\n throw new Error(\n `Expected array when converting GraphQL data into PostgreSQL data; failing type: '${\n type.namespaceName\n }.${type.name}' (type: ${type === null ? \"null\" : typeof type})`\n );\n }\n return sql.fragment`array[${sql.join(\n val.map(v => gql2pg(v, type.arrayItemType, modifier)),\n \", \"\n )}]::${sql.identifier(type.namespaceName)}.${sql.identifier(\n type.name\n )}`;\n } else {\n return sql.value(val);\n }\n };\n\n const makeIntervalFields = () => {\n return {\n seconds: {\n description:\n \"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.\",\n type: GraphQLFloat,\n },\n minutes: {\n description: \"A quantity of minutes.\",\n type: GraphQLInt,\n },\n hours: {\n description: \"A quantity of hours.\",\n type: GraphQLInt,\n },\n days: {\n description: \"A quantity of days.\",\n type: GraphQLInt,\n },\n months: {\n description: \"A quantity of months.\",\n type: GraphQLInt,\n },\n years: {\n description: \"A quantity of years.\",\n type: GraphQLInt,\n },\n };\n };\n const GQLInterval = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.builtin(\"Interval\"),\n description:\n \"An interval of time that has passed where the smallest distinct unit is a second.\",\n fields: makeIntervalFields(),\n },\n {\n isIntervalType: true,\n }\n );\n addType(GQLInterval, \"graphile-build-pg built-in\");\n\n const GQLIntervalInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(inflection.builtin(\"Interval\")),\n description:\n \"An interval of time that has passed where the smallest distinct unit is a second.\",\n fields: makeIntervalFields(),\n },\n {\n isIntervalInputType: true,\n }\n );\n addType(GQLIntervalInput, \"graphile-build-pg built-in\");\n\n const stringType = (name, description) =>\n new GraphQLScalarType({\n name,\n description,\n serialize: value => String(value),\n parseValue: value => String(value),\n parseLiteral: ast => {\n if (ast.kind !== Kind.STRING) {\n throw new Error(\"Can only parse string values\");\n }\n return ast.value;\n },\n });\n\n const BigFloat = stringType(\n inflection.builtin(\"BigFloat\"),\n \"A floating point number that requires more precision than IEEE 754 binary 64\"\n );\n const BitString = stringType(\n inflection.builtin(\"BitString\"),\n \"A string representing a series of binary bits\"\n );\n addType(BigFloat, \"graphile-build-pg built-in\");\n addType(BitString, \"graphile-build-pg built-in\");\n\n const rawTypes = [\n 1186, // interval\n 1082, // date\n 1114, // timestamp\n 1184, // timestamptz\n 1083, // time\n 1266, // timetz\n ];\n\n const tweakToJson = fragment => fragment; // Since everything is to_json'd now, just pass through\n const tweakToText = fragment => sql.fragment`(${fragment})::text`;\n const tweakToNumericText = fragment =>\n sql.fragment`(${fragment})::numeric::text`;\n const pgTweaksByTypeIdAndModifer = {};\n const pgTweaksByTypeId = {\n // '::text' rawTypes\n ...rawTypes.reduce((memo, typeId) => {\n memo[typeId] = tweakToText;\n return memo;\n }, {}),\n\n // cast numbers above our ken to strings to avoid loss of precision\n \"20\": tweakToText,\n \"1700\": tweakToText,\n // to_json all dates to make them ISO (overrides rawTypes above)\n \"1082\": tweakToJson,\n \"1114\": tweakToJson,\n \"1184\": tweakToJson,\n \"1083\": tweakToJson,\n \"1266\": tweakToJson,\n \"790\": tweakToNumericText,\n };\n\n const pgTweakFragmentForTypeAndModifier = (\n fragment,\n type,\n typeModifier = null,\n resolveData\n ) => {\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n const tweaker =\n (pgTweaksByTypeIdAndModifer[type.id] &&\n pgTweaksByTypeIdAndModifer[type.id][typeModifierKey]) ||\n pgTweaksByTypeId[type.id];\n if (tweaker) {\n return tweaker(fragment, resolveData);\n } else if (type.domainBaseType) {\n // TODO: check that domains don't support atttypemod\n return pgTweakFragmentForTypeAndModifier(\n fragment,\n type.domainBaseType,\n type.domainBaseTypeModifier,\n resolveData\n );\n } else if (type.isPgArray) {\n const error = new Error(\n `Internal graphile-build-pg error: should not attempt to tweak an array, please process array before tweaking (type: \"${type.namespaceName}.${type.name}\")`\n );\n if (process.env.NODE_ENV === \"test\") {\n // This is to ensure that Graphile core does not introduce these problems\n throw error;\n }\n // eslint-disable-next-line no-console\n console.error(error);\n return fragment;\n } else {\n return fragment;\n }\n };\n /*\n Determined by running:\n\n select oid, typname, typarray, typcategory, typtype from pg_catalog.pg_type where typtype = 'b' order by oid;\n\n We only need to add oidLookups for types that don't have the correct fallback\n */\n const SimpleDate = stringType(\n inflection.builtin(\"Date\"),\n \"The day, does not include a time.\"\n );\n const SimpleDatetime = stringType(\n inflection.builtin(\"Datetime\"),\n \"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.\"\n );\n const SimpleTime = stringType(\n inflection.builtin(\"Time\"),\n \"The exact time of day, does not include the date. May or may not have a timezone offset.\"\n );\n const SimpleJSON = stringType(\n inflection.builtin(\"JSON\"),\n \"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).\"\n );\n const SimpleUUID = stringType(\n inflection.builtin(\"UUID\"),\n \"A universally unique identifier as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122).\"\n );\n const InetType = stringType(\n inflection.builtin(\"InternetAddress\"),\n \"An IPv4 or IPv6 host address, and optionally its subnet.\"\n );\n const CidrType = pgUseCustomNetworkScalars\n ? stringType(\n inflection.builtin(\"CidrAddress\"),\n \"An IPv4 or IPv6 CIDR address.\"\n )\n : GraphQLString;\n const MacAddrType = pgUseCustomNetworkScalars\n ? stringType(inflection.builtin(\"MacAddress\"), \"A 6-byte MAC address.\")\n : GraphQLString;\n const MacAddr8Type = pgUseCustomNetworkScalars\n ? stringType(\n inflection.builtin(\"MacAddress8\"),\n \"An 8-byte MAC address.\"\n )\n : GraphQLString;\n\n // pgExtendedTypes might change what types we use for things\n const JSONType = pgExtendedTypes\n ? makeGraphQLJSONType(graphql, inflection.builtin(\"JSON\"))\n : SimpleJSON;\n const UUIDType = SimpleUUID; // GraphQLUUID\n const DateType = SimpleDate; // GraphQLDate\n const DateTimeType = SimpleDatetime; // GraphQLDateTime\n const TimeType = SimpleTime; // GraphQLTime\n\n // 'point' in PostgreSQL is a 16-byte type that's comprised of two 8-byte floats.\n const Point = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.builtin(\"Point\"),\n fields: {\n x: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n y: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n },\n },\n {\n isPointType: true,\n }\n );\n const PointInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(inflection.builtin(\"Point\")),\n fields: {\n x: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n y: {\n type: new GraphQLNonNull(GraphQLFloat),\n },\n },\n },\n {\n isPointInputType: true,\n }\n );\n\n // Other plugins might want to use JSON\n addType(JSONType, \"graphile-build-pg built-in\");\n addType(UUIDType, \"graphile-build-pg built-in\");\n addType(DateType, \"graphile-build-pg built-in\");\n addType(DateTimeType, \"graphile-build-pg built-in\");\n addType(TimeType, \"graphile-build-pg built-in\");\n\n const oidLookup = {\n \"20\": stringType(\n inflection.builtin(\"BigInt\"),\n \"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.\"\n ), // bitint - even though this is int8, it's too big for JS int, so cast to string.\n \"21\": GraphQLInt, // int2\n \"23\": GraphQLInt, // int4\n \"700\": GraphQLFloat, // float4\n \"701\": GraphQLFloat, // float8\n \"1700\": BigFloat, // numeric\n \"790\": GraphQLFloat, // money\n\n \"1186\": GQLInterval, // interval\n \"1082\": DateType, // date\n \"1114\": DateTimeType, // timestamp\n \"1184\": DateTimeType, // timestamptz\n \"1083\": TimeType, // time\n \"1266\": TimeType, // timetz\n\n \"114\": JSONType, // json\n \"3802\": JSONType, // jsonb\n \"2950\": UUIDType, // uuid\n\n \"1560\": BitString, // bit\n \"1562\": BitString, // varbit\n\n \"18\": GraphQLString, // char\n \"25\": GraphQLString, // text\n \"1043\": GraphQLString, // varchar\n\n \"600\": Point, // point\n\n \"869\": InetType,\n \"650\": CidrType,\n \"829\": MacAddrType,\n \"774\": MacAddr8Type,\n };\n const oidInputLookup = {\n \"1186\": GQLIntervalInput, // interval\n \"600\": PointInput, // point\n };\n const jsonStringify = o => JSON.stringify(o);\n if (pgExtendedTypes) {\n pg2GqlMapper[114] = {\n map: identity,\n unmap: o => sql.value(jsonStringify(o)),\n };\n } else {\n pg2GqlMapper[114] = {\n map: jsonStringify,\n unmap: str => sql.value(str),\n };\n }\n pg2GqlMapper[3802] = pg2GqlMapper[114]; // jsonb\n\n // interval\n pg2GqlMapper[1186] = {\n map: str => parseInterval(str),\n unmap: o => {\n const keys = [\n \"seconds\",\n \"minutes\",\n \"hours\",\n \"days\",\n \"months\",\n \"years\",\n ];\n const parts = [];\n for (const key of keys) {\n if (o[key]) {\n parts.push(`${o[key]} ${key}`);\n }\n }\n return sql.value(parts.join(\" \") || \"0 seconds\");\n },\n };\n\n pg2GqlMapper[790] = {\n map: _ => _,\n unmap: val => sql.fragment`(${sql.value(val)})::money`,\n };\n\n // point\n pg2GqlMapper[600] = {\n map: f => {\n if (f[0] === \"(\" && f[f.length - 1] === \")\") {\n const [x, y] = f\n .substr(1, f.length - 2)\n .split(\",\")\n .map(f => parseFloat(f));\n return { x, y };\n }\n },\n unmap: o => sql.fragment`point(${sql.value(o.x)}, ${sql.value(o.y)})`,\n };\n\n // TODO: add more support for geometric types\n\n let depth = 0;\n\n /*\n * Enforce: this is the fallback when we can't find a specific GraphQL type\n * for a specific PG type. Use the generators from\n * `pgRegisterGqlTypeByTypeId` first, this is a last resort.\n */\n const enforceGqlTypeByPgTypeId = (typeId, typeModifier) => {\n const type = introspectionResultsByKind.type.find(t => t.id === typeId);\n depth++;\n if (depth > 50) {\n throw new Error(\"Type enforcement went too deep - infinite loop?\");\n }\n try {\n return reallyEnforceGqlTypeByPgTypeAndModifier(type, typeModifier);\n } catch (e) {\n const error = new Error(\n `Error occurred when processing database type '${\n type.namespaceName\n }.${type.name}' (type=${type.type}):\\n${indent(e.message)}`\n );\n // $FlowFixMe\n error.originalError = e;\n throw error;\n } finally {\n depth--;\n }\n };\n const reallyEnforceGqlTypeByPgTypeAndModifier = (type, typeModifier) => {\n if (!type.id) {\n throw new Error(\n `Invalid argument to enforceGqlTypeByPgTypeId - expected a full type, received '${type}'`\n );\n }\n if (!gqlTypeByTypeIdAndModifier[type.id]) {\n gqlTypeByTypeIdAndModifier[type.id] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[type.id]) {\n gqlInputTypeByTypeIdAndModifier[type.id] = {};\n }\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n // Explicit overrides\n if (!gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n const gqlType = oidLookup[type.id];\n if (gqlType) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = gqlType;\n }\n }\n if (!gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n const gqlInputType = oidInputLookup[type.id];\n if (gqlInputType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = gqlInputType;\n }\n }\n // Enums\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"e\"\n ) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = newWithHooks(\n GraphQLEnumType,\n {\n name: inflection.enumType(type),\n description: type.description,\n values: type.enumVariants.reduce((memo, value) => {\n memo[inflection.enumName(value)] = {\n value: value,\n };\n return memo;\n }, {}),\n },\n {\n pgIntrospection: type,\n isPgEnumType: true,\n }\n );\n }\n // Ranges\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"r\"\n ) {\n const subtype =\n introspectionResultsByKind.typeById[type.rangeSubTypeId];\n const gqlRangeSubType = getGqlTypeByTypeIdAndModifier(\n subtype.id,\n typeModifier\n );\n if (!gqlRangeSubType) {\n throw new Error(\"Range of unsupported\");\n }\n let Range = getTypeByName(inflection.rangeType(gqlRangeSubType.name));\n let RangeInput;\n if (!Range) {\n const RangeBound = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.rangeBoundType(gqlRangeSubType.name),\n description:\n \"The value at one end of a range. A range can either include this value, or not.\",\n fields: {\n value: {\n description: \"The value at one end of our range.\",\n type: new GraphQLNonNull(gqlRangeSubType),\n },\n inclusive: {\n description:\n \"Whether or not the value of this bound is included in the range.\",\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n },\n {\n isPgRangeBoundType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n const RangeBoundInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(RangeBound.name),\n description:\n \"The value at one end of a range. A range can either include this value, or not.\",\n fields: {\n value: {\n description: \"The value at one end of our range.\",\n type: new GraphQLNonNull(gqlRangeSubType),\n },\n inclusive: {\n description:\n \"Whether or not the value of this bound is included in the range.\",\n type: new GraphQLNonNull(GraphQLBoolean),\n },\n },\n },\n {\n isPgRangeBoundInputType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n Range = newWithHooks(\n GraphQLObjectType,\n {\n name: inflection.rangeType(gqlRangeSubType.name),\n description: `A range of \\`${gqlRangeSubType.name}\\`.`,\n fields: {\n start: {\n description: \"The starting bound of our range.\",\n type: RangeBound,\n },\n end: {\n description: \"The ending bound of our range.\",\n type: RangeBound,\n },\n },\n },\n {\n isPgRangeType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n RangeInput = newWithHooks(\n GraphQLInputObjectType,\n {\n name: inflection.inputType(Range.name),\n description: `A range of \\`${gqlRangeSubType.name}\\`.`,\n fields: {\n start: {\n description: \"The starting bound of our range.\",\n type: RangeBoundInput,\n },\n end: {\n description: \"The ending bound of our range.\",\n type: RangeBoundInput,\n },\n },\n },\n {\n isPgRangeInputType: true,\n pgIntrospection: type,\n pgSubtypeIntrospection: subtype,\n pgTypeModifier: typeModifier,\n }\n );\n addType(Range, \"graphile-build-pg built-in\");\n addType(RangeInput, \"graphile-build-pg built-in\");\n } else {\n RangeInput = getTypeByName(inflection.inputType(Range.name));\n }\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Range;\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = RangeInput;\n if (pgTweaksByTypeIdAndModifer[type.id] === undefined) {\n pgTweaksByTypeIdAndModifer[type.id] = {};\n }\n pgTweaksByTypeIdAndModifer[type.id][\n typeModifierKey\n ] = fragment => sql.fragment`\\\ncase\nwhen (${fragment}) is null then null\nelse json_build_object(\n 'start',\n case when lower(${fragment}) is null then null\n else json_build_object('value', ${pgTweakFragmentForTypeAndModifier(\n sql.fragment`lower(${fragment})`,\n subtype,\n typeModifier,\n {}\n )}, 'inclusive', lower_inc(${fragment}))\n end,\n 'end',\n case when upper(${fragment}) is null then null\n else json_build_object('value', ${pgTweakFragmentForTypeAndModifier(\n sql.fragment`upper(${fragment})`,\n subtype,\n typeModifier,\n {}\n )}, 'inclusive', upper_inc(${fragment}))\n end\n)\nend`;\n pg2GqlMapper[type.id] = {\n map: identity,\n unmap: ({ start, end }) => {\n // Ref: https://www.postgresql.org/docs/9.6/static/rangetypes.html#RANGETYPES-CONSTRUCT\n const lower =\n (start && gql2pg(start.value, subtype, null)) || sql.null;\n const upper =\n (end && gql2pg(end.value, subtype, null)) || sql.null;\n const lowerInclusive = start && !start.inclusive ? \"(\" : \"[\";\n const upperInclusive = end && !end.inclusive ? \")\" : \"]\";\n return sql.fragment`${sql.identifier(\n type.namespaceName,\n type.name\n )}(${lower}, ${upper}, ${sql.literal(\n lowerInclusive + upperInclusive\n )})`;\n },\n };\n }\n\n // Domains\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.type === \"d\" &&\n type.domainBaseTypeId\n ) {\n const baseType = getGqlTypeByTypeIdAndModifier(\n type.domainBaseTypeId,\n typeModifier\n );\n const baseInputType =\n gqlInputTypeByTypeIdAndModifier[type.domainBaseTypeId][\n typeModifierKey\n ];\n // Hack stolen from: https://github.com/graphile/postgraphile/blob/ade728ed8f8e3ecdc5fdad7d770c67aa573578eb/src/graphql/schema/type/aliasGqlType.ts#L16\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Object.assign(\n Object.create(baseType),\n {\n name: inflection.domainType(type),\n description: type.description,\n }\n );\n if (baseInputType && baseInputType !== baseType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = Object.assign(Object.create(baseInputType), {\n name: inflection.inputType(\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]\n ),\n description: type.description,\n });\n }\n }\n\n // Arrays\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"A\"\n ) {\n const arrayEntryOutputType = getGqlTypeByTypeIdAndModifier(\n type.arrayItemTypeId,\n typeModifier\n );\n gqlTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = new GraphQLList(arrayEntryOutputType);\n if (!disableIssue390Fix) {\n const arrayEntryInputType = getGqlInputTypeByTypeIdAndModifier(\n type.arrayItemTypeId,\n typeModifier\n );\n if (arrayEntryInputType) {\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = new GraphQLList(arrayEntryInputType);\n }\n }\n }\n\n // Booleans\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"B\"\n ) {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = GraphQLBoolean;\n }\n\n // Numbers may be too large for GraphQL/JS to handle, so stringify by\n // default.\n if (\n !gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n type.category === \"N\"\n ) {\n pgTweaksByTypeId[type.id] = tweakToText;\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = BigFloat;\n }\n\n // Nothing else worked; pass through as string!\n if (!gqlTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n // XXX: consider using stringType(upperFirst(camelCase(`fallback_${type.name}`)), type.description)?\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = GraphQLString;\n }\n // Now for input types, fall back to output types if possible\n if (!gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey]) {\n if (\n isInputType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])\n ) {\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] =\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];\n }\n }\n addType(\n getNamedType(gqlTypeByTypeIdAndModifier[type.id][typeModifierKey])\n );\n return gqlTypeByTypeIdAndModifier[type.id][typeModifierKey];\n };\n\n function getGqlTypeByTypeIdAndModifier(\n typeId,\n typeModifier = null,\n useFallback = true\n ) {\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n if (!gqlTypeByTypeIdAndModifier[typeId]) {\n gqlTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[typeId]) {\n gqlInputTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlTypeByTypeIdAndModifier[typeId][typeModifierKey]) {\n const type = introspectionResultsByKind.type.find(\n t => t.id === typeId\n );\n if (!type) {\n throw new Error(\n `Type '${typeId}' not present in introspection results`\n );\n }\n const gen = gqlTypeByTypeIdGenerator[type.id];\n if (gen) {\n const set = Type => {\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = Type;\n };\n const result = gen(set, typeModifier);\n if (result) {\n if (\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] !== result\n ) {\n throw new Error(\n `Callback and return types differ when defining type for '${type.id}'`\n );\n }\n gqlTypeByTypeIdAndModifier[type.id][typeModifierKey] = result;\n }\n }\n }\n if (\n !gqlTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n typeModifierKey > -1\n ) {\n // Fall back to `null` modifier, but if that still doesn't work, we\n // still want to pass the modifier to enforceGqlTypeByPgTypeId.\n const fallback = getGqlTypeByTypeIdAndModifier(typeId, null, false);\n if (fallback) {\n return fallback;\n }\n }\n if (\n useFallback &&\n !gqlTypeByTypeIdAndModifier[typeId][typeModifierKey]\n ) {\n return enforceGqlTypeByPgTypeId(typeId, typeModifier);\n }\n return gqlTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n\n function getGqlInputTypeByTypeIdAndModifier(typeId, typeModifier = null) {\n // First, load the OUTPUT type (it might register an input type)\n getGqlTypeByTypeIdAndModifier(typeId, typeModifier);\n\n const typeModifierKey = typeModifier != null ? typeModifier : -1;\n if (!gqlInputTypeByTypeIdAndModifier[typeId]) {\n gqlInputTypeByTypeIdAndModifier[typeId] = {};\n }\n if (!gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey]) {\n const type = introspectionResultsByKind.typeById[typeId];\n\n if (!type) {\n throw new Error(\n `Type '${typeId}' not present in introspection results`\n );\n }\n const gen = gqlInputTypeByTypeIdGenerator[type.id];\n if (gen) {\n const set = Type => {\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] = Type;\n };\n const result = gen(set, typeModifier);\n if (result) {\n if (\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] &&\n gqlInputTypeByTypeIdAndModifier[type.id][typeModifierKey] !==\n result\n ) {\n throw new Error(\n `Callback and return types differ when defining type for '${type.id}'`\n );\n }\n gqlInputTypeByTypeIdAndModifier[type.id][\n typeModifierKey\n ] = result;\n }\n }\n }\n // Use the same type as the output type if it's valid input\n if (\n !gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n gqlTypeByTypeIdAndModifier[typeId] &&\n gqlTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n isInputType(gqlTypeByTypeIdAndModifier[typeId][typeModifierKey])\n ) {\n gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] =\n gqlTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n if (\n !gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey] &&\n typeModifierKey > -1\n ) {\n // Fall back to default\n return getGqlInputTypeByTypeIdAndModifier(typeId, null);\n }\n return gqlInputTypeByTypeIdAndModifier[typeId][typeModifierKey];\n }\n function registerGqlTypeByTypeId(typeId, gen, yieldToExisting = false) {\n if (gqlTypeByTypeIdGenerator[typeId]) {\n if (yieldToExisting) {\n return;\n }\n throw new Error(\n `There's already a type generator registered for '${typeId}'`\n );\n }\n gqlTypeByTypeIdGenerator[typeId] = gen;\n }\n function registerGqlInputTypeByTypeId(\n typeId,\n gen,\n yieldToExisting = false\n ) {\n if (gqlInputTypeByTypeIdGenerator[typeId]) {\n if (yieldToExisting) {\n return;\n }\n throw new Error(\n `There's already an input type generator registered for '${typeId}'`\n );\n }\n gqlInputTypeByTypeIdGenerator[typeId] = gen;\n }\n\n // DEPRECATIONS!\n function getGqlTypeByTypeId(typeId, typeModifier) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: getGqlTypeByTypeId should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the second parameter (or null if it's not available).\"\n );\n }\n return getGqlTypeByTypeIdAndModifier(typeId, typeModifier);\n }\n function getGqlInputTypeByTypeId(typeId, typeModifier) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: getGqlInputTypeByTypeId should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the second parameter (or null if it's not available).\"\n );\n }\n return getGqlInputTypeByTypeIdAndModifier(typeId, typeModifier);\n }\n function pgTweakFragmentForType(\n fragment,\n type,\n typeModifier,\n resolveData\n ) {\n if (typeModifier === undefined) {\n // eslint-disable-next-line no-console\n console.warn(\n \"DEPRECATION WARNING: pgTweakFragmentForType should not be used - for some columns we also require typeModifier to be specified. Please update your code ASAP to pass `attribute.typeModifier` through as the third parameter (or null if it's not available).\"\n );\n }\n return pgTweakFragmentForTypeAndModifier(\n fragment,\n type,\n typeModifier,\n resolveData\n );\n }\n // END OF DEPRECATIONS!\n\n return build.extend(build, {\n pgRegisterGqlTypeByTypeId: registerGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId: registerGqlInputTypeByTypeId,\n pgGetGqlTypeByTypeIdAndModifier: getGqlTypeByTypeIdAndModifier,\n pgGetGqlInputTypeByTypeIdAndModifier: getGqlInputTypeByTypeIdAndModifier,\n pg2GqlMapper,\n pg2gql,\n pg2gqlForType,\n gql2pg,\n pgTweakFragmentForTypeAndModifier,\n pgTweaksByTypeId,\n pgTweaksByTypeIdAndModifer,\n\n // DEPRECATED METHODS:\n pgGetGqlTypeByTypeId: getGqlTypeByTypeId, // DEPRECATED, replaced by getGqlTypeByTypeIdAndModifier\n pgGetGqlInputTypeByTypeId: getGqlInputTypeByTypeId, // DEPRECATED, replaced by getGqlInputTypeByTypeIdAndModifier\n pgTweakFragmentForType, // DEPRECATED, replaced by pgTweakFragmentForTypeAndModifier\n });\n },\n [\"PgTypes\"],\n [],\n [\"PgIntrospection\", \"StandardTypes\"]\n );\n\n /* Start of hstore type */\n builder.hook(\n \"inflection\",\n (inflection, build) => {\n // This hook allows you to append a plugin which renames the KeyValueHash\n // (hstore) type name.\n if (pgSkipHstore) return build;\n return build.extend(inflection, {\n hstoreType() {\n return \"KeyValueHash\";\n },\n });\n },\n [\"PgTypesHstore\"]\n );\n builder.hook(\n \"build\",\n build => {\n // This hook tells graphile-build-pg about the hstore database type so it\n // knows how to express it in input/output.\n if (pgSkipHstore) return build;\n const {\n pgIntrospectionResultsByKind: introspectionResultsByKind,\n pgRegisterGqlTypeByTypeId,\n pgRegisterGqlInputTypeByTypeId,\n pg2GqlMapper,\n pgSql: sql,\n graphql,\n } = build;\n\n // Check we have the hstore extension\n const hstoreExtension = introspectionResultsByKind.extension.find(\n e => e.name === \"hstore\"\n );\n if (!hstoreExtension) {\n return build;\n }\n\n // Get the 'hstore' type itself:\n const hstoreType = introspectionResultsByKind.type.find(\n t =>\n t.name === \"hstore\" && t.namespaceId === hstoreExtension.namespaceId\n );\n if (!hstoreType) {\n return build;\n }\n\n const hstoreTypeName = build.inflection.hstoreType();\n\n // We're going to use our own special HStore type for this so that we get\n // better validation; but you could just as easily use JSON directly if you\n // wanted to.\n const GraphQLHStoreType = makeGraphQLHstoreType(graphql, hstoreTypeName);\n\n // Now register the hstore type with the type system for both output and input.\n pgRegisterGqlTypeByTypeId(hstoreType.id, () => GraphQLHStoreType);\n pgRegisterGqlInputTypeByTypeId(hstoreType.id, () => GraphQLHStoreType);\n\n // Finally we must tell the system how to translate the data between PG-land and JS-land:\n pg2GqlMapper[hstoreType.id] = {\n // node-postgres parses hstore for us, no action required on map\n map: identity,\n // When unmapping we need to convert back to hstore\n unmap: o =>\n sql.fragment`(${sql.value(hstoreStringify(o))}::${sql.identifier(\n hstoreType.namespaceName,\n hstoreType.name\n )})`,\n };\n\n return build;\n },\n [\"PgTypesHstore\"],\n [],\n [\"PgTypes\"]\n );\n /* End of hstore type */\n}: Plugin);\n\nfunction makeGraphQLHstoreType(graphql, hstoreTypeName) {\n const { GraphQLScalarType, Kind } = graphql;\n\n function isValidHstoreObject(obj) {\n if (obj === null) {\n // Null is okay\n return true;\n } else if (typeof obj === \"object\") {\n // A hash with string/null values is also okay\n const keys = Object.keys(obj);\n for (const key of keys) {\n const val = obj[key];\n if (val === null) {\n // Null is okay\n } else if (typeof val === \"string\") {\n // String is okay\n } else {\n // Everything else is invalid.\n return false;\n }\n }\n return true;\n } else {\n // Everything else is invalid.\n return false;\n }\n }\n\n function identityWithCheck(obj) {\n if (isValidHstoreObject(obj)) {\n return obj;\n }\n throw new TypeError(\n `This is not a valid ${hstoreTypeName} object, it must be a key/value hash where keys and values are both strings (or null).`\n );\n }\n\n function parseValueLiteral(ast, variables) {\n switch (ast.kind) {\n case Kind.INT:\n case Kind.FLOAT:\n // Number isn't really okay, but we'll coerce it to a string anyway.\n return String(parseFloat(ast.value));\n case Kind.STRING:\n // String is okay.\n return String(ast.value);\n case Kind.NULL:\n // Null is okay.\n return null;\n case Kind.VARIABLE: {\n // Variable is okay if that variable is either a string or null.\n const name = ast.name.value;\n const value = variables ? variables[name] : undefined;\n if (value === null || typeof value === \"string\") {\n return value;\n }\n return undefined;\n }\n default:\n // Everything else is invalid.\n return undefined;\n }\n }\n\n function parseLiteral(ast, variables) {\n switch (ast.kind) {\n case Kind.OBJECT: {\n const value = ast.fields.reduce((memo, field) => {\n memo[field.name.value] = parseValueLiteral(field.value, variables);\n return memo;\n }, Object.create(null));\n\n if (!isValidHstoreObject(value)) {\n return undefined;\n }\n return value;\n }\n\n case Kind.NULL:\n return null;\n\n case Kind.VARIABLE: {\n const name = ast.name.value;\n const value = variables ? variables[name] : undefined;\n\n if (!isValidHstoreObject(value)) {\n return undefined;\n }\n return value;\n }\n\n default:\n return undefined;\n }\n }\n\n // TODO: use newWithHooks instead\n const GraphQLHStore = new GraphQLScalarType({\n name: hstoreTypeName,\n description:\n \"A set of key/value pairs, keys are strings, values may be a string or null. Exposed as a JSON object.\",\n serialize: identity,\n parseValue: identityWithCheck,\n parseLiteral,\n });\n return GraphQLHStore;\n}\n\n// To include a double quote or a backslash in a key or value, escape it\n// with a backslash.\n// -- https://www.postgresql.org/docs/10/static/hstore.html\nfunction toHstoreString(str) {\n return '\"' + str.replace(/([\"\\\\])/g, \"\\\\$1\") + '\"';\n}\n\nfunction hstoreStringify(o) {\n if (o === null) {\n return null;\n }\n if (typeof o !== \"object\") {\n throw new TypeError(\"Expected an hstore object\");\n }\n const keys = Object.keys(o);\n const encodeKeyValue = key => {\n const value = o[key];\n if (value === null) {\n return `${toHstoreString(key)} => NULL`;\n } else {\n return `${toHstoreString(key)} => ${toHstoreString(String(value))}`;\n }\n };\n return keys.map(encodeKeyValue).join(\", \");\n}\n"],"file":"PgTypesPlugin.js"}
|
|
@@ -367,6 +367,7 @@ with
|
|
|
367
367
|
idx.indimmediate as "isImmediate", -- enforce uniqueness immediately on insert
|
|
368
368
|
idx.indisreplident as "isReplicaIdentity",
|
|
369
369
|
idx.indisvalid as "isValid", -- if false, don't use for queries
|
|
370
|
+
idx.indpred is not null as "isPartial", -- if true, index is not on on rows.
|
|
370
371
|
idx.indkey as "attributeNums",
|
|
371
372
|
am.amname as "indexType",
|
|
372
373
|
${serverVersionNum >= 90600 ? `\
|
|
@@ -375,6 +375,7 @@ with
|
|
|
375
375
|
idx.indimmediate as "isImmediate", -- enforce uniqueness immediately on insert
|
|
376
376
|
idx.indisreplident as "isReplicaIdentity",
|
|
377
377
|
idx.indisvalid as "isValid", -- if false, don't use for queries
|
|
378
|
+
idx.indpred is not null as "isPartial", -- if true, index is not on on rows.
|
|
378
379
|
idx.indkey as "attributeNums",
|
|
379
380
|
am.amname as "indexType",
|
|
380
381
|
${
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/introspectionQuery.js"],"names":["makeIntrospectionQuery","serverVersionNum","options","pgLegacyFunctionsOnly","module","exports"],"mappings":";;AACA;;;;;;;;AAQA,SAASA,sBAAT,CACEC,gBADF,EAEEC,OAA4C,GAAG,EAFjD,EAGU;AACR,QAAM;AAAEC,IAAAA;AAAF,MAA4BD,OAAlC;AACA,SAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA2EFD,gBAAgB,IAAI,MAApB,GACI,mBADJ,GAEI,kDACL;QAECE,qBAAqB,GAChB;;;;;sDADgB,GAOhB;;;;;;;;4GASN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiGCF,gBAAgB,IAAI,MAApB,GAA6B,iBAA7B,GAAiD,IAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA6KtDA,gBAAgB,IAAI,KAApB,GACK;;;;;;;;4CADL,GAUI,EACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAzXL;AA2ZD;;AAEDG,MAAM,CAACC,OAAP,GAAiB;AACfL,EAAAA;AADe,CAAjB","sourcesContent":["// @flow\n/*\n * IMPORTANT: when editing this file, ensure all operators (e.g. `@>`) are\n * specified in the correct namespace (e.g. `operator(pg_catalog.@>)`). It looks\n * weird, but it prevents clashes with extensions or user code that may\n * overload operators, e.g. extension `intarray` overloads `@>`.\n *\n * NOTE: I'm not doing this with `=` because that way lies madness.\n */\nfunction makeIntrospectionQuery(\n serverVersionNum: number,\n options: { pgLegacyFunctionsOnly?: boolean } = {}\n): string {\n const { pgLegacyFunctionsOnly } = options;\n return `\\\n-- @see https://www.postgresql.org/docs/9.5/static/catalogs.html\n-- @see https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/introspectionQuery.js\n--\n-- ## Parameters\n-- - \\`$1\\`: An array of strings that represent the namespaces we are introspecting.\n-- - \\`$2\\`: set true to include functions/tables/etc that come from extensions\nwith\n recursive accessible_roles(_oid) as (\n select oid _oid, pg_roles.*\n from pg_roles\n where rolname = current_user\n union all\n select pg_roles.oid _oid, pg_roles.*\n from pg_roles, accessible_roles, pg_auth_members\n where pg_auth_members.roleid = pg_roles.oid\n and pg_auth_members.member = accessible_roles._oid\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-namespace.html\n namespace as (\n select\n 'namespace' as \"kind\",\n nsp.oid as \"id\",\n nsp.nspname as \"name\",\n dsc.description as \"description\"\n from\n pg_catalog.pg_namespace as nsp\n left join pg_catalog.pg_description as dsc on dsc.objoid = nsp.oid and dsc.classoid = 'pg_catalog.pg_namespace'::regclass\n where\n nsp.nspname = any ($1)\n order by\n nsp.nspname\n ),\n -- Select all of the remote procedures we can use in this schema. This comes\n -- first so that we can select types and classes using the information we get\n -- from it.\n --\n -- @see https://www.postgresql.org/docs/9.6/static/catalog-pg-proc.html\n procedure as (\n select\n 'procedure' as \"kind\",\n pro.oid as \"id\",\n pro.proname as \"name\",\n dsc.description as \"description\",\n pro.pronamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n pro.proisstrict as \"isStrict\",\n pro.proretset as \"returnsSet\",\n case\n when pro.provolatile = 'i' then true\n when pro.provolatile = 's' then true\n else false\n end as \"isStable\",\n pro.prorettype as \"returnTypeId\",\n coalesce(pro.proallargtypes, pro.proargtypes) as \"argTypeIds\",\n coalesce(pro.proargmodes, array[]::text[]) as \"argModes\",\n coalesce(pro.proargnames, array[]::text[]) as \"argNames\",\n pro.pronargs as \"inputArgsCount\",\n pro.pronargdefaults as \"argDefaultsNum\",\n pro.procost as \"cost\",\n exists(select 1 from accessible_roles where has_function_privilege(accessible_roles.oid, pro.oid, 'EXECUTE')) as \"aclExecutable\",\n (select lanname from pg_catalog.pg_language where pg_language.oid = pro.prolang) as \"language\"\n from\n pg_catalog.pg_proc as pro\n left join pg_catalog.pg_description as dsc on dsc.objoid = pro.oid and dsc.classoid = 'pg_catalog.pg_proc'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = pro.pronamespace\n where\n pro.pronamespace in (select \"id\" from namespace) and\n -- Currently we don’t support functions with variadic arguments. In the\n -- future we may, but for now let’s just ignore functions with variadic\n -- arguments.\n -- TODO: Variadic arguments.\n pro.provariadic = 0 and\n -- Filter our aggregate functions and window functions.\n ${\n serverVersionNum >= 110000\n ? \"pro.prokind = 'f'\"\n : \"pro.proisagg = false and pro.proiswindow = false\"\n } and\n ${\n pgLegacyFunctionsOnly\n ? `\\\n -- We want to make sure the argument mode for all of our arguments is\n -- \\`IN\\` which means \\`proargmodes\\` will be null.\n pro.proargmodes is null and\n -- Do not select procedures that return \\`RECORD\\` (oid 2249).\n pro.prorettype operator(pg_catalog.<>) 2249 and`\n : `\\\n -- We want to make sure the argument modes for all of our arguments are\n -- \\`IN\\`, \\`OUT\\`, \\`INOUT\\`, or \\`TABLE\\` (not \\`VARIADIC\\`).\n (pro.proargmodes is null or pro.proargmodes operator(pg_catalog.<@) array['i','o','b','t']::\"char\"[]) and\n -- Do not select procedures that return \\`RECORD\\` (oid 2249) unless they\n -- have \\`OUT\\`, \\`INOUT\\`, or \\`TABLE\\` arguments to define the return type.\n (pro.prorettype operator(pg_catalog.<>) 2249 or pro.proargmodes && array['o','b','t']::\"char\"[]) and\n -- Do not select procedures that have \\`RECORD\\` arguments.\n (pro.proallargtypes is null or not (pro.proallargtypes operator(pg_catalog.@>) array[2249::oid])) and`\n }\n -- Do not select procedures that create range types. These are utility\n -- functions that really don’t need to be exposed in an API.\n pro.proname not in (\n select typ.typname\n from pg_catalog.pg_type as typ\n where typ.typtype = 'r'\n and typ.typnamespace = pro.pronamespace\n ) and\n -- Do not expose trigger functions (type trigger has oid 2279)\n pro.prorettype operator(pg_catalog.<>) 2279 and\n -- We don't want functions that will clash with GraphQL (treat them as private)\n pro.proname not like E'\\\\\\\\_\\\\\\\\_%' and\n -- We also don’t want procedures that have been defined in our namespace\n -- twice. This leads to duplicate fields in the API which throws an\n -- error. In the future we may support this case. For now though, it is\n -- too complex.\n (\n select count(pro2.*)\n from pg_catalog.pg_proc as pro2\n where pro2.pronamespace = pro.pronamespace\n and pro2.proname = pro.proname\n ) = 1 and\n ($2 is true or not exists(\n select 1\n from pg_catalog.pg_depend\n where pg_depend.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n and pg_depend.deptype = 'e'\n and pg_depend.classid = 'pg_catalog.pg_proc'::pg_catalog.regclass\n and pg_depend.objid = pro.oid\n ))\n order by\n pro.pronamespace, pro.proname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-class.html\n class as (\n select\n 'class' as \"kind\",\n rel.oid as \"id\",\n rel.relname as \"name\",\n rel.relkind as \"classKind\",\n dsc.description as \"description\",\n rel.relnamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n rel.reltype as \"typeId\",\n -- Here we determine whether or not we can use this class in a\n -- \\`SELECT\\`’s \\`FROM\\` clause. In order to determine this we look at them\n -- \\`relkind\\` column, if it is \\`i\\` (index) or \\`c\\` (composite), we cannot\n -- select this class. Otherwise we can.\n rel.relkind not in ('i', 'c') as \"isSelectable\",\n -- Here we are determining whether we can insert/update/delete a class.\n -- This is helpful as it lets us detect non-updatable views and then\n -- exclude them from being inserted/updated/deleted into. For more info\n -- on how \\`pg_catalog.pg_relation_is_updatable\\` works:\n --\n -- - https://www.postgresql.org/message-id/CAEZATCV2_qN9P3zbvADwME_TkYf2gR_X2cLQR4R+pqkwxGxqJg@mail.gmail.com\n -- - https://github.com/postgres/postgres/blob/2410a2543e77983dab1f63f48b2adcd23dba994e/src/backend/utils/adt/misc.c#L684\n -- - https://github.com/postgres/postgres/blob/3aff33aa687e47d52f453892498b30ac98a296af/src/backend/rewrite/rewriteHandler.c#L2351\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00010000') = B'00010000' as \"isDeletable\",\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00001000') = B'00001000' as \"isInsertable\",\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00000100') = B'00000100' as \"isUpdatable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'SELECT')) as \"aclSelectable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'INSERT')) as \"aclInsertable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'UPDATE')) as \"aclUpdatable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'DELETE')) as \"aclDeletable\"\n from\n pg_catalog.pg_class as rel\n left join pg_catalog.pg_description as dsc on dsc.objoid = rel.oid and dsc.objsubid = 0 and dsc.classoid = 'pg_catalog.pg_class'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = rel.relnamespace\n where\n rel.relpersistence in ('p') and\n -- We don't want classes that will clash with GraphQL (treat them as private)\n rel.relname not like E'\\\\\\\\_\\\\\\\\_%' and\n rel.relkind in ('r', 'v', 'm', 'c', 'f') and\n ($2 is true or not exists(\n select 1\n from pg_catalog.pg_depend\n where pg_depend.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n and pg_depend.deptype = 'e'\n and pg_depend.classid = 'pg_catalog.pg_class'::pg_catalog.regclass\n and pg_depend.objid = rel.oid\n ))\n order by\n rel.relnamespace, rel.relname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-attribute.html\n attribute as (\n select\n 'attribute' as \"kind\",\n att.attrelid as \"classId\",\n att.attnum as \"num\",\n att.attname as \"name\",\n dsc.description as \"description\",\n att.atttypid as \"typeId\",\n nullif(att.atttypmod, -1) as \"typeModifier\",\n att.attnotnull as \"isNotNull\",\n att.atthasdef as \"hasDefault\",\n ${serverVersionNum >= 100000 ? \"att.attidentity\" : \"''\"} as \"identity\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'SELECT')) as \"aclSelectable\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'INSERT')) as \"aclInsertable\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'UPDATE')) as \"aclUpdatable\",\n -- https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=c62dd80cdf149e2792b13c13777a539f5abb0370\n att.attacl is not null and exists(select 1 from aclexplode(att.attacl) aclitem where aclitem.privilege_type = 'SELECT' and grantee in (select oid from accessible_roles)) as \"columnLevelSelectGrant\"\n from\n pg_catalog.pg_attribute as att\n left join pg_catalog.pg_description as dsc on dsc.objoid = att.attrelid and dsc.objsubid = att.attnum and dsc.classoid = 'pg_catalog.pg_class'::regclass\n where\n att.attrelid in (select \"id\" from class) and\n att.attnum > 0 and\n -- We don't want attributes that will clash with GraphQL (treat them as private)\n att.attname not like E'\\\\\\\\_\\\\\\\\_%' and\n not att.attisdropped\n order by\n att.attrelid, att.attnum\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-type.html\n type as (\n -- Use another \\`WITH\\` statement here, because our \\`WHERE\\` clause will need\n -- to use it.\n with type_all as (\n select\n 'type' as \"kind\",\n typ.oid as \"id\",\n typ.typname as \"name\",\n dsc.description as \"description\",\n typ.typnamespace as \"namespaceId\",\n -- We include the namespace name in types only because we select so\n -- many types that are outside of our core set of namespaces. Having\n -- the namespace name is super helpful when generating SQL, so\n -- conditionally having namespace names for types is a pain.\n nsp.nspname as \"namespaceName\",\n typ.typtype as \"type\",\n typ.typcategory as \"category\",\n typ.typnotnull as \"domainIsNotNull\",\n nullif(typ.typelem, 0) as \"arrayItemTypeId\",\n typ.typlen as \"typeLength\",\n (typ.typelem <> 0 and typ.typlen = -1) as \"isPgArray\",\n nullif(typ.typrelid, 0) as \"classId\",\n nullif(typ.typbasetype, 0) as \"domainBaseTypeId\",\n nullif(typ.typtypmod, -1) as \"domainTypeModifier\",\n typ.typdefaultbin is not null as \"domainHasDefault\",\n -- If this type is an enum type, let’s select all of its enum variants.\n --\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-enum.html\n case\n when typ.typtype = 'e' then array(\n select enm.enumlabel\n from pg_catalog.pg_enum as enm\n where enm.enumtypid = typ.oid\n order by enm.enumsortorder\n )\n else null\n end as \"enumVariants\",\n -- If this type is a range type, we want to select the sub type of the\n -- range.\n --\n -- @see https://www.postgresql.org/docs/9.6/static/catalog-pg-range.html\n case\n when typ.typtype = 'r' then (\n select rng.rngsubtype\n from pg_catalog.pg_range as rng\n where rng.rngtypid = typ.oid\n limit 1\n )\n else null\n end as \"rangeSubTypeId\"\n from\n pg_catalog.pg_type as typ\n left join pg_catalog.pg_description as dsc on dsc.objoid = typ.oid and dsc.classoid = 'pg_catalog.pg_type'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = typ.typnamespace\n )\n select\n *\n from\n type_all as typ\n where\n typ.id in (\n select \"typeId\" from class\n union all\n select \"typeId\" from attribute\n union all\n select \"returnTypeId\" from procedure\n union all\n select unnest(\"argTypeIds\") from procedure\n union all\n -- If this type is a base type for *any* domain type, we will include it\n -- in our selection. This may mean we fetch more types than we need, but\n -- the alternative is to do some funky SQL recursion which would be hard\n -- code to read. So we prefer code readability over selecting like 3 or\n -- 4 less type rows.\n --\n -- We also do this for range sub types and array item types.\n select \"domainBaseTypeId\" from type_all\n union all\n select \"rangeSubTypeId\" from type_all\n union all\n select \"arrayItemTypeId\" from type_all\n )\n order by\n \"namespaceId\", \"name\"\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-constraint.html\n \"constraint\" as (\n select distinct on (con.conrelid, con.conkey, con.confrelid, con.confkey)\n 'constraint' as \"kind\",\n con.oid as \"id\",\n con.conname as \"name\",\n con.contype as \"type\",\n con.conrelid as \"classId\",\n nullif(con.confrelid, 0) as \"foreignClassId\",\n dsc.description as \"description\",\n con.conkey as \"keyAttributeNums\",\n con.confkey as \"foreignKeyAttributeNums\"\n from\n pg_catalog.pg_constraint as con\n inner join class on (con.conrelid = class.id)\n left join pg_catalog.pg_description as dsc on dsc.objoid = con.oid and dsc.classoid = 'pg_catalog.pg_constraint'::regclass\n where\n -- Only get constraints for classes we have selected.\n con.conrelid in (select \"id\" from class where \"namespaceId\" in (select \"id\" from namespace)) and\n case\n -- If this is a foreign key constraint, we want to ensure that the\n -- foreign class is also in the list of classes we have already\n -- selected.\n when con.contype = 'f' then con.confrelid in (select \"id\" from class where \"namespaceId\" in (select \"id\" from namespace))\n -- Otherwise, this should be true.\n else true\n end and\n -- We only want foreign key, primary key, and unique constraints. We\n -- made add support for more constraints in the future.\n con.contype in ('f', 'p', 'u')\n order by\n con.conrelid, con.conkey, con.confrelid, con.confkey, con.conname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-extension.html\n \"extension\" as (\n select\n 'extension' as \"kind\",\n ext.oid as \"id\",\n ext.extname as \"name\",\n ext.extnamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n ext.extrelocatable as \"relocatable\",\n ext.extversion as \"version\",\n ext.extconfig as \"configurationClassIds\",\n dsc.description as \"description\"\n from\n pg_catalog.pg_extension as ext\n left join pg_catalog.pg_description as dsc on dsc.objoid = ext.oid and dsc.classoid = 'pg_catalog.pg_extension'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = ext.extnamespace\n order by\n ext.extname, ext.oid\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-index.html\n \"indexes\" as (\n select\n 'index' as \"kind\",\n idx.indexrelid as \"id\",\n idx_more.relname as \"name\",\n nsp.nspname as \"namespaceName\",\n idx.indrelid as \"classId\",\n idx.indnatts as \"numberOfAttributes\",\n idx.indisunique as \"isUnique\",\n idx.indisprimary as \"isPrimary\",\n idx.indimmediate as \"isImmediate\", -- enforce uniqueness immediately on insert\n idx.indisreplident as \"isReplicaIdentity\",\n idx.indisvalid as \"isValid\", -- if false, don't use for queries\n idx.indkey as \"attributeNums\",\n am.amname as \"indexType\",\n ${\n serverVersionNum >= 90600\n ? `\\\n (\n select array_agg(pg_index_column_has_property(idx.indexrelid,n::int2,'asc'))\n from unnest(idx.indkey) with ordinality as ord(key,n)\n ) as \"attributePropertiesAsc\",\n (\n select array_agg(pg_index_column_has_property(idx.indexrelid,n::int2,'nulls_first'))\n from unnest(idx.indkey) with ordinality as ord(key,n)\n ) as \"attributePropertiesNullsFirst\",`\n : \"\"\n }\n dsc.description as \"description\"\n from\n pg_catalog.pg_index as idx\n inner join pg_catalog.pg_class idx_more on (idx.indexrelid = idx_more.oid)\n inner join class on (idx.indrelid = class.id)\n inner join pg_catalog.pg_namespace as nsp on (nsp.oid = idx_more.relnamespace)\n inner join pg_catalog.pg_am as am on (am.oid = idx_more.relam)\n left join pg_catalog.pg_description as dsc on dsc.objoid = idx.indexrelid and dsc.objsubid = 0 and dsc.classoid = 'pg_catalog.pg_class'::regclass\n where\n idx.indislive is not false and\n idx.indisexclusion is not true and -- exclusion index\n idx.indcheckxmin is not true and -- always valid?\n idx.indpred is null -- no partial index predicate\n order by\n idx.indrelid, idx.indexrelid\n )\nselect row_to_json(x) as object from namespace as x\nunion all\nselect row_to_json(x) as object from class as x\nunion all\nselect row_to_json(x) as object from attribute as x\nunion all\nselect row_to_json(x) as object from type as x\nunion all\nselect row_to_json(x) as object from \"constraint\" as x\nunion all\nselect row_to_json(x) as object from procedure as x\nunion all\nselect row_to_json(x) as object from extension as x\nunion all\nselect row_to_json(x) as object from indexes as x\n;\n`;\n}\n\nmodule.exports = {\n makeIntrospectionQuery,\n};\n"],"file":"introspectionQuery.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/introspectionQuery.js"],"names":["makeIntrospectionQuery","serverVersionNum","options","pgLegacyFunctionsOnly","module","exports"],"mappings":";;AACA;;;;;;;;AAQA,SAASA,sBAAT,CACEC,gBADF,EAEEC,OAA4C,GAAG,EAFjD,EAGU;AACR,QAAM;AAAEC,IAAAA;AAAF,MAA4BD,OAAlC;AACA,SAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA2EFD,gBAAgB,IAAI,MAApB,GACI,mBADJ,GAEI,kDACL;QAECE,qBAAqB,GAChB;;;;;sDADgB,GAOhB;;;;;;;;4GASN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiGCF,gBAAgB,IAAI,MAApB,GAA6B,iBAA7B,GAAiD,IAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA8KtDA,gBAAgB,IAAI,KAApB,GACK;;;;;;;;4CADL,GAUI,EACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA1XL;AA4ZD;;AAEDG,MAAM,CAACC,OAAP,GAAiB;AACfL,EAAAA;AADe,CAAjB","sourcesContent":["// @flow\n/*\n * IMPORTANT: when editing this file, ensure all operators (e.g. `@>`) are\n * specified in the correct namespace (e.g. `operator(pg_catalog.@>)`). It looks\n * weird, but it prevents clashes with extensions or user code that may\n * overload operators, e.g. extension `intarray` overloads `@>`.\n *\n * NOTE: I'm not doing this with `=` because that way lies madness.\n */\nfunction makeIntrospectionQuery(\n serverVersionNum: number,\n options: { pgLegacyFunctionsOnly?: boolean } = {}\n): string {\n const { pgLegacyFunctionsOnly } = options;\n return `\\\n-- @see https://www.postgresql.org/docs/9.5/static/catalogs.html\n-- @see https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/introspectionQuery.js\n--\n-- ## Parameters\n-- - \\`$1\\`: An array of strings that represent the namespaces we are introspecting.\n-- - \\`$2\\`: set true to include functions/tables/etc that come from extensions\nwith\n recursive accessible_roles(_oid) as (\n select oid _oid, pg_roles.*\n from pg_roles\n where rolname = current_user\n union all\n select pg_roles.oid _oid, pg_roles.*\n from pg_roles, accessible_roles, pg_auth_members\n where pg_auth_members.roleid = pg_roles.oid\n and pg_auth_members.member = accessible_roles._oid\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-namespace.html\n namespace as (\n select\n 'namespace' as \"kind\",\n nsp.oid as \"id\",\n nsp.nspname as \"name\",\n dsc.description as \"description\"\n from\n pg_catalog.pg_namespace as nsp\n left join pg_catalog.pg_description as dsc on dsc.objoid = nsp.oid and dsc.classoid = 'pg_catalog.pg_namespace'::regclass\n where\n nsp.nspname = any ($1)\n order by\n nsp.nspname\n ),\n -- Select all of the remote procedures we can use in this schema. This comes\n -- first so that we can select types and classes using the information we get\n -- from it.\n --\n -- @see https://www.postgresql.org/docs/9.6/static/catalog-pg-proc.html\n procedure as (\n select\n 'procedure' as \"kind\",\n pro.oid as \"id\",\n pro.proname as \"name\",\n dsc.description as \"description\",\n pro.pronamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n pro.proisstrict as \"isStrict\",\n pro.proretset as \"returnsSet\",\n case\n when pro.provolatile = 'i' then true\n when pro.provolatile = 's' then true\n else false\n end as \"isStable\",\n pro.prorettype as \"returnTypeId\",\n coalesce(pro.proallargtypes, pro.proargtypes) as \"argTypeIds\",\n coalesce(pro.proargmodes, array[]::text[]) as \"argModes\",\n coalesce(pro.proargnames, array[]::text[]) as \"argNames\",\n pro.pronargs as \"inputArgsCount\",\n pro.pronargdefaults as \"argDefaultsNum\",\n pro.procost as \"cost\",\n exists(select 1 from accessible_roles where has_function_privilege(accessible_roles.oid, pro.oid, 'EXECUTE')) as \"aclExecutable\",\n (select lanname from pg_catalog.pg_language where pg_language.oid = pro.prolang) as \"language\"\n from\n pg_catalog.pg_proc as pro\n left join pg_catalog.pg_description as dsc on dsc.objoid = pro.oid and dsc.classoid = 'pg_catalog.pg_proc'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = pro.pronamespace\n where\n pro.pronamespace in (select \"id\" from namespace) and\n -- Currently we don’t support functions with variadic arguments. In the\n -- future we may, but for now let’s just ignore functions with variadic\n -- arguments.\n -- TODO: Variadic arguments.\n pro.provariadic = 0 and\n -- Filter our aggregate functions and window functions.\n ${\n serverVersionNum >= 110000\n ? \"pro.prokind = 'f'\"\n : \"pro.proisagg = false and pro.proiswindow = false\"\n } and\n ${\n pgLegacyFunctionsOnly\n ? `\\\n -- We want to make sure the argument mode for all of our arguments is\n -- \\`IN\\` which means \\`proargmodes\\` will be null.\n pro.proargmodes is null and\n -- Do not select procedures that return \\`RECORD\\` (oid 2249).\n pro.prorettype operator(pg_catalog.<>) 2249 and`\n : `\\\n -- We want to make sure the argument modes for all of our arguments are\n -- \\`IN\\`, \\`OUT\\`, \\`INOUT\\`, or \\`TABLE\\` (not \\`VARIADIC\\`).\n (pro.proargmodes is null or pro.proargmodes operator(pg_catalog.<@) array['i','o','b','t']::\"char\"[]) and\n -- Do not select procedures that return \\`RECORD\\` (oid 2249) unless they\n -- have \\`OUT\\`, \\`INOUT\\`, or \\`TABLE\\` arguments to define the return type.\n (pro.prorettype operator(pg_catalog.<>) 2249 or pro.proargmodes && array['o','b','t']::\"char\"[]) and\n -- Do not select procedures that have \\`RECORD\\` arguments.\n (pro.proallargtypes is null or not (pro.proallargtypes operator(pg_catalog.@>) array[2249::oid])) and`\n }\n -- Do not select procedures that create range types. These are utility\n -- functions that really don’t need to be exposed in an API.\n pro.proname not in (\n select typ.typname\n from pg_catalog.pg_type as typ\n where typ.typtype = 'r'\n and typ.typnamespace = pro.pronamespace\n ) and\n -- Do not expose trigger functions (type trigger has oid 2279)\n pro.prorettype operator(pg_catalog.<>) 2279 and\n -- We don't want functions that will clash with GraphQL (treat them as private)\n pro.proname not like E'\\\\\\\\_\\\\\\\\_%' and\n -- We also don’t want procedures that have been defined in our namespace\n -- twice. This leads to duplicate fields in the API which throws an\n -- error. In the future we may support this case. For now though, it is\n -- too complex.\n (\n select count(pro2.*)\n from pg_catalog.pg_proc as pro2\n where pro2.pronamespace = pro.pronamespace\n and pro2.proname = pro.proname\n ) = 1 and\n ($2 is true or not exists(\n select 1\n from pg_catalog.pg_depend\n where pg_depend.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n and pg_depend.deptype = 'e'\n and pg_depend.classid = 'pg_catalog.pg_proc'::pg_catalog.regclass\n and pg_depend.objid = pro.oid\n ))\n order by\n pro.pronamespace, pro.proname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-class.html\n class as (\n select\n 'class' as \"kind\",\n rel.oid as \"id\",\n rel.relname as \"name\",\n rel.relkind as \"classKind\",\n dsc.description as \"description\",\n rel.relnamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n rel.reltype as \"typeId\",\n -- Here we determine whether or not we can use this class in a\n -- \\`SELECT\\`’s \\`FROM\\` clause. In order to determine this we look at them\n -- \\`relkind\\` column, if it is \\`i\\` (index) or \\`c\\` (composite), we cannot\n -- select this class. Otherwise we can.\n rel.relkind not in ('i', 'c') as \"isSelectable\",\n -- Here we are determining whether we can insert/update/delete a class.\n -- This is helpful as it lets us detect non-updatable views and then\n -- exclude them from being inserted/updated/deleted into. For more info\n -- on how \\`pg_catalog.pg_relation_is_updatable\\` works:\n --\n -- - https://www.postgresql.org/message-id/CAEZATCV2_qN9P3zbvADwME_TkYf2gR_X2cLQR4R+pqkwxGxqJg@mail.gmail.com\n -- - https://github.com/postgres/postgres/blob/2410a2543e77983dab1f63f48b2adcd23dba994e/src/backend/utils/adt/misc.c#L684\n -- - https://github.com/postgres/postgres/blob/3aff33aa687e47d52f453892498b30ac98a296af/src/backend/rewrite/rewriteHandler.c#L2351\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00010000') = B'00010000' as \"isDeletable\",\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00001000') = B'00001000' as \"isInsertable\",\n (pg_catalog.pg_relation_is_updatable(rel.oid, true)::bit(8) operator(pg_catalog.&) B'00000100') = B'00000100' as \"isUpdatable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'SELECT')) as \"aclSelectable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'INSERT')) as \"aclInsertable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'UPDATE')) as \"aclUpdatable\",\n exists(select 1 from accessible_roles where has_table_privilege(accessible_roles.oid, rel.oid, 'DELETE')) as \"aclDeletable\"\n from\n pg_catalog.pg_class as rel\n left join pg_catalog.pg_description as dsc on dsc.objoid = rel.oid and dsc.objsubid = 0 and dsc.classoid = 'pg_catalog.pg_class'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = rel.relnamespace\n where\n rel.relpersistence in ('p') and\n -- We don't want classes that will clash with GraphQL (treat them as private)\n rel.relname not like E'\\\\\\\\_\\\\\\\\_%' and\n rel.relkind in ('r', 'v', 'm', 'c', 'f') and\n ($2 is true or not exists(\n select 1\n from pg_catalog.pg_depend\n where pg_depend.refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n and pg_depend.deptype = 'e'\n and pg_depend.classid = 'pg_catalog.pg_class'::pg_catalog.regclass\n and pg_depend.objid = rel.oid\n ))\n order by\n rel.relnamespace, rel.relname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-attribute.html\n attribute as (\n select\n 'attribute' as \"kind\",\n att.attrelid as \"classId\",\n att.attnum as \"num\",\n att.attname as \"name\",\n dsc.description as \"description\",\n att.atttypid as \"typeId\",\n nullif(att.atttypmod, -1) as \"typeModifier\",\n att.attnotnull as \"isNotNull\",\n att.atthasdef as \"hasDefault\",\n ${serverVersionNum >= 100000 ? \"att.attidentity\" : \"''\"} as \"identity\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'SELECT')) as \"aclSelectable\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'INSERT')) as \"aclInsertable\",\n exists(select 1 from accessible_roles where has_column_privilege(accessible_roles.oid, att.attrelid, att.attname, 'UPDATE')) as \"aclUpdatable\",\n -- https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=c62dd80cdf149e2792b13c13777a539f5abb0370\n att.attacl is not null and exists(select 1 from aclexplode(att.attacl) aclitem where aclitem.privilege_type = 'SELECT' and grantee in (select oid from accessible_roles)) as \"columnLevelSelectGrant\"\n from\n pg_catalog.pg_attribute as att\n left join pg_catalog.pg_description as dsc on dsc.objoid = att.attrelid and dsc.objsubid = att.attnum and dsc.classoid = 'pg_catalog.pg_class'::regclass\n where\n att.attrelid in (select \"id\" from class) and\n att.attnum > 0 and\n -- We don't want attributes that will clash with GraphQL (treat them as private)\n att.attname not like E'\\\\\\\\_\\\\\\\\_%' and\n not att.attisdropped\n order by\n att.attrelid, att.attnum\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-type.html\n type as (\n -- Use another \\`WITH\\` statement here, because our \\`WHERE\\` clause will need\n -- to use it.\n with type_all as (\n select\n 'type' as \"kind\",\n typ.oid as \"id\",\n typ.typname as \"name\",\n dsc.description as \"description\",\n typ.typnamespace as \"namespaceId\",\n -- We include the namespace name in types only because we select so\n -- many types that are outside of our core set of namespaces. Having\n -- the namespace name is super helpful when generating SQL, so\n -- conditionally having namespace names for types is a pain.\n nsp.nspname as \"namespaceName\",\n typ.typtype as \"type\",\n typ.typcategory as \"category\",\n typ.typnotnull as \"domainIsNotNull\",\n nullif(typ.typelem, 0) as \"arrayItemTypeId\",\n typ.typlen as \"typeLength\",\n (typ.typelem <> 0 and typ.typlen = -1) as \"isPgArray\",\n nullif(typ.typrelid, 0) as \"classId\",\n nullif(typ.typbasetype, 0) as \"domainBaseTypeId\",\n nullif(typ.typtypmod, -1) as \"domainTypeModifier\",\n typ.typdefaultbin is not null as \"domainHasDefault\",\n -- If this type is an enum type, let’s select all of its enum variants.\n --\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-enum.html\n case\n when typ.typtype = 'e' then array(\n select enm.enumlabel\n from pg_catalog.pg_enum as enm\n where enm.enumtypid = typ.oid\n order by enm.enumsortorder\n )\n else null\n end as \"enumVariants\",\n -- If this type is a range type, we want to select the sub type of the\n -- range.\n --\n -- @see https://www.postgresql.org/docs/9.6/static/catalog-pg-range.html\n case\n when typ.typtype = 'r' then (\n select rng.rngsubtype\n from pg_catalog.pg_range as rng\n where rng.rngtypid = typ.oid\n limit 1\n )\n else null\n end as \"rangeSubTypeId\"\n from\n pg_catalog.pg_type as typ\n left join pg_catalog.pg_description as dsc on dsc.objoid = typ.oid and dsc.classoid = 'pg_catalog.pg_type'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = typ.typnamespace\n )\n select\n *\n from\n type_all as typ\n where\n typ.id in (\n select \"typeId\" from class\n union all\n select \"typeId\" from attribute\n union all\n select \"returnTypeId\" from procedure\n union all\n select unnest(\"argTypeIds\") from procedure\n union all\n -- If this type is a base type for *any* domain type, we will include it\n -- in our selection. This may mean we fetch more types than we need, but\n -- the alternative is to do some funky SQL recursion which would be hard\n -- code to read. So we prefer code readability over selecting like 3 or\n -- 4 less type rows.\n --\n -- We also do this for range sub types and array item types.\n select \"domainBaseTypeId\" from type_all\n union all\n select \"rangeSubTypeId\" from type_all\n union all\n select \"arrayItemTypeId\" from type_all\n )\n order by\n \"namespaceId\", \"name\"\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-constraint.html\n \"constraint\" as (\n select distinct on (con.conrelid, con.conkey, con.confrelid, con.confkey)\n 'constraint' as \"kind\",\n con.oid as \"id\",\n con.conname as \"name\",\n con.contype as \"type\",\n con.conrelid as \"classId\",\n nullif(con.confrelid, 0) as \"foreignClassId\",\n dsc.description as \"description\",\n con.conkey as \"keyAttributeNums\",\n con.confkey as \"foreignKeyAttributeNums\"\n from\n pg_catalog.pg_constraint as con\n inner join class on (con.conrelid = class.id)\n left join pg_catalog.pg_description as dsc on dsc.objoid = con.oid and dsc.classoid = 'pg_catalog.pg_constraint'::regclass\n where\n -- Only get constraints for classes we have selected.\n con.conrelid in (select \"id\" from class where \"namespaceId\" in (select \"id\" from namespace)) and\n case\n -- If this is a foreign key constraint, we want to ensure that the\n -- foreign class is also in the list of classes we have already\n -- selected.\n when con.contype = 'f' then con.confrelid in (select \"id\" from class where \"namespaceId\" in (select \"id\" from namespace))\n -- Otherwise, this should be true.\n else true\n end and\n -- We only want foreign key, primary key, and unique constraints. We\n -- made add support for more constraints in the future.\n con.contype in ('f', 'p', 'u')\n order by\n con.conrelid, con.conkey, con.confrelid, con.confkey, con.conname\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-extension.html\n \"extension\" as (\n select\n 'extension' as \"kind\",\n ext.oid as \"id\",\n ext.extname as \"name\",\n ext.extnamespace as \"namespaceId\",\n nsp.nspname as \"namespaceName\",\n ext.extrelocatable as \"relocatable\",\n ext.extversion as \"version\",\n ext.extconfig as \"configurationClassIds\",\n dsc.description as \"description\"\n from\n pg_catalog.pg_extension as ext\n left join pg_catalog.pg_description as dsc on dsc.objoid = ext.oid and dsc.classoid = 'pg_catalog.pg_extension'::regclass\n left join pg_catalog.pg_namespace as nsp on nsp.oid = ext.extnamespace\n order by\n ext.extname, ext.oid\n ),\n -- @see https://www.postgresql.org/docs/9.5/static/catalog-pg-index.html\n \"indexes\" as (\n select\n 'index' as \"kind\",\n idx.indexrelid as \"id\",\n idx_more.relname as \"name\",\n nsp.nspname as \"namespaceName\",\n idx.indrelid as \"classId\",\n idx.indnatts as \"numberOfAttributes\",\n idx.indisunique as \"isUnique\",\n idx.indisprimary as \"isPrimary\",\n idx.indimmediate as \"isImmediate\", -- enforce uniqueness immediately on insert\n idx.indisreplident as \"isReplicaIdentity\",\n idx.indisvalid as \"isValid\", -- if false, don't use for queries\n idx.indpred is not null as \"isPartial\", -- if true, index is not on on rows.\n idx.indkey as \"attributeNums\",\n am.amname as \"indexType\",\n ${\n serverVersionNum >= 90600\n ? `\\\n (\n select array_agg(pg_index_column_has_property(idx.indexrelid,n::int2,'asc'))\n from unnest(idx.indkey) with ordinality as ord(key,n)\n ) as \"attributePropertiesAsc\",\n (\n select array_agg(pg_index_column_has_property(idx.indexrelid,n::int2,'nulls_first'))\n from unnest(idx.indkey) with ordinality as ord(key,n)\n ) as \"attributePropertiesNullsFirst\",`\n : \"\"\n }\n dsc.description as \"description\"\n from\n pg_catalog.pg_index as idx\n inner join pg_catalog.pg_class idx_more on (idx.indexrelid = idx_more.oid)\n inner join class on (idx.indrelid = class.id)\n inner join pg_catalog.pg_namespace as nsp on (nsp.oid = idx_more.relnamespace)\n inner join pg_catalog.pg_am as am on (am.oid = idx_more.relam)\n left join pg_catalog.pg_description as dsc on dsc.objoid = idx.indexrelid and dsc.objsubid = 0 and dsc.classoid = 'pg_catalog.pg_class'::regclass\n where\n idx.indislive is not false and\n idx.indisexclusion is not true and -- exclusion index\n idx.indcheckxmin is not true and -- always valid?\n idx.indpred is null -- no partial index predicate\n order by\n idx.indrelid, idx.indexrelid\n )\nselect row_to_json(x) as object from namespace as x\nunion all\nselect row_to_json(x) as object from class as x\nunion all\nselect row_to_json(x) as object from attribute as x\nunion all\nselect row_to_json(x) as object from type as x\nunion all\nselect row_to_json(x) as object from \"constraint\" as x\nunion all\nselect row_to_json(x) as object from procedure as x\nunion all\nselect row_to_json(x) as object from extension as x\nunion all\nselect row_to_json(x) as object from indexes as x\n;\n`;\n}\n\nmodule.exports = {\n makeIntrospectionQuery,\n};\n"],"file":"introspectionQuery.js"}
|
|
@@ -257,7 +257,14 @@ exists(
|
|
|
257
257
|
if (queryBuilder.isOrderUnique() && orderBy.length > 0) {
|
|
258
258
|
return sql.fragment`json_build_array(${sql.join([...getPgCursorPrefix(), sql.fragment`json_build_array(${sql.join(orderBy, ", ")})`], ", ")})`;
|
|
259
259
|
} else {
|
|
260
|
-
return sql.fragment`json_build_array(${sql.join(getPgCursorPrefix(), ", ")},
|
|
260
|
+
return sql.fragment`json_build_array(${sql.join(getPgCursorPrefix(), ", ")}, ${
|
|
261
|
+
/*
|
|
262
|
+
* NOTE[useAsterisk/row_number]: If we have useAsterisk then the
|
|
263
|
+
* query with limit offset is in a subquery, so our row_number()
|
|
264
|
+
* call doesn't know about it. Here we add the offset back in
|
|
265
|
+
* again. See matching NOTE in QueryBuilder.js.
|
|
266
|
+
*/
|
|
267
|
+
options.useAsterisk ? sql.fragment`${sql.literal(queryBuilder.getFinalOffset() || 0)} + ` : sql.fragment``}(row_number() over (partition by 1)))`;
|
|
261
268
|
}
|
|
262
269
|
});
|
|
263
270
|
}
|
|
@@ -297,7 +297,19 @@ exists(
|
|
|
297
297
|
return sql.fragment`json_build_array(${sql.join(
|
|
298
298
|
getPgCursorPrefix(),
|
|
299
299
|
", "
|
|
300
|
-
)},
|
|
300
|
+
)}, ${
|
|
301
|
+
/*
|
|
302
|
+
* NOTE[useAsterisk/row_number]: If we have useAsterisk then the
|
|
303
|
+
* query with limit offset is in a subquery, so our row_number()
|
|
304
|
+
* call doesn't know about it. Here we add the offset back in
|
|
305
|
+
* again. See matching NOTE in QueryBuilder.js.
|
|
306
|
+
*/
|
|
307
|
+
options.useAsterisk
|
|
308
|
+
? sql.fragment`${sql.literal(
|
|
309
|
+
queryBuilder.getFinalOffset() || 0
|
|
310
|
+
)} + `
|
|
311
|
+
: sql.fragment``
|
|
312
|
+
}(row_number() over (partition by 1)))`;
|
|
301
313
|
}
|
|
302
314
|
});
|
|
303
315
|
}
|