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

Function prepareOperations

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

Source from the content-addressed store, hash-verified

349};
350
351const prepareOperations = (
352 fields: readonly ExtractedField[],
353 introspection: IntrospectionResult,
354): readonly PreparedOperation[] => {
355 const typeMap = new Map<string, IntrospectionType>();
356 for (const t of introspection.__schema.types) {
357 typeMap.set(t.name, t);
358 }
359
360 const fieldMap = new Map<string, { kind: GraphqlOperationKind; field: IntrospectionField }>();
361 const schema = introspection.__schema;
362 for (const rootKind of ["query", "mutation"] as const) {
363 const typeName = rootKind === "query" ? schema.queryType?.name : schema.mutationType?.name;
364 if (!typeName) continue;
365 const rootType = typeMap.get(typeName);
366 if (!rootType?.fields) continue;
367 for (const f of rootType.fields) {
368 if (!f.name.startsWith("__")) {
369 fieldMap.set(`${rootKind}.${f.name}`, { kind: rootKind, field: f });
370 }
371 }
372 }
373
374 return fields.map((extracted) => {
375 const prefix = extracted.kind === "mutation" ? "mutation" : "query";
376 // A tool's name keeps its `<kind>.<field>` path (e.g. `query.hello`,
377 // `mutation.setGreeting`). The address grammar treats `<tool>` as the
378 // trailing remainder (see parseToolAddress), so the dot nests naturally.
379 const toolName = `${prefix}.${extracted.fieldName}`;
380 const description = Option.getOrElse(
381 extracted.description,
382 () => `GraphQL ${extracted.kind}: ${extracted.fieldName} -> ${extracted.returnTypeName}`,
383 );
384
385 const key = `${extracted.kind}.${extracted.fieldName}`;
386 const entry = fieldMap.get(key);
387 const built = entry
388 ? buildOperationStringForField(entry.kind, entry.field, typeMap)
389 : {
390 operationString: `${extracted.kind} ${operationNameForField(extracted.fieldName)} { ${extracted.fieldName} }`,
391 operationPrefix: undefined,
392 operationSuffix: undefined,
393 };
394
395 const binding = OperationBinding.make({
396 kind: extracted.kind,
397 fieldName: extracted.fieldName,
398 operationString: built.operationString,
399 variableNames: extracted.arguments.map((a) => a.name),
400 ...(built.operationPrefix !== undefined && built.operationSuffix !== undefined
401 ? { operationPrefix: built.operationPrefix, operationSuffix: built.operationSuffix }
402 : {}),
403 });
404
405 return {
406 toolName,
407 description,
408 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