MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / prepareOperations

Function prepareOperations

packages/plugins/graphql/src/sdk/plugin.ts:471–535  ·  view source on GitHub ↗
(
  fields: readonly ExtractedField[],
  introspection: IntrospectionResult,
)

Source from the content-addressed store, hash-verified

469};
470
471const prepareOperations = (
472 fields: readonly ExtractedField[],
473 introspection: IntrospectionResult,
474): readonly PreparedOperation[] => {
475 const typeMap = new Map<string, IntrospectionType>();
476 for (const t of introspection.__schema.types) {
477 typeMap.set(t.name, t);
478 }
479
480 const fieldMap = new Map<string, { kind: GraphqlOperationKind; field: IntrospectionField }>();
481 const schema = introspection.__schema;
482 for (const rootKind of ["query", "mutation"] as const) {
483 const typeName = rootKind === "query" ? schema.queryType?.name : schema.mutationType?.name;
484 if (!typeName) continue;
485 const rootType = typeMap.get(typeName);
486 if (!rootType?.fields) continue;
487 for (const f of rootType.fields) {
488 if (!f.name.startsWith("__")) {
489 fieldMap.set(`${rootKind}.${f.name}`, { kind: rootKind, field: f });
490 }
491 }
492 }
493
494 return fields.map((extracted) => {
495 const prefix = extracted.kind === "mutation" ? "mutation" : "query";
496 // A tool's name keeps its `<kind>.<field>` path (e.g. `query.hello`,
497 // `mutation.setGreeting`). The address grammar treats `<tool>` as the
498 // trailing remainder (see parseToolAddress), so the dot nests naturally.
499 const toolName = `${prefix}.${extracted.fieldName}`;
500 const description = Option.getOrElse(
501 extracted.description,
502 () => `GraphQL ${extracted.kind}: ${extracted.fieldName} -> ${extracted.returnTypeName}`,
503 );
504
505 const key = `${extracted.kind}.${extracted.fieldName}`;
506 const entry = fieldMap.get(key);
507 const built = entry
508 ? buildOperationStringForField(entry.kind, entry.field, typeMap)
509 : {
510 operationString: `${extracted.kind} ${operationNameForField(extracted.fieldName)} { ${extracted.fieldName} }`,
511 operationPrefix: undefined,
512 operationSuffix: undefined,
513 };
514
515 const binding = OperationBinding.make({
516 kind: extracted.kind,
517 fieldName: extracted.fieldName,
518 operationString: built.operationString,
519 variableNames: extracted.arguments.map((a) => a.name),
520 ...(built.operationPrefix !== undefined && built.operationSuffix !== undefined
521 ? { operationPrefix: built.operationPrefix, operationSuffix: built.operationSuffix }
522 : {}),
523 });
524
525 return {
526 toolName,
527 description,
528 inputSchema: withSelectInput(

Callers 3

materializeOperationsFunction · 0.85
plugin.tsFile · 0.85

Calls 5

operationNameForFieldFunction · 0.85
withSelectInputFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected