@graphitation/supermassive 3.15.1 → 3.16.1-canary.0
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/.eslintcache +1 -1
- package/CHANGELOG.md +10 -2
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +43 -4
- package/lib/executeWithoutSchema.js.map +2 -2
- package/lib/executeWithoutSchema.mjs +43 -4
- package/lib/executeWithoutSchema.mjs.map +2 -2
- package/lib/schema/definition.d.ts +54 -19
- package/lib/schema/definition.d.ts.map +1 -1
- package/lib/schema/definition.js +127 -18
- package/lib/schema/definition.js.map +3 -3
- package/lib/schema/definition.mjs +109 -16
- package/lib/schema/definition.mjs.map +2 -2
- package/lib/schema/directives.d.ts.map +1 -1
- package/lib/schema/directives.js +3 -3
- package/lib/schema/directives.js.map +2 -2
- package/lib/schema/directives.mjs +4 -4
- package/lib/schema/directives.mjs.map +2 -2
- package/lib/utilities/decodeASTSchema.d.ts.map +1 -1
- package/lib/utilities/decodeASTSchema.js +185 -33
- package/lib/utilities/decodeASTSchema.js.map +2 -2
- package/lib/utilities/decodeASTSchema.mjs +196 -36
- package/lib/utilities/decodeASTSchema.mjs.map +2 -2
- package/lib/utilities/encodeASTSchema.d.ts +5 -1
- package/lib/utilities/encodeASTSchema.d.ts.map +1 -1
- package/lib/utilities/encodeASTSchema.js +171 -38
- package/lib/utilities/encodeASTSchema.js.map +2 -2
- package/lib/utilities/encodeASTSchema.mjs +171 -38
- package/lib/utilities/encodeASTSchema.mjs.map +2 -2
- package/lib/utilities/extractMinimalViableSchemaForRequestDocument.js +1 -1
- package/lib/utilities/extractMinimalViableSchemaForRequestDocument.js.map +2 -2
- package/lib/utilities/extractMinimalViableSchemaForRequestDocument.mjs +2 -2
- package/lib/utilities/extractMinimalViableSchemaForRequestDocument.mjs.map +2 -2
- package/lib/utilities/mergeSchemaDefinitions.d.ts.map +1 -1
- package/lib/utilities/mergeSchemaDefinitions.js +52 -2
- package/lib/utilities/mergeSchemaDefinitions.js.map +3 -3
- package/lib/utilities/mergeSchemaDefinitions.mjs +59 -4
- package/lib/utilities/mergeSchemaDefinitions.mjs.map +3 -3
- package/lib/utilities/subtractSchemaDefinitions.js +4 -4
- package/lib/utilities/subtractSchemaDefinitions.js.map +2 -2
- package/lib/utilities/subtractSchemaDefinitions.mjs +5 -5
- package/lib/utilities/subtractSchemaDefinitions.mjs.map +2 -2
- package/lib/values.js +2 -2
- package/lib/values.js.map +2 -2
- package/lib/values.mjs +4 -4
- package/lib/values.mjs.map +2 -2
- package/package.json +1 -1
|
@@ -280,9 +280,9 @@ function subtractEnumValues(typeName, minuendValues, subtrahendValues, strict) {
|
|
|
280
280
|
function subtractDirectives(minuendDirectives, subtrahendDirectives, strict) {
|
|
281
281
|
const result = [];
|
|
282
282
|
for (const minuendDirective of minuendDirectives) {
|
|
283
|
-
const minuendName = (0, import_definition.
|
|
283
|
+
const minuendName = (0, import_definition.getDirectiveDefinitionName)(minuendDirective);
|
|
284
284
|
const subtrahendDirective = subtrahendDirectives.find(
|
|
285
|
-
(d) => (0, import_definition.
|
|
285
|
+
(d) => (0, import_definition.getDirectiveDefinitionName)(d) === minuendName
|
|
286
286
|
);
|
|
287
287
|
if (!subtrahendDirective) {
|
|
288
288
|
result.push(minuendDirective);
|
|
@@ -318,9 +318,9 @@ function subtractDirectives(minuendDirectives, subtrahendDirectives, strict) {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
for (const subtrahendDirective of subtrahendDirectives) {
|
|
321
|
-
const subtrahendName = (0, import_definition.
|
|
321
|
+
const subtrahendName = (0, import_definition.getDirectiveDefinitionName)(subtrahendDirective);
|
|
322
322
|
const exists = minuendDirectives.some(
|
|
323
|
-
(d) => (0, import_definition.
|
|
323
|
+
(d) => (0, import_definition.getDirectiveDefinitionName)(d) === subtrahendName
|
|
324
324
|
);
|
|
325
325
|
if (!exists) {
|
|
326
326
|
if (strict) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utilities/subtractSchemaDefinitions.ts"],
|
|
4
|
-
"sourcesContent": ["// Note: this utility is vibe-coded. Use at your own risk! :)\nimport {\n SchemaDefinitions,\n DirectiveDefinitionTuple,\n FieldDefinitionRecord,\n InputValueDefinitionRecord,\n TypeDefinitionsRecord,\n TypeDefinitionTuple,\n getDirectiveDefinitionArgs,\n getDirectiveName,\n getEnumValues,\n getFieldTypeReference,\n getFieldArgs,\n getFields,\n getInputObjectFields,\n getInputValueTypeReference,\n getUnionTypeMembers,\n isEnumTypeDefinition,\n isInputObjectTypeDefinition,\n isInterfaceTypeDefinition,\n isObjectTypeDefinition,\n isScalarTypeDefinition,\n isUnionTypeDefinition,\n createEnumTypeDefinition,\n createInputObjectTypeDefinition,\n createInterfaceTypeDefinition,\n createObjectTypeDefinition,\n createUnionTypeDefinition,\n getObjectTypeInterfaces,\n getInterfaceTypeInterfaces,\n} from \"../schema/definition\";\nimport { inspect } from \"../jsutils/inspect\";\n\n/**\n * Subtracts schema definitions from minuend that exist in subtrahend.\n * Returns a new SchemaDefinitions object without mutating inputs.\n *\n * @param minuend - The schema definitions to subtract from\n * @param subtrahend - The schema definitions to subtract\n * @param strict - If true, throws errors on items in subtrahend that are not in minuend; if false, ignores them\n * @returns A new SchemaDefinitions with elements from minuend not in subtrahend\n */\nexport function subtractSchemaDefinitions(\n minuend: SchemaDefinitions,\n subtrahend: SchemaDefinitions,\n strict = false,\n): SchemaDefinitions {\n const result: SchemaDefinitions = {\n types: {},\n directives: [],\n };\n\n // Subtract types\n if (minuend.types && subtrahend.types) {\n result.types = subtractTypes(minuend.types, subtrahend.types, strict);\n } else if (minuend.types) {\n result.types = { ...minuend.types };\n }\n\n // Subtract directives\n if (minuend.directives && subtrahend.directives) {\n result.directives = subtractDirectives(\n minuend.directives,\n subtrahend.directives,\n strict,\n );\n } else if (minuend.directives) {\n result.directives = [...minuend.directives];\n }\n\n return result;\n}\n\n/**\n * Subtracts types from minuend that exist in subtrahend.\n */\nfunction subtractTypes(\n minuend: TypeDefinitionsRecord,\n subtrahend: TypeDefinitionsRecord,\n strict: boolean,\n): TypeDefinitionsRecord {\n const result: TypeDefinitionsRecord = {};\n\n for (const [typeName, minuendDef] of Object.entries(minuend)) {\n const subtrahendDef = subtrahend[typeName];\n\n if (!subtrahendDef) {\n // Type doesn't exist in subtrahend, keep it\n result[typeName] = minuendDef;\n continue;\n }\n\n // Validate type kinds match\n if (minuendDef[0] !== subtrahendDef[0]) {\n throw new Error(\n `Type ${typeName} is represented differently in different schema fragments:\\n` +\n inspect(minuendDef) +\n `\\n` +\n inspect(subtrahendDef),\n );\n }\n\n // Handle different type kinds\n const subtractedType = subtractType(\n typeName,\n minuendDef,\n subtrahendDef,\n strict,\n );\n if (subtractedType) {\n result[typeName] = subtractedType;\n }\n }\n\n // Check for types in subtrahend that don't exist in minuend\n for (const typeName of Object.keys(subtrahend)) {\n if (!(typeName in minuend)) {\n if (strict) {\n throw new Error(`Type ${typeName} does not exist in minuend`);\n }\n // In non-strict mode, ignore missing types\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts a single type definition.\n */\nfunction subtractType(\n typeName: string,\n minuendDef: TypeDefinitionTuple,\n subtrahendDef: TypeDefinitionTuple,\n strict: boolean,\n): TypeDefinitionTuple | null {\n if (\n isObjectTypeDefinition(minuendDef) &&\n isObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getObjectTypeInterfaces(minuendDef);\n return createObjectTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInterfaceTypeDefinition(minuendDef) &&\n isInterfaceTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getInterfaceTypeInterfaces(minuendDef);\n return createInterfaceTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInputObjectTypeDefinition(minuendDef) &&\n isInputObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractInputFields(\n typeName,\n getInputObjectFields(minuendDef),\n getInputObjectFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n return createInputObjectTypeDefinition(subtractedFields);\n }\n\n if (\n isUnionTypeDefinition(minuendDef) &&\n isUnionTypeDefinition(subtrahendDef)\n ) {\n const subtractedMembers = subtractUnionMembers(\n typeName,\n getUnionTypeMembers(minuendDef),\n getUnionTypeMembers(subtrahendDef),\n strict,\n );\n if (subtractedMembers.length === 0) {\n return null; // All members removed\n }\n return createUnionTypeDefinition(subtractedMembers);\n }\n\n if (isEnumTypeDefinition(minuendDef) && isEnumTypeDefinition(subtrahendDef)) {\n const subtractedValues = subtractEnumValues(\n typeName,\n getEnumValues(minuendDef),\n getEnumValues(subtrahendDef),\n strict,\n );\n if (subtractedValues.length === 0) {\n return null; // All values removed\n }\n return createEnumTypeDefinition(subtractedValues);\n }\n\n if (\n isScalarTypeDefinition(minuendDef) &&\n isScalarTypeDefinition(subtrahendDef)\n ) {\n // Scalars are atomic - if subtrahend has it, remove entire scalar\n return null;\n }\n\n return null;\n}\n\n/**\n * Subtracts fields from object/interface types.\n */\nfunction subtractFields(\n typeName: string,\n minuendFields: FieldDefinitionRecord,\n subtrahendFields: FieldDefinitionRecord,\n strict: boolean,\n): FieldDefinitionRecord {\n const result: FieldDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getFieldTypeReference(minuendField);\n const subtrahendType = getFieldTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Validate field arguments match exactly\n const minuendArgs = getFieldArgs(minuendField);\n const subtrahendArgs = getFieldArgs(subtrahendField);\n\n // Both must have same argument structure\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, field can be subtracted\n } else if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - not exact match\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument structures.`,\n );\n } else {\n // Both have arguments, compare them\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} argument ${argName} has different types.`,\n );\n }\n }\n }\n\n // Field exists in subtrahend and matches exactly, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts input fields from input object types.\n */\nfunction subtractInputFields(\n typeName: string,\n minuendFields: InputValueDefinitionRecord,\n subtrahendFields: InputValueDefinitionRecord,\n strict: boolean,\n): InputValueDefinitionRecord {\n const result: InputValueDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getInputValueTypeReference(minuendField);\n const subtrahendType = getInputValueTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Input field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Field exists in subtrahend, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Input field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts union members.\n */\nfunction subtractUnionMembers(\n typeName: string,\n minuendMembers: string[],\n subtrahendMembers: string[],\n strict: boolean,\n): string[] {\n // Union types must match exactly for subtraction\n const minuendSet = new Set(minuendMembers);\n const subtrahendSet = new Set(subtrahendMembers);\n\n // Check if they have the same members\n if (\n minuendMembers.length === subtrahendMembers.length &&\n minuendMembers.every((member) => subtrahendSet.has(member))\n ) {\n // Exact match - remove the entire union\n return [];\n }\n\n // Check for members in subtrahend that don't exist in minuend\n for (const member of subtrahendMembers) {\n if (!minuendSet.has(member)) {\n if (strict) {\n throw new Error(\n `Union ${typeName}: member ${member} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing members and keep the original union\n return minuendMembers;\n }\n }\n\n // If we get here, all subtrahend members exist in minuend but they don't match exactly\n throw new Error(\n `Union types must match exactly for subtraction. Union ${typeName} has different member sets.`,\n );\n}\n\n/**\n * Subtracts enum values.\n */\nfunction subtractEnumValues(\n typeName: string,\n minuendValues: string[],\n subtrahendValues: string[],\n strict: boolean,\n): string[] {\n // Enum types must match exactly for subtraction\n const minuendSet = new Set(minuendValues);\n const subtrahendSet = new Set(subtrahendValues);\n\n // Check if they have the same values\n if (\n minuendValues.length === subtrahendValues.length &&\n minuendValues.every((value) => subtrahendSet.has(value))\n ) {\n // Exact match - remove the entire enum\n return [];\n }\n\n // Check for values in subtrahend that don't exist in minuend\n for (const value of subtrahendValues) {\n if (!minuendSet.has(value)) {\n if (strict) {\n throw new Error(\n `Enum ${typeName}: value ${value} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing values and keep the original enum\n return minuendValues;\n }\n }\n\n // If we get here, all subtrahend values exist in minuend but they don't match exactly\n throw new Error(\n `Enum types must match exactly for subtraction. Enum ${typeName} has different value sets.`,\n );\n}\n\n/**\n * Subtracts directives.\n */\nfunction subtractDirectives(\n minuendDirectives: DirectiveDefinitionTuple[],\n subtrahendDirectives: DirectiveDefinitionTuple[],\n strict: boolean,\n): DirectiveDefinitionTuple[] {\n const result: DirectiveDefinitionTuple[] = [];\n\n for (const minuendDirective of minuendDirectives) {\n const minuendName = getDirectiveName(minuendDirective);\n const subtrahendDirective = subtrahendDirectives.find(\n (d) => getDirectiveName(d) === minuendName,\n );\n\n if (!subtrahendDirective) {\n // Directive doesn't exist in subtrahend, keep it\n result.push(minuendDirective);\n continue;\n }\n\n // Directive exists, check arguments\n const minuendArgs = getDirectiveDefinitionArgs(minuendDirective);\n const subtrahendArgs = getDirectiveDefinitionArgs(subtrahendDirective);\n\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, remove entire directive\n continue;\n }\n\n if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - arguments don't match exactly\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument structures.`,\n );\n }\n\n // Both have arguments, check if they match exactly\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} argument ${argName} has different types.`,\n );\n }\n }\n\n // Arguments match exactly, remove entire directive\n }\n\n // Check for directives in subtrahend that don't exist in minuend\n for (const subtrahendDirective of subtrahendDirectives) {\n const subtrahendName = getDirectiveName(subtrahendDirective);\n const exists = minuendDirectives.some(\n (d) => getDirectiveName(d) === subtrahendName,\n );\n if (!exists) {\n if (strict) {\n throw new Error(\n `Directive ${subtrahendName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing directives\n }\n }\n\n return result;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBA6BO;AACP,qBAAwB;AAWjB,SAAS,0BACd,SACA,YACA,SAAS,OACU;AACnB,QAAM,SAA4B;AAAA,IAChC,OAAO,CAAC;AAAA,IACR,YAAY,CAAC;AAAA,EACf;AAGA,MAAI,QAAQ,SAAS,WAAW,OAAO;AACrC,WAAO,QAAQ,cAAc,QAAQ,OAAO,WAAW,OAAO,MAAM;AAAA,EACtE,WAAW,QAAQ,OAAO;AACxB,WAAO,QAAQ,EAAE,GAAG,QAAQ,MAAM;AAAA,EACpC;AAGA,MAAI,QAAQ,cAAc,WAAW,YAAY;AAC/C,WAAO,aAAa;AAAA,MAClB,QAAQ;AAAA,MACR,WAAW;AAAA,MACX;AAAA,IACF;AAAA,EACF,WAAW,QAAQ,YAAY;AAC7B,WAAO,aAAa,CAAC,GAAG,QAAQ,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eACA,kBACA,QACU;AAEV,QAAM,aAAa,IAAI,IAAI,aAAa;AACxC,QAAM,gBAAgB,IAAI,IAAI,gBAAgB;AAG9C,MACE,cAAc,WAAW,iBAAiB,UAC1C,cAAc,MAAM,CAAC,UAAU,cAAc,IAAI,KAAK,CAAC,GACvD;AAEA,WAAO,CAAC;AAAA,EACV;AAGA,aAAW,SAAS,kBAAkB;AACpC,QAAI,CAAC,WAAW,IAAI,KAAK,GAAG;AAC1B,UAAI,QAAQ;AACV,cAAM,IAAI;AAAA,UACR,QAAQ,mBAAmB;AAAA,QAC7B;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR,uDAAuD;AAAA,EACzD;AACF;AAKA,SAAS,mBACP,mBACA,sBACA,QAC4B;AAC5B,QAAM,SAAqC,CAAC;AAE5C,aAAW,oBAAoB,mBAAmB;AAChD,UAAM,kBAAc,
|
|
4
|
+
"sourcesContent": ["// Note: this utility is vibe-coded. Use at your own risk! :)\nimport {\n SchemaDefinitions,\n DirectiveDefinitionTuple,\n FieldDefinitionRecord,\n InputValueDefinitionRecord,\n TypeDefinitionsRecord,\n TypeDefinitionTuple,\n getDirectiveDefinitionArgs,\n getDirectiveDefinitionName,\n getEnumValues,\n getFieldTypeReference,\n getFieldArgs,\n getFields,\n getInputObjectFields,\n getInputValueTypeReference,\n getUnionTypeMembers,\n isEnumTypeDefinition,\n isInputObjectTypeDefinition,\n isInterfaceTypeDefinition,\n isObjectTypeDefinition,\n isScalarTypeDefinition,\n isUnionTypeDefinition,\n createEnumTypeDefinition,\n createInputObjectTypeDefinition,\n createInterfaceTypeDefinition,\n createObjectTypeDefinition,\n createUnionTypeDefinition,\n getObjectTypeInterfaces,\n getInterfaceTypeInterfaces,\n} from \"../schema/definition\";\nimport { inspect } from \"../jsutils/inspect\";\n\n/**\n * Subtracts schema definitions from minuend that exist in subtrahend.\n * Returns a new SchemaDefinitions object without mutating inputs.\n *\n * @param minuend - The schema definitions to subtract from\n * @param subtrahend - The schema definitions to subtract\n * @param strict - If true, throws errors on items in subtrahend that are not in minuend; if false, ignores them\n * @returns A new SchemaDefinitions with elements from minuend not in subtrahend\n */\nexport function subtractSchemaDefinitions(\n minuend: SchemaDefinitions,\n subtrahend: SchemaDefinitions,\n strict = false,\n): SchemaDefinitions {\n const result: SchemaDefinitions = {\n types: {},\n directives: [],\n };\n\n // Subtract types\n if (minuend.types && subtrahend.types) {\n result.types = subtractTypes(minuend.types, subtrahend.types, strict);\n } else if (minuend.types) {\n result.types = { ...minuend.types };\n }\n\n // Subtract directives\n if (minuend.directives && subtrahend.directives) {\n result.directives = subtractDirectives(\n minuend.directives,\n subtrahend.directives,\n strict,\n );\n } else if (minuend.directives) {\n result.directives = [...minuend.directives];\n }\n\n return result;\n}\n\n/**\n * Subtracts types from minuend that exist in subtrahend.\n */\nfunction subtractTypes(\n minuend: TypeDefinitionsRecord,\n subtrahend: TypeDefinitionsRecord,\n strict: boolean,\n): TypeDefinitionsRecord {\n const result: TypeDefinitionsRecord = {};\n\n for (const [typeName, minuendDef] of Object.entries(minuend)) {\n const subtrahendDef = subtrahend[typeName];\n\n if (!subtrahendDef) {\n // Type doesn't exist in subtrahend, keep it\n result[typeName] = minuendDef;\n continue;\n }\n\n // Validate type kinds match\n if (minuendDef[0] !== subtrahendDef[0]) {\n throw new Error(\n `Type ${typeName} is represented differently in different schema fragments:\\n` +\n inspect(minuendDef) +\n `\\n` +\n inspect(subtrahendDef),\n );\n }\n\n // Handle different type kinds\n const subtractedType = subtractType(\n typeName,\n minuendDef,\n subtrahendDef,\n strict,\n );\n if (subtractedType) {\n result[typeName] = subtractedType;\n }\n }\n\n // Check for types in subtrahend that don't exist in minuend\n for (const typeName of Object.keys(subtrahend)) {\n if (!(typeName in minuend)) {\n if (strict) {\n throw new Error(`Type ${typeName} does not exist in minuend`);\n }\n // In non-strict mode, ignore missing types\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts a single type definition.\n */\nfunction subtractType(\n typeName: string,\n minuendDef: TypeDefinitionTuple,\n subtrahendDef: TypeDefinitionTuple,\n strict: boolean,\n): TypeDefinitionTuple | null {\n if (\n isObjectTypeDefinition(minuendDef) &&\n isObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getObjectTypeInterfaces(minuendDef);\n return createObjectTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInterfaceTypeDefinition(minuendDef) &&\n isInterfaceTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getInterfaceTypeInterfaces(minuendDef);\n return createInterfaceTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInputObjectTypeDefinition(minuendDef) &&\n isInputObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractInputFields(\n typeName,\n getInputObjectFields(minuendDef),\n getInputObjectFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n return createInputObjectTypeDefinition(subtractedFields);\n }\n\n if (\n isUnionTypeDefinition(minuendDef) &&\n isUnionTypeDefinition(subtrahendDef)\n ) {\n const subtractedMembers = subtractUnionMembers(\n typeName,\n getUnionTypeMembers(minuendDef),\n getUnionTypeMembers(subtrahendDef),\n strict,\n );\n if (subtractedMembers.length === 0) {\n return null; // All members removed\n }\n return createUnionTypeDefinition(subtractedMembers);\n }\n\n if (isEnumTypeDefinition(minuendDef) && isEnumTypeDefinition(subtrahendDef)) {\n const subtractedValues = subtractEnumValues(\n typeName,\n getEnumValues(minuendDef),\n getEnumValues(subtrahendDef),\n strict,\n );\n if (subtractedValues.length === 0) {\n return null; // All values removed\n }\n return createEnumTypeDefinition(subtractedValues);\n }\n\n if (\n isScalarTypeDefinition(minuendDef) &&\n isScalarTypeDefinition(subtrahendDef)\n ) {\n // Scalars are atomic - if subtrahend has it, remove entire scalar\n return null;\n }\n\n return null;\n}\n\n/**\n * Subtracts fields from object/interface types.\n */\nfunction subtractFields(\n typeName: string,\n minuendFields: FieldDefinitionRecord,\n subtrahendFields: FieldDefinitionRecord,\n strict: boolean,\n): FieldDefinitionRecord {\n const result: FieldDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getFieldTypeReference(minuendField);\n const subtrahendType = getFieldTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Validate field arguments match exactly\n const minuendArgs = getFieldArgs(minuendField);\n const subtrahendArgs = getFieldArgs(subtrahendField);\n\n // Both must have same argument structure\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, field can be subtracted\n } else if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - not exact match\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument structures.`,\n );\n } else {\n // Both have arguments, compare them\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} argument ${argName} has different types.`,\n );\n }\n }\n }\n\n // Field exists in subtrahend and matches exactly, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts input fields from input object types.\n */\nfunction subtractInputFields(\n typeName: string,\n minuendFields: InputValueDefinitionRecord,\n subtrahendFields: InputValueDefinitionRecord,\n strict: boolean,\n): InputValueDefinitionRecord {\n const result: InputValueDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getInputValueTypeReference(minuendField);\n const subtrahendType = getInputValueTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Input field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Field exists in subtrahend, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Input field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts union members.\n */\nfunction subtractUnionMembers(\n typeName: string,\n minuendMembers: string[],\n subtrahendMembers: string[],\n strict: boolean,\n): string[] {\n // Union types must match exactly for subtraction\n const minuendSet = new Set(minuendMembers);\n const subtrahendSet = new Set(subtrahendMembers);\n\n // Check if they have the same members\n if (\n minuendMembers.length === subtrahendMembers.length &&\n minuendMembers.every((member) => subtrahendSet.has(member))\n ) {\n // Exact match - remove the entire union\n return [];\n }\n\n // Check for members in subtrahend that don't exist in minuend\n for (const member of subtrahendMembers) {\n if (!minuendSet.has(member)) {\n if (strict) {\n throw new Error(\n `Union ${typeName}: member ${member} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing members and keep the original union\n return minuendMembers;\n }\n }\n\n // If we get here, all subtrahend members exist in minuend but they don't match exactly\n throw new Error(\n `Union types must match exactly for subtraction. Union ${typeName} has different member sets.`,\n );\n}\n\n/**\n * Subtracts enum values.\n */\nfunction subtractEnumValues(\n typeName: string,\n minuendValues: string[],\n subtrahendValues: string[],\n strict: boolean,\n): string[] {\n // Enum types must match exactly for subtraction\n const minuendSet = new Set(minuendValues);\n const subtrahendSet = new Set(subtrahendValues);\n\n // Check if they have the same values\n if (\n minuendValues.length === subtrahendValues.length &&\n minuendValues.every((value) => subtrahendSet.has(value))\n ) {\n // Exact match - remove the entire enum\n return [];\n }\n\n // Check for values in subtrahend that don't exist in minuend\n for (const value of subtrahendValues) {\n if (!minuendSet.has(value)) {\n if (strict) {\n throw new Error(\n `Enum ${typeName}: value ${value} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing values and keep the original enum\n return minuendValues;\n }\n }\n\n // If we get here, all subtrahend values exist in minuend but they don't match exactly\n throw new Error(\n `Enum types must match exactly for subtraction. Enum ${typeName} has different value sets.`,\n );\n}\n\n/**\n * Subtracts directives.\n */\nfunction subtractDirectives(\n minuendDirectives: DirectiveDefinitionTuple[],\n subtrahendDirectives: DirectiveDefinitionTuple[],\n strict: boolean,\n): DirectiveDefinitionTuple[] {\n const result: DirectiveDefinitionTuple[] = [];\n\n for (const minuendDirective of minuendDirectives) {\n const minuendName = getDirectiveDefinitionName(minuendDirective);\n const subtrahendDirective = subtrahendDirectives.find(\n (d) => getDirectiveDefinitionName(d) === minuendName,\n );\n\n if (!subtrahendDirective) {\n // Directive doesn't exist in subtrahend, keep it\n result.push(minuendDirective);\n continue;\n }\n\n // Directive exists, check arguments\n const minuendArgs = getDirectiveDefinitionArgs(minuendDirective);\n const subtrahendArgs = getDirectiveDefinitionArgs(subtrahendDirective);\n\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, remove entire directive\n continue;\n }\n\n if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - arguments don't match exactly\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument structures.`,\n );\n }\n\n // Both have arguments, check if they match exactly\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} argument ${argName} has different types.`,\n );\n }\n }\n\n // Arguments match exactly, remove entire directive\n }\n\n // Check for directives in subtrahend that don't exist in minuend\n for (const subtrahendDirective of subtrahendDirectives) {\n const subtrahendName = getDirectiveDefinitionName(subtrahendDirective);\n const exists = minuendDirectives.some(\n (d) => getDirectiveDefinitionName(d) === subtrahendName,\n );\n if (!exists) {\n if (strict) {\n throw new Error(\n `Directive ${subtrahendName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing directives\n }\n }\n\n return result;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,w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DirectiveDefinitionName,
|
|
5
5
|
getEnumValues,
|
|
6
6
|
getFieldTypeReference,
|
|
7
7
|
getFieldArgs,
|
|
@@ -281,9 +281,9 @@ function subtractEnumValues(typeName, minuendValues, subtrahendValues, strict) {
|
|
|
281
281
|
function subtractDirectives(minuendDirectives, subtrahendDirectives, strict) {
|
|
282
282
|
const result = [];
|
|
283
283
|
for (const minuendDirective of minuendDirectives) {
|
|
284
|
-
const minuendName =
|
|
284
|
+
const minuendName = getDirectiveDefinitionName(minuendDirective);
|
|
285
285
|
const subtrahendDirective = subtrahendDirectives.find(
|
|
286
|
-
(d) =>
|
|
286
|
+
(d) => getDirectiveDefinitionName(d) === minuendName
|
|
287
287
|
);
|
|
288
288
|
if (!subtrahendDirective) {
|
|
289
289
|
result.push(minuendDirective);
|
|
@@ -319,9 +319,9 @@ function subtractDirectives(minuendDirectives, subtrahendDirectives, strict) {
|
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
for (const subtrahendDirective of subtrahendDirectives) {
|
|
322
|
-
const subtrahendName =
|
|
322
|
+
const subtrahendName = getDirectiveDefinitionName(subtrahendDirective);
|
|
323
323
|
const exists = minuendDirectives.some(
|
|
324
|
-
(d) =>
|
|
324
|
+
(d) => getDirectiveDefinitionName(d) === subtrahendName
|
|
325
325
|
);
|
|
326
326
|
if (!exists) {
|
|
327
327
|
if (strict) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utilities/subtractSchemaDefinitions.ts"],
|
|
4
|
-
"sourcesContent": ["// Note: this utility is vibe-coded. Use at your own risk! :)\nimport {\n SchemaDefinitions,\n DirectiveDefinitionTuple,\n FieldDefinitionRecord,\n InputValueDefinitionRecord,\n TypeDefinitionsRecord,\n TypeDefinitionTuple,\n getDirectiveDefinitionArgs,\n getDirectiveName,\n getEnumValues,\n getFieldTypeReference,\n getFieldArgs,\n getFields,\n getInputObjectFields,\n getInputValueTypeReference,\n getUnionTypeMembers,\n isEnumTypeDefinition,\n isInputObjectTypeDefinition,\n isInterfaceTypeDefinition,\n isObjectTypeDefinition,\n isScalarTypeDefinition,\n isUnionTypeDefinition,\n createEnumTypeDefinition,\n createInputObjectTypeDefinition,\n createInterfaceTypeDefinition,\n createObjectTypeDefinition,\n createUnionTypeDefinition,\n getObjectTypeInterfaces,\n getInterfaceTypeInterfaces,\n} from \"../schema/definition\";\nimport { inspect } from \"../jsutils/inspect\";\n\n/**\n * Subtracts schema definitions from minuend that exist in subtrahend.\n * Returns a new SchemaDefinitions object without mutating inputs.\n *\n * @param minuend - The schema definitions to subtract from\n * @param subtrahend - The schema definitions to subtract\n * @param strict - If true, throws errors on items in subtrahend that are not in minuend; if false, ignores them\n * @returns A new SchemaDefinitions with elements from minuend not in subtrahend\n */\nexport function subtractSchemaDefinitions(\n minuend: SchemaDefinitions,\n subtrahend: SchemaDefinitions,\n strict = false,\n): SchemaDefinitions {\n const result: SchemaDefinitions = {\n types: {},\n directives: [],\n };\n\n // Subtract types\n if (minuend.types && subtrahend.types) {\n result.types = subtractTypes(minuend.types, subtrahend.types, strict);\n } else if (minuend.types) {\n result.types = { ...minuend.types };\n }\n\n // Subtract directives\n if (minuend.directives && subtrahend.directives) {\n result.directives = subtractDirectives(\n minuend.directives,\n subtrahend.directives,\n strict,\n );\n } else if (minuend.directives) {\n result.directives = [...minuend.directives];\n }\n\n return result;\n}\n\n/**\n * Subtracts types from minuend that exist in subtrahend.\n */\nfunction subtractTypes(\n minuend: TypeDefinitionsRecord,\n subtrahend: TypeDefinitionsRecord,\n strict: boolean,\n): TypeDefinitionsRecord {\n const result: TypeDefinitionsRecord = {};\n\n for (const [typeName, minuendDef] of Object.entries(minuend)) {\n const subtrahendDef = subtrahend[typeName];\n\n if (!subtrahendDef) {\n // Type doesn't exist in subtrahend, keep it\n result[typeName] = minuendDef;\n continue;\n }\n\n // Validate type kinds match\n if (minuendDef[0] !== subtrahendDef[0]) {\n throw new Error(\n `Type ${typeName} is represented differently in different schema fragments:\\n` +\n inspect(minuendDef) +\n `\\n` +\n inspect(subtrahendDef),\n );\n }\n\n // Handle different type kinds\n const subtractedType = subtractType(\n typeName,\n minuendDef,\n subtrahendDef,\n strict,\n );\n if (subtractedType) {\n result[typeName] = subtractedType;\n }\n }\n\n // Check for types in subtrahend that don't exist in minuend\n for (const typeName of Object.keys(subtrahend)) {\n if (!(typeName in minuend)) {\n if (strict) {\n throw new Error(`Type ${typeName} does not exist in minuend`);\n }\n // In non-strict mode, ignore missing types\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts a single type definition.\n */\nfunction subtractType(\n typeName: string,\n minuendDef: TypeDefinitionTuple,\n subtrahendDef: TypeDefinitionTuple,\n strict: boolean,\n): TypeDefinitionTuple | null {\n if (\n isObjectTypeDefinition(minuendDef) &&\n isObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getObjectTypeInterfaces(minuendDef);\n return createObjectTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInterfaceTypeDefinition(minuendDef) &&\n isInterfaceTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getInterfaceTypeInterfaces(minuendDef);\n return createInterfaceTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInputObjectTypeDefinition(minuendDef) &&\n isInputObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractInputFields(\n typeName,\n getInputObjectFields(minuendDef),\n getInputObjectFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n return createInputObjectTypeDefinition(subtractedFields);\n }\n\n if (\n isUnionTypeDefinition(minuendDef) &&\n isUnionTypeDefinition(subtrahendDef)\n ) {\n const subtractedMembers = subtractUnionMembers(\n typeName,\n getUnionTypeMembers(minuendDef),\n getUnionTypeMembers(subtrahendDef),\n strict,\n );\n if (subtractedMembers.length === 0) {\n return null; // All members removed\n }\n return createUnionTypeDefinition(subtractedMembers);\n }\n\n if (isEnumTypeDefinition(minuendDef) && isEnumTypeDefinition(subtrahendDef)) {\n const subtractedValues = subtractEnumValues(\n typeName,\n getEnumValues(minuendDef),\n getEnumValues(subtrahendDef),\n strict,\n );\n if (subtractedValues.length === 0) {\n return null; // All values removed\n }\n return createEnumTypeDefinition(subtractedValues);\n }\n\n if (\n isScalarTypeDefinition(minuendDef) &&\n isScalarTypeDefinition(subtrahendDef)\n ) {\n // Scalars are atomic - if subtrahend has it, remove entire scalar\n return null;\n }\n\n return null;\n}\n\n/**\n * Subtracts fields from object/interface types.\n */\nfunction subtractFields(\n typeName: string,\n minuendFields: FieldDefinitionRecord,\n subtrahendFields: FieldDefinitionRecord,\n strict: boolean,\n): FieldDefinitionRecord {\n const result: FieldDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getFieldTypeReference(minuendField);\n const subtrahendType = getFieldTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Validate field arguments match exactly\n const minuendArgs = getFieldArgs(minuendField);\n const subtrahendArgs = getFieldArgs(subtrahendField);\n\n // Both must have same argument structure\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, field can be subtracted\n } else if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - not exact match\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument structures.`,\n );\n } else {\n // Both have arguments, compare them\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} argument ${argName} has different types.`,\n );\n }\n }\n }\n\n // Field exists in subtrahend and matches exactly, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts input fields from input object types.\n */\nfunction subtractInputFields(\n typeName: string,\n minuendFields: InputValueDefinitionRecord,\n subtrahendFields: InputValueDefinitionRecord,\n strict: boolean,\n): InputValueDefinitionRecord {\n const result: InputValueDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getInputValueTypeReference(minuendField);\n const subtrahendType = getInputValueTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Input field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Field exists in subtrahend, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Input field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts union members.\n */\nfunction subtractUnionMembers(\n typeName: string,\n minuendMembers: string[],\n subtrahendMembers: string[],\n strict: boolean,\n): string[] {\n // Union types must match exactly for subtraction\n const minuendSet = new Set(minuendMembers);\n const subtrahendSet = new Set(subtrahendMembers);\n\n // Check if they have the same members\n if (\n minuendMembers.length === subtrahendMembers.length &&\n minuendMembers.every((member) => subtrahendSet.has(member))\n ) {\n // Exact match - remove the entire union\n return [];\n }\n\n // Check for members in subtrahend that don't exist in minuend\n for (const member of subtrahendMembers) {\n if (!minuendSet.has(member)) {\n if (strict) {\n throw new Error(\n `Union ${typeName}: member ${member} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing members and keep the original union\n return minuendMembers;\n }\n }\n\n // If we get here, all subtrahend members exist in minuend but they don't match exactly\n throw new Error(\n `Union types must match exactly for subtraction. Union ${typeName} has different member sets.`,\n );\n}\n\n/**\n * Subtracts enum values.\n */\nfunction subtractEnumValues(\n typeName: string,\n minuendValues: string[],\n subtrahendValues: string[],\n strict: boolean,\n): string[] {\n // Enum types must match exactly for subtraction\n const minuendSet = new Set(minuendValues);\n const subtrahendSet = new Set(subtrahendValues);\n\n // Check if they have the same values\n if (\n minuendValues.length === subtrahendValues.length &&\n minuendValues.every((value) => subtrahendSet.has(value))\n ) {\n // Exact match - remove the entire enum\n return [];\n }\n\n // Check for values in subtrahend that don't exist in minuend\n for (const value of subtrahendValues) {\n if (!minuendSet.has(value)) {\n if (strict) {\n throw new Error(\n `Enum ${typeName}: value ${value} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing values and keep the original enum\n return minuendValues;\n }\n }\n\n // If we get here, all subtrahend values exist in minuend but they don't match exactly\n throw new Error(\n `Enum types must match exactly for subtraction. Enum ${typeName} has different value sets.`,\n );\n}\n\n/**\n * Subtracts directives.\n */\nfunction subtractDirectives(\n minuendDirectives: DirectiveDefinitionTuple[],\n subtrahendDirectives: DirectiveDefinitionTuple[],\n strict: boolean,\n): DirectiveDefinitionTuple[] {\n const result: DirectiveDefinitionTuple[] = [];\n\n for (const minuendDirective of minuendDirectives) {\n const minuendName = getDirectiveName(minuendDirective);\n const subtrahendDirective = subtrahendDirectives.find(\n (d) => getDirectiveName(d) === minuendName,\n );\n\n if (!subtrahendDirective) {\n // Directive doesn't exist in subtrahend, keep it\n result.push(minuendDirective);\n continue;\n }\n\n // Directive exists, check arguments\n const minuendArgs = getDirectiveDefinitionArgs(minuendDirective);\n const subtrahendArgs = getDirectiveDefinitionArgs(subtrahendDirective);\n\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, remove entire directive\n continue;\n }\n\n if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - arguments don't match exactly\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument structures.`,\n );\n }\n\n // Both have arguments, check if they match exactly\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} argument ${argName} has different types.`,\n );\n }\n }\n\n // Arguments match exactly, remove entire directive\n }\n\n // Check for directives in subtrahend that don't exist in minuend\n for (const subtrahendDirective of subtrahendDirectives) {\n const subtrahendName = getDirectiveName(subtrahendDirective);\n const exists = minuendDirectives.some(\n (d) => getDirectiveName(d) === subtrahendName,\n );\n if (!exists) {\n if (strict) {\n throw new Error(\n `Directive ${subtrahendName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing directives\n }\n }\n\n return result;\n}\n"],
|
|
5
|
-
"mappings": ";AACA;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AAWjB,SAAS,0BACd,SACA,YACA,SAAS,OACU;AACnB,QAAM,SAA4B;AAAA,IAChC,OAAO,CAAC;AAAA,IACR,YAAY,CAAC;AAAA,EACf;AAGA,MAAI,QAAQ,SAAS,WAAW,OAAO;AACrC,WAAO,QAAQ,cAAc,QAAQ,OAAO,WAAW,OAAO,MAAM;AAAA,EACtE,WAAW,QAAQ,OAAO;AACxB,WAAO,QAAQ,EAAE,GAAG,QAAQ,MAAM;AAAA,EACpC;AAGA,MAAI,QAAQ,cAAc,WAAW,YAAY;AAC/C,WAAO,aAAa;AAAA,MAClB,QAAQ;AAAA,MACR,WAAW;AAAA,MACX;AAAA,IACF;AAAA,EACF,WAAW,QAAQ,YAAY;AAC7B,WAAO,aAAa,CAAC,GAAG,QAAQ,UAAU;AAAA,EAC5C;AAEA,SAAO;AACT;AAKA,SAAS,cACP,SACA,YACA,QACuB;AACvB,QAAM,SAAgC,CAAC;AAEvC,aAAW,CAAC,UAAU,UAAU,KAAK,OAAO,QAAQ,OAAO,GAAG;AAC5D,UAAM,gBAAgB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,CAAC;AAAA,EACV;AAGA,aAAW,SAAS,kBAAkB;AACpC,QAAI,CAAC,WAAW,IAAI,KAAK,GAAG;AAC1B,UAAI,QAAQ;AACV,cAAM,IAAI;AAAA,UACR,QAAQ,mBAAmB;AAAA,QAC7B;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,QAAM,IAAI;AAAA,IACR,uDAAuD;AAAA,EACzD;AACF;AAKA,SAAS,mBACP,mBACA,sBACA,QAC4B;AAC5B,QAAM,SAAqC,CAAC;AAE5C,aAAW,oBAAoB,mBAAmB;AAChD,UAAM,cAAc,
|
|
4
|
+
"sourcesContent": ["// Note: this utility is vibe-coded. Use at your own risk! :)\nimport {\n SchemaDefinitions,\n DirectiveDefinitionTuple,\n FieldDefinitionRecord,\n InputValueDefinitionRecord,\n TypeDefinitionsRecord,\n TypeDefinitionTuple,\n getDirectiveDefinitionArgs,\n getDirectiveDefinitionName,\n getEnumValues,\n getFieldTypeReference,\n getFieldArgs,\n getFields,\n getInputObjectFields,\n getInputValueTypeReference,\n getUnionTypeMembers,\n isEnumTypeDefinition,\n isInputObjectTypeDefinition,\n isInterfaceTypeDefinition,\n isObjectTypeDefinition,\n isScalarTypeDefinition,\n isUnionTypeDefinition,\n createEnumTypeDefinition,\n createInputObjectTypeDefinition,\n createInterfaceTypeDefinition,\n createObjectTypeDefinition,\n createUnionTypeDefinition,\n getObjectTypeInterfaces,\n getInterfaceTypeInterfaces,\n} from \"../schema/definition\";\nimport { inspect } from \"../jsutils/inspect\";\n\n/**\n * Subtracts schema definitions from minuend that exist in subtrahend.\n * Returns a new SchemaDefinitions object without mutating inputs.\n *\n * @param minuend - The schema definitions to subtract from\n * @param subtrahend - The schema definitions to subtract\n * @param strict - If true, throws errors on items in subtrahend that are not in minuend; if false, ignores them\n * @returns A new SchemaDefinitions with elements from minuend not in subtrahend\n */\nexport function subtractSchemaDefinitions(\n minuend: SchemaDefinitions,\n subtrahend: SchemaDefinitions,\n strict = false,\n): SchemaDefinitions {\n const result: SchemaDefinitions = {\n types: {},\n directives: [],\n };\n\n // Subtract types\n if (minuend.types && subtrahend.types) {\n result.types = subtractTypes(minuend.types, subtrahend.types, strict);\n } else if (minuend.types) {\n result.types = { ...minuend.types };\n }\n\n // Subtract directives\n if (minuend.directives && subtrahend.directives) {\n result.directives = subtractDirectives(\n minuend.directives,\n subtrahend.directives,\n strict,\n );\n } else if (minuend.directives) {\n result.directives = [...minuend.directives];\n }\n\n return result;\n}\n\n/**\n * Subtracts types from minuend that exist in subtrahend.\n */\nfunction subtractTypes(\n minuend: TypeDefinitionsRecord,\n subtrahend: TypeDefinitionsRecord,\n strict: boolean,\n): TypeDefinitionsRecord {\n const result: TypeDefinitionsRecord = {};\n\n for (const [typeName, minuendDef] of Object.entries(minuend)) {\n const subtrahendDef = subtrahend[typeName];\n\n if (!subtrahendDef) {\n // Type doesn't exist in subtrahend, keep it\n result[typeName] = minuendDef;\n continue;\n }\n\n // Validate type kinds match\n if (minuendDef[0] !== subtrahendDef[0]) {\n throw new Error(\n `Type ${typeName} is represented differently in different schema fragments:\\n` +\n inspect(minuendDef) +\n `\\n` +\n inspect(subtrahendDef),\n );\n }\n\n // Handle different type kinds\n const subtractedType = subtractType(\n typeName,\n minuendDef,\n subtrahendDef,\n strict,\n );\n if (subtractedType) {\n result[typeName] = subtractedType;\n }\n }\n\n // Check for types in subtrahend that don't exist in minuend\n for (const typeName of Object.keys(subtrahend)) {\n if (!(typeName in minuend)) {\n if (strict) {\n throw new Error(`Type ${typeName} does not exist in minuend`);\n }\n // In non-strict mode, ignore missing types\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts a single type definition.\n */\nfunction subtractType(\n typeName: string,\n minuendDef: TypeDefinitionTuple,\n subtrahendDef: TypeDefinitionTuple,\n strict: boolean,\n): TypeDefinitionTuple | null {\n if (\n isObjectTypeDefinition(minuendDef) &&\n isObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getObjectTypeInterfaces(minuendDef);\n return createObjectTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInterfaceTypeDefinition(minuendDef) &&\n isInterfaceTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractFields(\n typeName,\n getFields(minuendDef),\n getFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n const interfaces = getInterfaceTypeInterfaces(minuendDef);\n return createInterfaceTypeDefinition(\n subtractedFields,\n interfaces.length > 0 ? interfaces : undefined,\n );\n }\n\n if (\n isInputObjectTypeDefinition(minuendDef) &&\n isInputObjectTypeDefinition(subtrahendDef)\n ) {\n const subtractedFields = subtractInputFields(\n typeName,\n getInputObjectFields(minuendDef),\n getInputObjectFields(subtrahendDef),\n strict,\n );\n if (Object.keys(subtractedFields).length === 0) {\n return null; // All fields removed\n }\n return createInputObjectTypeDefinition(subtractedFields);\n }\n\n if (\n isUnionTypeDefinition(minuendDef) &&\n isUnionTypeDefinition(subtrahendDef)\n ) {\n const subtractedMembers = subtractUnionMembers(\n typeName,\n getUnionTypeMembers(minuendDef),\n getUnionTypeMembers(subtrahendDef),\n strict,\n );\n if (subtractedMembers.length === 0) {\n return null; // All members removed\n }\n return createUnionTypeDefinition(subtractedMembers);\n }\n\n if (isEnumTypeDefinition(minuendDef) && isEnumTypeDefinition(subtrahendDef)) {\n const subtractedValues = subtractEnumValues(\n typeName,\n getEnumValues(minuendDef),\n getEnumValues(subtrahendDef),\n strict,\n );\n if (subtractedValues.length === 0) {\n return null; // All values removed\n }\n return createEnumTypeDefinition(subtractedValues);\n }\n\n if (\n isScalarTypeDefinition(minuendDef) &&\n isScalarTypeDefinition(subtrahendDef)\n ) {\n // Scalars are atomic - if subtrahend has it, remove entire scalar\n return null;\n }\n\n return null;\n}\n\n/**\n * Subtracts fields from object/interface types.\n */\nfunction subtractFields(\n typeName: string,\n minuendFields: FieldDefinitionRecord,\n subtrahendFields: FieldDefinitionRecord,\n strict: boolean,\n): FieldDefinitionRecord {\n const result: FieldDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getFieldTypeReference(minuendField);\n const subtrahendType = getFieldTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Validate field arguments match exactly\n const minuendArgs = getFieldArgs(minuendField);\n const subtrahendArgs = getFieldArgs(subtrahendField);\n\n // Both must have same argument structure\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, field can be subtracted\n } else if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - not exact match\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument structures.`,\n );\n } else {\n // Both have arguments, compare them\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Field arguments must match exactly for subtraction. Field ${typeName}.${fieldName} argument ${argName} has different types.`,\n );\n }\n }\n }\n\n // Field exists in subtrahend and matches exactly, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts input fields from input object types.\n */\nfunction subtractInputFields(\n typeName: string,\n minuendFields: InputValueDefinitionRecord,\n subtrahendFields: InputValueDefinitionRecord,\n strict: boolean,\n): InputValueDefinitionRecord {\n const result: InputValueDefinitionRecord = {};\n\n for (const [fieldName, minuendField] of Object.entries(minuendFields)) {\n const subtrahendField = subtrahendFields[fieldName];\n\n if (!subtrahendField) {\n // Field doesn't exist in subtrahend, keep it\n result[fieldName] = minuendField;\n continue;\n }\n\n // Validate field types match\n const minuendType = getInputValueTypeReference(minuendField);\n const subtrahendType = getInputValueTypeReference(subtrahendField);\n if (minuendType !== subtrahendType) {\n throw new Error(\n `Input field ${typeName}.${fieldName} has different type: ${inspect(\n minuendType,\n )} vs ${inspect(subtrahendType)}`,\n );\n }\n\n // Field exists in subtrahend, remove it\n }\n\n // Check for fields in subtrahend that don't exist in minuend\n for (const fieldName of Object.keys(subtrahendFields)) {\n if (!(fieldName in minuendFields)) {\n if (strict) {\n throw new Error(\n `Input field ${typeName}.${fieldName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing fields\n }\n }\n\n return result;\n}\n\n/**\n * Subtracts union members.\n */\nfunction subtractUnionMembers(\n typeName: string,\n minuendMembers: string[],\n subtrahendMembers: string[],\n strict: boolean,\n): string[] {\n // Union types must match exactly for subtraction\n const minuendSet = new Set(minuendMembers);\n const subtrahendSet = new Set(subtrahendMembers);\n\n // Check if they have the same members\n if (\n minuendMembers.length === subtrahendMembers.length &&\n minuendMembers.every((member) => subtrahendSet.has(member))\n ) {\n // Exact match - remove the entire union\n return [];\n }\n\n // Check for members in subtrahend that don't exist in minuend\n for (const member of subtrahendMembers) {\n if (!minuendSet.has(member)) {\n if (strict) {\n throw new Error(\n `Union ${typeName}: member ${member} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing members and keep the original union\n return minuendMembers;\n }\n }\n\n // If we get here, all subtrahend members exist in minuend but they don't match exactly\n throw new Error(\n `Union types must match exactly for subtraction. Union ${typeName} has different member sets.`,\n );\n}\n\n/**\n * Subtracts enum values.\n */\nfunction subtractEnumValues(\n typeName: string,\n minuendValues: string[],\n subtrahendValues: string[],\n strict: boolean,\n): string[] {\n // Enum types must match exactly for subtraction\n const minuendSet = new Set(minuendValues);\n const subtrahendSet = new Set(subtrahendValues);\n\n // Check if they have the same values\n if (\n minuendValues.length === subtrahendValues.length &&\n minuendValues.every((value) => subtrahendSet.has(value))\n ) {\n // Exact match - remove the entire enum\n return [];\n }\n\n // Check for values in subtrahend that don't exist in minuend\n for (const value of subtrahendValues) {\n if (!minuendSet.has(value)) {\n if (strict) {\n throw new Error(\n `Enum ${typeName}: value ${value} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing values and keep the original enum\n return minuendValues;\n }\n }\n\n // If we get here, all subtrahend values exist in minuend but they don't match exactly\n throw new Error(\n `Enum types must match exactly for subtraction. Enum ${typeName} has different value sets.`,\n );\n}\n\n/**\n * Subtracts directives.\n */\nfunction subtractDirectives(\n minuendDirectives: DirectiveDefinitionTuple[],\n subtrahendDirectives: DirectiveDefinitionTuple[],\n strict: boolean,\n): DirectiveDefinitionTuple[] {\n const result: DirectiveDefinitionTuple[] = [];\n\n for (const minuendDirective of minuendDirectives) {\n const minuendName = getDirectiveDefinitionName(minuendDirective);\n const subtrahendDirective = subtrahendDirectives.find(\n (d) => getDirectiveDefinitionName(d) === minuendName,\n );\n\n if (!subtrahendDirective) {\n // Directive doesn't exist in subtrahend, keep it\n result.push(minuendDirective);\n continue;\n }\n\n // Directive exists, check arguments\n const minuendArgs = getDirectiveDefinitionArgs(minuendDirective);\n const subtrahendArgs = getDirectiveDefinitionArgs(subtrahendDirective);\n\n if (!minuendArgs && !subtrahendArgs) {\n // Both have no arguments, remove entire directive\n continue;\n }\n\n if (!minuendArgs || !subtrahendArgs) {\n // One has args, other doesn't - arguments don't match exactly\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument structures.`,\n );\n }\n\n // Both have arguments, check if they match exactly\n const minuendArgKeys = Object.keys(minuendArgs).sort();\n const subtrahendArgKeys = Object.keys(subtrahendArgs).sort();\n\n if (\n minuendArgKeys.length !== subtrahendArgKeys.length ||\n !minuendArgKeys.every((key, index) => key === subtrahendArgKeys[index])\n ) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} has different argument keys.`,\n );\n }\n\n // Check each argument type matches\n for (const argName of minuendArgKeys) {\n const minuendArgType = getInputValueTypeReference(minuendArgs[argName]);\n const subtrahendArgType = getInputValueTypeReference(\n subtrahendArgs[argName],\n );\n if (minuendArgType !== subtrahendArgType) {\n throw new Error(\n `Directive arguments must match exactly for subtraction. Directive ${minuendName} argument ${argName} has different types.`,\n );\n }\n }\n\n // Arguments match exactly, remove entire directive\n }\n\n // Check for directives in subtrahend that don't exist in minuend\n for (const subtrahendDirective of subtrahendDirectives) {\n const subtrahendName = getDirectiveDefinitionName(subtrahendDirective);\n const exists = minuendDirectives.some(\n (d) => getDirectiveDefinitionName(d) === subtrahendName,\n );\n if (!exists) {\n if (strict) {\n throw new Error(\n `Directive ${subtrahendName} does not exist in minuend`,\n );\n }\n // In non-strict mode, ignore missing directives\n }\n }\n\n return result;\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA,EAOE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;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UAAM,cAAc,2BAA2B,gBAAgB;AAC/D,UAAM,iBAAiB,2BAA2B,mBAAmB;AAErE,QAAI,CAAC,eAAe,CAAC,gBAAgB;AAEnC;AAAA,IACF;AAEA,QAAI,CAAC,eAAe,CAAC,gBAAgB;AAEnC,YAAM,IAAI;AAAA,QACR,qEAAqE;AAAA,MACvE;AAAA,IACF;AAGA,UAAM,iBAAiB,OAAO,KAAK,WAAW,EAAE,KAAK;AACrD,UAAM,oBAAoB,OAAO,KAAK,cAAc,EAAE,KAAK;AAE3D,QACE,eAAe,WAAW,kBAAkB,UAC5C,CAAC,eAAe,MAAM,CAAC,KAAK,UAAU,QAAQ,kBAAkB,KAAK,CAAC,GACtE;AACA,YAAM,IAAI;AAAA,QACR,qEAAqE;AAAA,MACvE;AAAA,IACF;AAGA,eAAW,WAAW,gBAAgB;AACpC,YAAM,iBAAiB,2BAA2B,YAAY,OAAO,CAAC;AACtE,YAAM,oBAAoB;AAAA,QACxB,eAAe,OAAO;AAAA,MACxB;AACA,UAAI,mBAAmB,mBAAmB;AACxC,cAAM,IAAI;AAAA,UACR,qEAAqE,wBAAwB;AAAA,QAC/F;AAAA,MACF;AAAA,IACF;AAAA,EAGF;AAGA,aAAW,uBAAuB,sBAAsB;AACtD,UAAM,iBAAiB,2BAA2B,mBAAmB;AACrE,UAAM,SAAS,kBAAkB;AAAA,MAC/B,CAAC,MAAM,2BAA2B,CAAC,MAAM;AAAA,IAC3C;AACA,QAAI,CAAC,QAAQ;AACX,UAAI,QAAQ;AACV,cAAM,IAAI;AAAA,UACR,aAAa;AAAA,QACf;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/values.js
CHANGED
|
@@ -119,7 +119,7 @@ function getArgumentValues(exeContext, def, node) {
|
|
|
119
119
|
var _a;
|
|
120
120
|
const definitions = exeContext.schemaFragment.definitions;
|
|
121
121
|
const coercedValues = {};
|
|
122
|
-
const argumentDefs = node.kind === import_graphql.Kind.FIELD ? (0, import_definition.getFieldArguments)(def) : (0, import_definition.
|
|
122
|
+
const argumentDefs = node.kind === import_graphql.Kind.FIELD ? (0, import_definition.getFieldArguments)(def) : (0, import_definition.getDirectiveDefinitionArgs)(def);
|
|
123
123
|
if (!argumentDefs) {
|
|
124
124
|
return coercedValues;
|
|
125
125
|
}
|
|
@@ -190,7 +190,7 @@ function getArgumentValues(exeContext, def, node) {
|
|
|
190
190
|
}
|
|
191
191
|
function getDirectiveValues(exeContext, directiveDef, node) {
|
|
192
192
|
var _a;
|
|
193
|
-
const name = (0, import_definition.
|
|
193
|
+
const name = (0, import_definition.getDirectiveDefinitionName)(directiveDef);
|
|
194
194
|
const directiveNode = (_a = node.directives) == null ? void 0 : _a.find(
|
|
195
195
|
(directive) => directive.name.value === name
|
|
196
196
|
);
|
package/lib/values.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/values.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n GraphQLError,\n Kind,\n print,\n locatedError,\n DirectiveNode,\n FieldNode,\n VariableDefinitionNode,\n} from \"graphql\";\nimport { inspect } from \"./jsutils/inspect\";\nimport { printPathArray } from \"./jsutils/printPathArray\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport {\n DirectiveDefinitionTuple,\n FieldDefinition,\n getFieldArguments,\n getDirectiveName,\n getInputDefaultValue,\n getInputValueTypeReference,\n isDefined,\n isInputType,\n getDirectiveArguments,\n} from \"./schema/definition\";\nimport { valueFromAST } from \"./utilities/valueFromAST\";\nimport { coerceInputValue } from \"./utilities/coerceInputValue\";\nimport {\n inspectTypeReference,\n isNonNullType,\n typeReferenceFromNode,\n} from \"./schema/reference\";\nimport type { SchemaFragment } from \"./types\";\n\ntype CoercedVariableValues =\n | { errors: Array<GraphQLError>; coerced?: never }\n | { coerced: { [variable: string]: unknown }; errors?: never };\n\n/**\n * Prepares an object map of variableValues of the correct type based on the\n * provided variable definitions and arbitrary input. If the input cannot be\n * parsed to match the variable definitions, a GraphQLError will be thrown.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n options?: { maxErrors?: number },\n): CoercedVariableValues {\n const errors: GraphQLError[] = [];\n const maxErrors = options?.maxErrors;\n try {\n const coerced = coerceVariableValues(\n schemaFragment,\n varDefNodes,\n inputs,\n (error) => {\n if (maxErrors != null && errors.length >= maxErrors) {\n throw locatedError(\n \"Too many errors processing variables, error limit reached. Execution aborted.\",\n [],\n );\n }\n errors.push(error);\n },\n );\n\n if (errors.length === 0) {\n return { coerced };\n }\n } catch (error) {\n errors.push(error as GraphQLError);\n }\n\n return { errors: errors };\n}\n\nfunction coerceVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n onError: (error: GraphQLError) => void,\n): { [variable: string]: unknown } {\n const coercedValues: { [variable: string]: unknown } = {};\n for (const varDefNode of varDefNodes) {\n const varName = varDefNode.variable.name.value;\n const varTypeReference = typeReferenceFromNode(varDefNode.type);\n\n if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n // Must use input types for variables. This should be caught during\n // validation, however is checked again here for safety.\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" expected value of type \"${varTypeStr}\" which cannot be used as an input type.`,\n [varDefNode.type],\n ),\n );\n continue;\n }\n\n if (!hasOwnProperty(inputs, varName)) {\n if (varDefNode.defaultValue) {\n coercedValues[varName] = valueFromAST(\n varDefNode.defaultValue,\n varTypeReference,\n schemaFragment,\n );\n } else if (isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of required type \"${varTypeStr}\" was not provided.`,\n [varDefNode],\n ),\n );\n }\n continue;\n }\n\n const value = inputs[varName];\n if (value === null && isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of non-null type \"${varTypeStr}\" must not be null.`,\n [varDefNode],\n ),\n );\n continue;\n }\n\n coercedValues[varName] = coerceInputValue(\n value,\n varTypeReference,\n schemaFragment,\n (path, invalidValue, error) => {\n let prefix =\n `Variable \"$${varName}\" got invalid value ` + inspect(invalidValue);\n if (path.length > 0) {\n prefix += ` at \"${varName}${printPathArray(path)}\"`;\n }\n onError(locatedError(prefix + \"; \" + error.message, [varDefNode]));\n },\n );\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a list of argument\n * definitions and list of argument AST nodes.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getArgumentValues(\n exeContext: ExecutionContext,\n def: FieldDefinition | DirectiveDefinitionTuple,\n node: FieldNode | DirectiveNode,\n): { [argument: string]: unknown } {\n const definitions = exeContext.schemaFragment.definitions;\n const coercedValues: { [argument: string]: unknown } = {};\n const argumentDefs =\n node.kind === Kind.FIELD\n ? getFieldArguments(def as FieldDefinition)\n : getDirectiveArguments(def as DirectiveDefinitionTuple);\n if (!argumentDefs) {\n return coercedValues;\n }\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const argumentNodes = node.arguments ?? [];\n const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));\n\n for (const [name, argumentDef] of Object.entries(argumentDefs)) {\n const argumentNode = argNodeMap.get(name);\n const argumentTypeRef = getInputValueTypeReference(argumentDef);\n const defaultValue = getInputDefaultValue(argumentDef);\n\n if (argumentNode == null) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" was not provided.`,\n [node],\n );\n }\n continue;\n }\n\n if (!isDefined(definitions, argumentTypeRef)) {\n throw locatedError(\n `Could not find type for argument ${name} in ${node.kind} ${node.name.value}`,\n [argumentNode],\n );\n }\n\n // if (!schemaTypes.isInputType(argumentTypeRef)) {\n // const type = schemaTypes.printTypeRef(argumentTypeRef);\n // throw locatedError(\n // `Argument \"$${name}\" expected value of type \"${type}\" which cannot be used as an input type.`,\n // [argumentNode],\n // );\n // }\n\n const valueNode = argumentNode.value;\n let isNull = valueNode.kind === Kind.NULL;\n\n if (valueNode.kind === Kind.VARIABLE) {\n const variableName = valueNode.name.value;\n if (\n exeContext.variableValues == null ||\n !hasOwnProperty(exeContext.variableValues, variableName)\n ) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" ` +\n `was provided the variable \"$${variableName}\" which was not provided a runtime value.`,\n [valueNode],\n );\n }\n continue;\n }\n isNull = exeContext.variableValues[variableName] == null;\n }\n\n if (isNull && isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of non-null type \"${type}\" must not be null.\"`,\n [valueNode],\n );\n }\n\n const coercedValue = valueFromAST(\n valueNode,\n argumentTypeRef,\n exeContext.schemaFragment,\n exeContext.variableValues,\n );\n if (coercedValue === undefined) {\n // Note: ValuesOfCorrectTypeRule validation should catch this before\n // execution. This is a runtime check to ensure execution does not\n // continue with an invalid argument value.\n throw locatedError(\n `Argument \"${name}\" has invalid value ${print(valueNode)}.`,\n [valueNode],\n );\n }\n coercedValues[name] = coercedValue;\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a directive definition\n * and a AST node which may contain directives. Optionally also accepts a map\n * of variable values.\n *\n * If the directive does not exist on the node, returns undefined.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n */\nexport function getDirectiveValues(\n exeContext: ExecutionContext,\n directiveDef: DirectiveDefinitionTuple,\n node: { directives?: ReadonlyArray<DirectiveNode> },\n): undefined | { [argument: string]: unknown } {\n const name = getDirectiveName(directiveDef);\n\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const directiveNode = node.directives?.find(\n (directive) => directive.name.value === name,\n );\n\n if (directiveNode) {\n return getArgumentValues(exeContext, directiveDef, directiveNode);\n }\n}\n\nfunction hasOwnProperty(obj: unknown, prop: string): boolean {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AACP,qBAAwB;AACxB,4BAA+B;AAE/B,wBAUO;AACP,0BAA6B;AAC7B,8BAAiC;AACjC,uBAIO;AAkBA,SAAS,kBACd,gBACA,aACA,QACA,SACuB;AACvB,QAAM,SAAyB,CAAC;AAChC,QAAM,YAAY,mCAAS;AAC3B,MAAI;AACF,UAAM,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA,CAAC,UAAU;AACT,YAAI,aAAa,QAAQ,OAAO,UAAU,WAAW;AACnD,oBAAM;AAAA,YACJ;AAAA,YACA,CAAC;AAAA,UACH;AAAA,QACF;AACA,eAAO,KAAK,KAAK;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,GAAG;AACvB,aAAO,EAAE,QAAQ;AAAA,IACnB;AAAA,EACF,SAAS,OAAP;AACA,WAAO,KAAK,KAAqB;AAAA,EACnC;AAEA,SAAO,EAAE,OAAe;AAC1B;AAEA,SAAS,qBACP,gBACA,aACA,QACA,SACiC;AACjC,QAAM,gBAAiD,CAAC;AACxD,aAAW,cAAc,aA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M,cAAc,WAAW,eAAe;AAC9C,QAAM,gBAAiD,CAAC;AACxD,QAAM,eACJ,KAAK,SAAS,oBAAK,YACf,qCAAkB,GAAsB,QACxC,
|
|
4
|
+
"sourcesContent": ["import {\n GraphQLError,\n Kind,\n print,\n locatedError,\n DirectiveNode,\n FieldNode,\n VariableDefinitionNode,\n} from \"graphql\";\nimport { inspect } from \"./jsutils/inspect\";\nimport { printPathArray } from \"./jsutils/printPathArray\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport {\n DirectiveDefinitionTuple,\n FieldDefinition,\n getFieldArguments,\n getDirectiveDefinitionName,\n getInputDefaultValue,\n getInputValueTypeReference,\n isDefined,\n isInputType,\n getDirectiveDefinitionArgs,\n} from \"./schema/definition\";\nimport { valueFromAST } from \"./utilities/valueFromAST\";\nimport { coerceInputValue } from \"./utilities/coerceInputValue\";\nimport {\n inspectTypeReference,\n isNonNullType,\n typeReferenceFromNode,\n} from \"./schema/reference\";\nimport type { SchemaFragment } from \"./types\";\n\ntype CoercedVariableValues =\n | { errors: Array<GraphQLError>; coerced?: never }\n | { coerced: { [variable: string]: unknown }; errors?: never };\n\n/**\n * Prepares an object map of variableValues of the correct type based on the\n * provided variable definitions and arbitrary input. If the input cannot be\n * parsed to match the variable definitions, a GraphQLError will be thrown.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n options?: { maxErrors?: number },\n): CoercedVariableValues {\n const errors: GraphQLError[] = [];\n const maxErrors = options?.maxErrors;\n try {\n const coerced = coerceVariableValues(\n schemaFragment,\n varDefNodes,\n inputs,\n (error) => {\n if (maxErrors != null && errors.length >= maxErrors) {\n throw locatedError(\n \"Too many errors processing variables, error limit reached. Execution aborted.\",\n [],\n );\n }\n errors.push(error);\n },\n );\n\n if (errors.length === 0) {\n return { coerced };\n }\n } catch (error) {\n errors.push(error as GraphQLError);\n }\n\n return { errors: errors };\n}\n\nfunction coerceVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n onError: (error: GraphQLError) => void,\n): { [variable: string]: unknown } {\n const coercedValues: { [variable: string]: unknown } = {};\n for (const varDefNode of varDefNodes) {\n const varName = varDefNode.variable.name.value;\n const varTypeReference = typeReferenceFromNode(varDefNode.type);\n\n if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n // Must use input types for variables. This should be caught during\n // validation, however is checked again here for safety.\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" expected value of type \"${varTypeStr}\" which cannot be used as an input type.`,\n [varDefNode.type],\n ),\n );\n continue;\n }\n\n if (!hasOwnProperty(inputs, varName)) {\n if (varDefNode.defaultValue) {\n coercedValues[varName] = valueFromAST(\n varDefNode.defaultValue,\n varTypeReference,\n schemaFragment,\n );\n } else if (isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of required type \"${varTypeStr}\" was not provided.`,\n [varDefNode],\n ),\n );\n }\n continue;\n }\n\n const value = inputs[varName];\n if (value === null && isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of non-null type \"${varTypeStr}\" must not be null.`,\n [varDefNode],\n ),\n );\n continue;\n }\n\n coercedValues[varName] = coerceInputValue(\n value,\n varTypeReference,\n schemaFragment,\n (path, invalidValue, error) => {\n let prefix =\n `Variable \"$${varName}\" got invalid value ` + inspect(invalidValue);\n if (path.length > 0) {\n prefix += ` at \"${varName}${printPathArray(path)}\"`;\n }\n onError(locatedError(prefix + \"; \" + error.message, [varDefNode]));\n },\n );\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a list of argument\n * definitions and list of argument AST nodes.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getArgumentValues(\n exeContext: ExecutionContext,\n def: FieldDefinition | DirectiveDefinitionTuple,\n node: FieldNode | DirectiveNode,\n): { [argument: string]: unknown } {\n const definitions = exeContext.schemaFragment.definitions;\n const coercedValues: { [argument: string]: unknown } = {};\n const argumentDefs =\n node.kind === Kind.FIELD\n ? getFieldArguments(def as FieldDefinition)\n : getDirectiveDefinitionArgs(def as DirectiveDefinitionTuple);\n if (!argumentDefs) {\n return coercedValues;\n }\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const argumentNodes = node.arguments ?? [];\n const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));\n\n for (const [name, argumentDef] of Object.entries(argumentDefs)) {\n const argumentNode = argNodeMap.get(name);\n const argumentTypeRef = getInputValueTypeReference(argumentDef);\n const defaultValue = getInputDefaultValue(argumentDef);\n\n if (argumentNode == null) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" was not provided.`,\n [node],\n );\n }\n continue;\n }\n\n if (!isDefined(definitions, argumentTypeRef)) {\n throw locatedError(\n `Could not find type for argument ${name} in ${node.kind} ${node.name.value}`,\n [argumentNode],\n );\n }\n\n // if (!schemaTypes.isInputType(argumentTypeRef)) {\n // const type = schemaTypes.printTypeRef(argumentTypeRef);\n // throw locatedError(\n // `Argument \"$${name}\" expected value of type \"${type}\" which cannot be used as an input type.`,\n // [argumentNode],\n // );\n // }\n\n const valueNode = argumentNode.value;\n let isNull = valueNode.kind === Kind.NULL;\n\n if (valueNode.kind === Kind.VARIABLE) {\n const variableName = valueNode.name.value;\n if (\n exeContext.variableValues == null ||\n !hasOwnProperty(exeContext.variableValues, variableName)\n ) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" ` +\n `was provided the variable \"$${variableName}\" which was not provided a runtime value.`,\n [valueNode],\n );\n }\n continue;\n }\n isNull = exeContext.variableValues[variableName] == null;\n }\n\n if (isNull && isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of non-null type \"${type}\" must not be null.\"`,\n [valueNode],\n );\n }\n\n const coercedValue = valueFromAST(\n valueNode,\n argumentTypeRef,\n exeContext.schemaFragment,\n exeContext.variableValues,\n );\n if (coercedValue === undefined) {\n // Note: ValuesOfCorrectTypeRule validation should catch this before\n // execution. This is a runtime check to ensure execution does not\n // continue with an invalid argument value.\n throw locatedError(\n `Argument \"${name}\" has invalid value ${print(valueNode)}.`,\n [valueNode],\n );\n }\n coercedValues[name] = coercedValue;\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a directive definition\n * and a AST node which may contain directives. Optionally also accepts a map\n * of variable values.\n *\n * If the directive does not exist on the node, returns undefined.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n */\nexport function getDirectiveValues(\n exeContext: ExecutionContext,\n directiveDef: DirectiveDefinitionTuple,\n node: { directives?: ReadonlyArray<DirectiveNode> },\n): undefined | { [argument: string]: unknown } {\n const name = getDirectiveDefinitionName(directiveDef);\n\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const directiveNode = node.directives?.find(\n (directive) => directive.name.value === name,\n );\n\n if (directiveNode) {\n return getArgumentValues(exeContext, directiveDef, directiveNode);\n }\n}\n\nfunction hasOwnProperty(obj: unknown, prop: string): boolean {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],
|
|
5
|
+
"mappings": ";;;;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A,IACF;AACA,kBAAc,IAAI,IAAI;AAAA,EACxB;AAEA,SAAO;AACT;AAaO,SAAS,mBACd,YACA,cACA,MAC6C;AA3R/C;AA4RE,QAAM,WAAO,8CAA2B,YAAY;AAGpD,QAAM,iBAAgB,UAAK,eAAL,mBAAiB;AAAA,IACrC,CAAC,cAAc,UAAU,KAAK,UAAU;AAAA;AAG1C,MAAI,eAAe;AACjB,WAAO,kBAAkB,YAAY,cAAc,aAAa;AAAA,EAClE;AACF;AAEA,SAAS,eAAe,KAAc,MAAuB;AAC3D,SAAO,OAAO,UAAU,eAAe,KAAK,KAAK,IAAI;AACvD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/lib/values.mjs
CHANGED
|
@@ -8,12 +8,12 @@ import { inspect } from "./jsutils/inspect.mjs";
|
|
|
8
8
|
import { printPathArray } from "./jsutils/printPathArray.mjs";
|
|
9
9
|
import {
|
|
10
10
|
getFieldArguments,
|
|
11
|
-
|
|
11
|
+
getDirectiveDefinitionName,
|
|
12
12
|
getInputDefaultValue,
|
|
13
13
|
getInputValueTypeReference,
|
|
14
14
|
isDefined,
|
|
15
15
|
isInputType,
|
|
16
|
-
|
|
16
|
+
getDirectiveDefinitionArgs
|
|
17
17
|
} from "./schema/definition.mjs";
|
|
18
18
|
import { valueFromAST } from "./utilities/valueFromAST.mjs";
|
|
19
19
|
import { coerceInputValue } from "./utilities/coerceInputValue.mjs";
|
|
@@ -111,7 +111,7 @@ function getArgumentValues(exeContext, def, node) {
|
|
|
111
111
|
var _a;
|
|
112
112
|
const definitions = exeContext.schemaFragment.definitions;
|
|
113
113
|
const coercedValues = {};
|
|
114
|
-
const argumentDefs = node.kind === Kind.FIELD ? getFieldArguments(def) :
|
|
114
|
+
const argumentDefs = node.kind === Kind.FIELD ? getFieldArguments(def) : getDirectiveDefinitionArgs(def);
|
|
115
115
|
if (!argumentDefs) {
|
|
116
116
|
return coercedValues;
|
|
117
117
|
}
|
|
@@ -182,7 +182,7 @@ function getArgumentValues(exeContext, def, node) {
|
|
|
182
182
|
}
|
|
183
183
|
function getDirectiveValues(exeContext, directiveDef, node) {
|
|
184
184
|
var _a;
|
|
185
|
-
const name =
|
|
185
|
+
const name = getDirectiveDefinitionName(directiveDef);
|
|
186
186
|
const directiveNode = (_a = node.directives) == null ? void 0 : _a.find(
|
|
187
187
|
(directive) => directive.name.value === name
|
|
188
188
|
);
|
package/lib/values.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/values.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n GraphQLError,\n Kind,\n print,\n locatedError,\n DirectiveNode,\n FieldNode,\n VariableDefinitionNode,\n} from \"graphql\";\nimport { inspect } from \"./jsutils/inspect\";\nimport { printPathArray } from \"./jsutils/printPathArray\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport {\n DirectiveDefinitionTuple,\n FieldDefinition,\n getFieldArguments,\n getDirectiveName,\n getInputDefaultValue,\n getInputValueTypeReference,\n isDefined,\n isInputType,\n getDirectiveArguments,\n} from \"./schema/definition\";\nimport { valueFromAST } from \"./utilities/valueFromAST\";\nimport { coerceInputValue } from \"./utilities/coerceInputValue\";\nimport {\n inspectTypeReference,\n isNonNullType,\n typeReferenceFromNode,\n} from \"./schema/reference\";\nimport type { SchemaFragment } from \"./types\";\n\ntype CoercedVariableValues =\n | { errors: Array<GraphQLError>; coerced?: never }\n | { coerced: { [variable: string]: unknown }; errors?: never };\n\n/**\n * Prepares an object map of variableValues of the correct type based on the\n * provided variable definitions and arbitrary input. If the input cannot be\n * parsed to match the variable definitions, a GraphQLError will be thrown.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n options?: { maxErrors?: number },\n): CoercedVariableValues {\n const errors: GraphQLError[] = [];\n const maxErrors = options?.maxErrors;\n try {\n const coerced = coerceVariableValues(\n schemaFragment,\n varDefNodes,\n inputs,\n (error) => {\n if (maxErrors != null && errors.length >= maxErrors) {\n throw locatedError(\n \"Too many errors processing variables, error limit reached. Execution aborted.\",\n [],\n );\n }\n errors.push(error);\n },\n );\n\n if (errors.length === 0) {\n return { coerced };\n }\n } catch (error) {\n errors.push(error as GraphQLError);\n }\n\n return { errors: errors };\n}\n\nfunction coerceVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n onError: (error: GraphQLError) => void,\n): { [variable: string]: unknown } {\n const coercedValues: { [variable: string]: unknown } = {};\n for (const varDefNode of varDefNodes) {\n const varName = varDefNode.variable.name.value;\n const varTypeReference = typeReferenceFromNode(varDefNode.type);\n\n if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n // Must use input types for variables. This should be caught during\n // validation, however is checked again here for safety.\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" expected value of type \"${varTypeStr}\" which cannot be used as an input type.`,\n [varDefNode.type],\n ),\n );\n continue;\n }\n\n if (!hasOwnProperty(inputs, varName)) {\n if (varDefNode.defaultValue) {\n coercedValues[varName] = valueFromAST(\n varDefNode.defaultValue,\n varTypeReference,\n schemaFragment,\n );\n } else if (isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of required type \"${varTypeStr}\" was not provided.`,\n [varDefNode],\n ),\n );\n }\n continue;\n }\n\n const value = inputs[varName];\n if (value === null && isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of non-null type \"${varTypeStr}\" must not be null.`,\n [varDefNode],\n ),\n );\n continue;\n }\n\n coercedValues[varName] = coerceInputValue(\n value,\n varTypeReference,\n schemaFragment,\n (path, invalidValue, error) => {\n let prefix =\n `Variable \"$${varName}\" got invalid value ` + inspect(invalidValue);\n if (path.length > 0) {\n prefix += ` at \"${varName}${printPathArray(path)}\"`;\n }\n onError(locatedError(prefix + \"; \" + error.message, [varDefNode]));\n },\n );\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a list of argument\n * definitions and list of argument AST nodes.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getArgumentValues(\n exeContext: ExecutionContext,\n def: FieldDefinition | DirectiveDefinitionTuple,\n node: FieldNode | DirectiveNode,\n): { [argument: string]: unknown } {\n const definitions = exeContext.schemaFragment.definitions;\n const coercedValues: { [argument: string]: unknown } = {};\n const argumentDefs =\n node.kind === Kind.FIELD\n ? getFieldArguments(def as FieldDefinition)\n : getDirectiveArguments(def as DirectiveDefinitionTuple);\n if (!argumentDefs) {\n return coercedValues;\n }\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const argumentNodes = node.arguments ?? [];\n const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));\n\n for (const [name, argumentDef] of Object.entries(argumentDefs)) {\n const argumentNode = argNodeMap.get(name);\n const argumentTypeRef = getInputValueTypeReference(argumentDef);\n const defaultValue = getInputDefaultValue(argumentDef);\n\n if (argumentNode == null) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" was not provided.`,\n [node],\n );\n }\n continue;\n }\n\n if (!isDefined(definitions, argumentTypeRef)) {\n throw locatedError(\n `Could not find type for argument ${name} in ${node.kind} ${node.name.value}`,\n [argumentNode],\n );\n }\n\n // if (!schemaTypes.isInputType(argumentTypeRef)) {\n // const type = schemaTypes.printTypeRef(argumentTypeRef);\n // throw locatedError(\n // `Argument \"$${name}\" expected value of type \"${type}\" which cannot be used as an input type.`,\n // [argumentNode],\n // );\n // }\n\n const valueNode = argumentNode.value;\n let isNull = valueNode.kind === Kind.NULL;\n\n if (valueNode.kind === Kind.VARIABLE) {\n const variableName = valueNode.name.value;\n if (\n exeContext.variableValues == null ||\n !hasOwnProperty(exeContext.variableValues, variableName)\n ) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" ` +\n `was provided the variable \"$${variableName}\" which was not provided a runtime value.`,\n [valueNode],\n );\n }\n continue;\n }\n isNull = exeContext.variableValues[variableName] == null;\n }\n\n if (isNull && isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of non-null type \"${type}\" must not be null.\"`,\n [valueNode],\n );\n }\n\n const coercedValue = valueFromAST(\n valueNode,\n argumentTypeRef,\n exeContext.schemaFragment,\n exeContext.variableValues,\n );\n if (coercedValue === undefined) {\n // Note: ValuesOfCorrectTypeRule validation should catch this before\n // execution. This is a runtime check to ensure execution does not\n // continue with an invalid argument value.\n throw locatedError(\n `Argument \"${name}\" has invalid value ${print(valueNode)}.`,\n [valueNode],\n );\n }\n coercedValues[name] = coercedValue;\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a directive definition\n * and a AST node which may contain directives. Optionally also accepts a map\n * of variable values.\n *\n * If the directive does not exist on the node, returns undefined.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n */\nexport function getDirectiveValues(\n exeContext: ExecutionContext,\n directiveDef: DirectiveDefinitionTuple,\n node: { directives?: ReadonlyArray<DirectiveNode> },\n): undefined | { [argument: string]: unknown } {\n const name = getDirectiveName(directiveDef);\n\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const directiveNode = node.directives?.find(\n (directive) => directive.name.value === name,\n );\n\n if (directiveNode) {\n return getArgumentValues(exeContext, directiveDef, directiveNode);\n }\n}\n\nfunction hasOwnProperty(obj: unknown, prop: string): boolean {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAE/B;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAkBA,SAAS,kBACd,gBACA,aACA,QACA,SACuB;AACvB,QAAM,SAAyB,CAAC;AAChC,QAAM,YAAY,mCAAS;AAC3B,MAAI;AACF,UAAM,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA,CAAC,UAAU;AACT,YAAI,aAAa,QAAQ,OAAO,UAAU,WAAW;AACnD,gBAAM;AAAA,YACJ;AAAA,YACA,CAAC;AAAA,UACH;AAAA,QACF;AACA,eAAO,KAAK,KAAK;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,GAAG;AACvB,aAAO,EAAE,QAAQ;AAAA,IACnB;AAAA,EACF,SAAS,OAAP;AACA,WAAO,KAAK,KAAqB;AAAA,EACnC;AAEA,SAAO,EAAE,OAAe;AAC1B;AAEA,SAAS,qBACP,gBACA,aACA,QACA,SACiC;AACjC,QAAM,gBAAiD,CAAC;AACxD,aAAW,cAAc,aAAa;AACpC,UAAM,UAAU,WAAW,SAAS,KAAK;AACzC,UAAM,mBAAmB,sBAAsB,WAAW,IAAI;AAE9D,QAAI,CAAC,YAAY,eAAe,aAAa,gBAAgB,GAAG;AAG9D,YAAM,aAAa,qBAAqB,gBAAgB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Node,\n FieldNode,\n VariableDefinitionNode,\n} from \"graphql\";\nimport { inspect } from \"./jsutils/inspect\";\nimport { printPathArray } from \"./jsutils/printPathArray\";\nimport { ExecutionContext } from \"./executeWithoutSchema\";\nimport {\n DirectiveDefinitionTuple,\n FieldDefinition,\n getFieldArguments,\n getDirectiveDefinitionName,\n getInputDefaultValue,\n getInputValueTypeReference,\n isDefined,\n isInputType,\n getDirectiveDefinitionArgs,\n} from \"./schema/definition\";\nimport { valueFromAST } from \"./utilities/valueFromAST\";\nimport { coerceInputValue } from \"./utilities/coerceInputValue\";\nimport {\n inspectTypeReference,\n isNonNullType,\n typeReferenceFromNode,\n} from \"./schema/reference\";\nimport type { SchemaFragment } from \"./types\";\n\ntype CoercedVariableValues =\n | { errors: Array<GraphQLError>; coerced?: never }\n | { coerced: { [variable: string]: unknown }; errors?: never };\n\n/**\n * Prepares an object map of variableValues of the correct type based on the\n * provided variable definitions and arbitrary input. If the input cannot be\n * parsed to match the variable definitions, a GraphQLError will be thrown.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n options?: { maxErrors?: number },\n): CoercedVariableValues {\n const errors: GraphQLError[] = [];\n const maxErrors = options?.maxErrors;\n try {\n const coerced = coerceVariableValues(\n schemaFragment,\n varDefNodes,\n inputs,\n (error) => {\n if (maxErrors != null && errors.length >= maxErrors) {\n throw locatedError(\n \"Too many errors processing variables, error limit reached. Execution aborted.\",\n [],\n );\n }\n errors.push(error);\n },\n );\n\n if (errors.length === 0) {\n return { coerced };\n }\n } catch (error) {\n errors.push(error as GraphQLError);\n }\n\n return { errors: errors };\n}\n\nfunction coerceVariableValues(\n schemaFragment: SchemaFragment,\n varDefNodes: ReadonlyArray<VariableDefinitionNode>,\n inputs: { [variable: string]: unknown },\n onError: (error: GraphQLError) => void,\n): { [variable: string]: unknown } {\n const coercedValues: { [variable: string]: unknown } = {};\n for (const varDefNode of varDefNodes) {\n const varName = varDefNode.variable.name.value;\n const varTypeReference = typeReferenceFromNode(varDefNode.type);\n\n if (!isInputType(schemaFragment.definitions, varTypeReference)) {\n // Must use input types for variables. This should be caught during\n // validation, however is checked again here for safety.\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" expected value of type \"${varTypeStr}\" which cannot be used as an input type.`,\n [varDefNode.type],\n ),\n );\n continue;\n }\n\n if (!hasOwnProperty(inputs, varName)) {\n if (varDefNode.defaultValue) {\n coercedValues[varName] = valueFromAST(\n varDefNode.defaultValue,\n varTypeReference,\n schemaFragment,\n );\n } else if (isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of required type \"${varTypeStr}\" was not provided.`,\n [varDefNode],\n ),\n );\n }\n continue;\n }\n\n const value = inputs[varName];\n if (value === null && isNonNullType(varTypeReference)) {\n const varTypeStr = inspectTypeReference(varTypeReference);\n onError(\n locatedError(\n `Variable \"$${varName}\" of non-null type \"${varTypeStr}\" must not be null.`,\n [varDefNode],\n ),\n );\n continue;\n }\n\n coercedValues[varName] = coerceInputValue(\n value,\n varTypeReference,\n schemaFragment,\n (path, invalidValue, error) => {\n let prefix =\n `Variable \"$${varName}\" got invalid value ` + inspect(invalidValue);\n if (path.length > 0) {\n prefix += ` at \"${varName}${printPathArray(path)}\"`;\n }\n onError(locatedError(prefix + \"; \" + error.message, [varDefNode]));\n },\n );\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a list of argument\n * definitions and list of argument AST nodes.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n *\n * @internal\n */\nexport function getArgumentValues(\n exeContext: ExecutionContext,\n def: FieldDefinition | DirectiveDefinitionTuple,\n node: FieldNode | DirectiveNode,\n): { [argument: string]: unknown } {\n const definitions = exeContext.schemaFragment.definitions;\n const coercedValues: { [argument: string]: unknown } = {};\n const argumentDefs =\n node.kind === Kind.FIELD\n ? getFieldArguments(def as FieldDefinition)\n : getDirectiveDefinitionArgs(def as DirectiveDefinitionTuple);\n if (!argumentDefs) {\n return coercedValues;\n }\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const argumentNodes = node.arguments ?? [];\n const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));\n\n for (const [name, argumentDef] of Object.entries(argumentDefs)) {\n const argumentNode = argNodeMap.get(name);\n const argumentTypeRef = getInputValueTypeReference(argumentDef);\n const defaultValue = getInputDefaultValue(argumentDef);\n\n if (argumentNode == null) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" was not provided.`,\n [node],\n );\n }\n continue;\n }\n\n if (!isDefined(definitions, argumentTypeRef)) {\n throw locatedError(\n `Could not find type for argument ${name} in ${node.kind} ${node.name.value}`,\n [argumentNode],\n );\n }\n\n // if (!schemaTypes.isInputType(argumentTypeRef)) {\n // const type = schemaTypes.printTypeRef(argumentTypeRef);\n // throw locatedError(\n // `Argument \"$${name}\" expected value of type \"${type}\" which cannot be used as an input type.`,\n // [argumentNode],\n // );\n // }\n\n const valueNode = argumentNode.value;\n let isNull = valueNode.kind === Kind.NULL;\n\n if (valueNode.kind === Kind.VARIABLE) {\n const variableName = valueNode.name.value;\n if (\n exeContext.variableValues == null ||\n !hasOwnProperty(exeContext.variableValues, variableName)\n ) {\n if (defaultValue !== undefined) {\n coercedValues[name] = defaultValue;\n } else if (isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of required type \"${type}\" ` +\n `was provided the variable \"$${variableName}\" which was not provided a runtime value.`,\n [valueNode],\n );\n }\n continue;\n }\n isNull = exeContext.variableValues[variableName] == null;\n }\n\n if (isNull && isNonNullType(argumentTypeRef)) {\n const type = inspectTypeReference(argumentTypeRef);\n throw locatedError(\n `Argument \"${name}\" of non-null type \"${type}\" must not be null.\"`,\n [valueNode],\n );\n }\n\n const coercedValue = valueFromAST(\n valueNode,\n argumentTypeRef,\n exeContext.schemaFragment,\n exeContext.variableValues,\n );\n if (coercedValue === undefined) {\n // Note: ValuesOfCorrectTypeRule validation should catch this before\n // execution. This is a runtime check to ensure execution does not\n // continue with an invalid argument value.\n throw locatedError(\n `Argument \"${name}\" has invalid value ${print(valueNode)}.`,\n [valueNode],\n );\n }\n coercedValues[name] = coercedValue;\n }\n\n return coercedValues;\n}\n\n/**\n * Prepares an object map of argument values given a directive definition\n * and a AST node which may contain directives. Optionally also accepts a map\n * of variable values.\n *\n * If the directive does not exist on the node, returns undefined.\n *\n * Note: The returned value is a plain Object with a prototype, since it is\n * exposed to user code. Care should be taken to not pull values from the\n * Object prototype.\n */\nexport function getDirectiveValues(\n exeContext: ExecutionContext,\n directiveDef: DirectiveDefinitionTuple,\n node: { directives?: ReadonlyArray<DirectiveNode> },\n): undefined | { [argument: string]: unknown } {\n const name = getDirectiveDefinitionName(directiveDef);\n\n // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')\n const directiveNode = node.directives?.find(\n (directive) => directive.name.value === name,\n );\n\n if (directiveNode) {\n return getArgumentValues(exeContext, directiveDef, directiveNode);\n }\n}\n\nfunction hasOwnProperty(obj: unknown, prop: string): boolean {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAE/B;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK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