Kong/insomnia · error · Error

Found usage of unknown fragment

Error message

Found usage of unknown fragment ${selection.name.value}

What it means

Thrown by replaceFragments in the GraphQL editor's prettify/inline pipeline: a selection is a FragmentSpread whose name has no matching definition in the supplied fragments list, so inlining that fragment is impossible. Indicates a query referencing an undefined fragment.

Solutions

  1. Define the missing fragment (e.g. `fragment X on Type { ... }`) somewhere in the query document before inlining
  2. Remove the fragment spread from the query if it is unused or unnecessary
  3. Check for typos between the spread name and the fragment definition name
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/insomnia/src/ui/components/editors/body/prettify-graphql.mjs:99 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26). Data as JSON: /api/errors/c5d4d4ea6fe2d8dc. Report an issue: GitHub.

Appendix: source

Thrown at packages/insomnia/src/ui/components/editors/body/prettify-graphql.mjs:99

const replaceFragments = (sourceNode, fragments) => {
  if (isSelectionsEmpty(sourceNode)) {
    return sourceNode;
  }

  const newNode = { ...sourceNode };

  let foundFragments = [];

  newNode.selectionSet.selections = newNode.selectionSet.selections.filter(selection => {
    if (selection.kind !== Kind.FRAGMENT_SPREAD) {
      return true;
    }

    if (!foundFragments.find(fragment => fragment.name.value === selection.name.value)) {
      const fragment = fragments.find(fragment => fragment.name.value === selection.name.value);

      if (!fragment) {
        throw new Error(`Found usage of unknown fragment ${selection.name.value}`);
      }

      foundFragments = [...foundFragments, fragment];
    }

    return false;
  });

  newNode.selectionSet.selections = [
    ...newNode.selectionSet.selections,
    ...foundFragments.reduce((acc, fragment) => [...fragment.selectionSet.selections, ...acc], []),
  ];

  newNode.selectionSet.selections = newNode.selectionSet.selections.map(selection =>
    replaceFragments(selection, fragments),
  );

  return newNode;

View on GitHub (pinned to d9bb2b0142)