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

Function checkGraphqlHealth

packages/plugins/graphql/src/sdk/plugin.ts:663–752  ·  view source on GitHub ↗
(input: {
  readonly integration: IntegrationRecord;
  readonly credential: {
    readonly template: AuthTemplateSlug;
    readonly values: Record<string, string | null>;
  };
  readonly spec?: { readonly operation: string };
  readonly httpClientLayer: Layer.Layer<HttpClient.HttpClient>;
})

Source from the content-addressed store, hash-verified

661};
662
663const checkGraphqlHealth = (input: {
664 readonly integration: IntegrationRecord;
665 readonly credential: {
666 readonly template: AuthTemplateSlug;
667 readonly values: Record<string, string | null>;
668 };
669 readonly spec?: { readonly operation: string };
670 readonly httpClientLayer: Layer.Layer<HttpClient.HttpClient>;
671}): Effect.Effect<HealthCheckResult, never> =>
672 Effect.gen(function* () {
673 const checkedAt = Date.now();
674 const decoded = yield* decodeGraphqlIntegrationConfig(input.integration.config).pipe(
675 Effect.option,
676 );
677 if (Option.isNone(decoded)) {
678 return {
679 status: "unknown",
680 checkedAt,
681 detail: "The GraphQL integration configuration is invalid. Edit it, then try again.",
682 } satisfies HealthCheckResult;
683 }
684
685 const config = decoded.value;
686 const operation =
687 input.spec?.operation ??
688 (config.introspectionHash === undefined ? GRAPHQL_HEALTH_OPERATION : undefined);
689 if (operation === undefined) {
690 return {
691 status: "unknown",
692 checkedAt,
693 detail: "No live schema health check is configured.",
694 } satisfies HealthCheckResult;
695 }
696 if (operation !== GRAPHQL_HEALTH_OPERATION) {
697 return {
698 status: "unknown",
699 checkedAt,
700 detail: `GraphQL health check operation "${operation}" is not supported. Use ${GRAPHQL_HEALTH_OPERATION}.`,
701 } satisfies HealthCheckResult;
702 }
703
704 const method = config.authenticationTemplate.find(
705 (candidate: GraphqlAuthMethod) => candidate.slug === String(input.credential.template),
706 );
707 const missing = missingCredentialVariables(method, input.credential.values);
708 if (missing.length > 0) {
709 return {
710 status: "expired",
711 checkedAt,
712 detail: `Enter a credential value for ${missing.join(", ")}, then try again.`,
713 } satisfies HealthCheckResult;
714 }
715
716 const auth = introspectHeadersForConnection(
717 config,
718 input.credential.values,
719 input.credential.template,
720 );

Callers 1

plugin.tsFile · 0.85

Calls 4

scrubCredentialValuesFunction · 0.85

Tested by

no test coverage detected