UNPKG

@graphql-codegen/python-operations

Version:

Document-driven GraphQL Code Generator plugin that emits Python operation types (per-operation result + variables).

33 lines (32 loc) • 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pyFieldName = exports.PYTHON_SCALARS = exports.isValidClassAttr = exports.isReservedField = void 0; exports.resultFieldKey = resultFieldKey; exports.fieldKey = fieldKey; const python_common_1 = require("@graphql-codegen/python-common"); Object.defineProperty(exports, "isReservedField", { enumerable: true, get: function () { return python_common_1.isReservedField; } }); Object.defineProperty(exports, "isValidClassAttr", { enumerable: true, get: function () { return python_common_1.isValidClassAttr; } }); Object.defineProperty(exports, "pyFieldName", { enumerable: true, get: function () { return python_common_1.pythonFieldName; } }); Object.defineProperty(exports, "PYTHON_SCALARS", { enumerable: true, get: function () { return python_common_1.PYTHON_SCALARS; } }); /** * Compute the attribute name for a `BaseModel` result class. Under `'snakeCase'` * the key is snake-cased (keywords suffixed with `_`); under `'keep'` the wire * name is used verbatim, but — because `BaseModel` classes cannot use functional * `TypedDict` syntax — a keyword / non-identifier name still falls back to a * trailing `_`. */ function resultFieldKey(name, convention) { if (convention === 'snakeCase') { return (0, python_common_1.pythonFieldName)(name); } return (0, python_common_1.isValidClassAttr)(name) ? name : `${name}_`; } /** * Compute the `TypedDict` key for a GraphQL response / variable name under the * given naming convention. Under `'keep'` the raw name is returned verbatim * (functional `TypedDict` syntax handles invalid keys); under `'snakeCase'` the * legacy snake_case + `_`-suffix behavior is applied. */ function fieldKey(name, convention) { return convention === 'snakeCase' ? (0, python_common_1.pythonFieldName)(name) : name; }