Skip to content

chatfuel-lab/wizard / content/modules/core/skill

scripts/validate-operations.mjs

View on GitHub
#!/usr/bin/env node
// Validates GraphQL documents against references/schema.graphql.
// With no args: validates this skill's examples/ plus every sibling
// chatfuel-* skill's examples/ (installed layout: ../../chatfuel-<id>/).
// With args: validates the given .graphql files instead.
// Usage: node scripts/validate-operations.mjs [file.graphql ...]
// Requires the `graphql` package (any v16+): npm i --no-save graphql
import { readFileSync, readdirSync, existsSync } from 'node:fs';
import { dirname, join, relative, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { buildSchema, parse, validate, specifiedRules } from 'graphql';

const skillRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
const schema = buildSchema(readFileSync(join(skillRoot, 'references', 'schema.graphql'), 'utf8'));

let files;
if (process.argv.length > 2) {
  files = process.argv.slice(2).map((f) => resolve(process.cwd(), f));
} else {
  files = [];
  const skillsDir = dirname(skillRoot);
  const siblings = readdirSync(skillsDir, { withFileTypes: true })
    .filter((d) => d.isDirectory() && d.name.startsWith('chatfuel-'))
    .map((d) => join(skillsDir, d.name));
  for (const dir of [skillRoot, ...siblings.filter((d) => d !== skillRoot)]) {
    const examples = join(dir, 'examples');
    if (!existsSync(examples)) continue;
    for (const f of readdirSync(examples)) {
      if (f.endsWith('.graphql')) files.push(join(examples, f));
    }
  }
}

let errorCount = 0;
for (const file of files) {
  const label = relative(process.cwd(), file);
  const source = readFileSync(file, 'utf8');
  let doc;
  try {
    doc = parse(source);
  } catch (e) {
    console.error(`✗ ${label}: parse error: ${e.message}`);
    errorCount += 1;
    continue;
  }
  const errors = validate(schema, doc, specifiedRules);
  if (errors.length === 0) {
    const ops = doc.definitions.filter((d) => d.kind === 'OperationDefinition').length;
    const frags = doc.definitions.filter((d) => d.kind === 'FragmentDefinition').length;
    console.log(`✓ ${label}: ${ops} operations, ${frags} fragments — valid`);
  } else {
    for (const e of errors) {
      const loc = e.locations?.[0];
      console.error(`✗ ${label}${loc ? `:${loc.line}` : ''}: ${e.message}`);
      errorCount += 1;
    }
  }
}

if (errorCount > 0) {
  console.error(`\n${errorCount} error(s).`);
  process.exit(1);
}
console.log('\nAll documents are valid.');
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall