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

Function prepareOperations

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

Source from the content-addressed store, hash-verified

499};
500
501const prepareOperations = (
502 fields: readonly ExtractedField[],
503 introspection: IntrospectionResult,
504): readonly PreparedOperation[] => {
505 const typeMap = new Map<string, IntrospectionType>();
506 for (const t of introspection.__schema.types) {
507 typeMap.set(t.name, t);
508 }
509
510 const fieldMap = new Map<string, { kind: GraphqlOperationKind; field: IntrospectionField }>();
511 const schema = introspection.__schema;
512 for (const rootKind of ["query", "mutation"] as const) {
513 const typeName = rootKind === "query" ? schema.queryType?.name : schema.mutationType?.name;
514 if (!typeName) continue;
515 const rootType = typeMap.get(typeName);
516 if (!rootType?.fields) continue;
517 for (const f of rootType.fields) {
518 if (!f.name.startsWith("__")) {
519 fieldMap.set(`${rootKind}.${f.name}`, { kind: rootKind, field: f });
520 }
521 }
522 }
523
524 return fields.map((extracted) => {
525 const prefix = extracted.kind === "mutation" ? "mutation" : "query";
526 // A tool's name keeps its `<kind>.<field>` path (e.g. `query.hello`,
527 // `mutation.setGreeting`). The address grammar treats `<tool>` as the
528 // trailing remainder (see parseToolAddress), so the dot nests naturally.
529 const toolName = `${prefix}.${extracted.fieldName}`;
530 const description = Option.getOrElse(
531 extracted.description,
532 () => `GraphQL ${extracted.kind}: ${extracted.fieldName} -> ${extracted.returnTypeName}`,
533 );
534
535 const key = `${extracted.kind}.${extracted.fieldName}`;
536 const entry = fieldMap.get(key);
537 const built = entry
538 ? buildOperationStringForField(entry.kind, entry.field, typeMap)
539 : {
540 operationString: `${extracted.kind} ${operationNameForField(extracted.fieldName)} { ${extracted.fieldName} }`,
541 operationPrefix: undefined,
542 operationSuffix: undefined,
543 };
544
545 const binding = OperationBinding.make({
546 kind: extracted.kind,
547 fieldName: extracted.fieldName,
548 operationString: built.operationString,
549 variableNames: extracted.arguments.map((a) => a.name),
550 ...(built.operationPrefix !== undefined && built.operationSuffix !== undefined
551 ? { operationPrefix: built.operationPrefix, operationSuffix: built.operationSuffix }
552 : {}),
553 });
554
555 return {
556 toolName,
557 description,
558 inputSchema: withSelectInput(

Callers 3

materializeOperationsFunction · 0.85
plugin.tsFile · 0.85

Calls 5

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

Tested by

no test coverage detected