twentyhq/twenty · error · Error

Genql batch fetcher returned unexpected result + JSON.strin

Error message

Genql batch fetcher returned unexpected result  + JSON.stringify(json)

What it means

Thrown by the genql batch fetcher wrapper (fetcher.ts:88-95) after the batcher returns a JSON object that has no `data` field. Unlike the single fetcher path, the batch path does not unwrap GraphQL `errors` into a GenqlError — it treats anything lacking `data` as an unexpected result and serializes the whole JSON for debugging.

Source

Thrown at packages/twenty-client-sdk/src/generate/genql/runtime/fetcher.ts:93

            }
        }
    }

    const batcher = new QueryBatcher(
        async (batchedQuery) => {
            // console.log(batchedQuery) // [{ query: 'query{user{age}}', variables: {} }, ...]
            const json = await fetcher!(batchedQuery)
            return json as any
        },
        batch === true ? DEFAULT_BATCH_OPTIONS : batch,
    )

    return async ({ query, variables }) => {
        const json = await batcher.fetch(query, variables)
        if (json?.data) {
            return json.data
        }
        throw new Error(
            'Genql batch fetcher returned unexpected result ' + JSON.stringify(json),
        )
    }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Disable batching (pass `batch: false` or omit it) to fall through to the single-fetcher path that properly raises GenqlError on `errors`.
  2. Log JSON.stringify(json) from the thrown error to see the actual server response shape.
  3. Fix the underlying GraphQL error the server is reporting in the `errors` array.
  4. Confirm the Twenty server supports GraphQL query batching.

Example fix

// before
const client = createClient({ url, headers, batch: true });
// after
const client = createClient({ url, headers, batch: false });
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const data = await client.someQuery();
} catch (err) {
  if (err.message.startsWith('Genql batch fetcher returned unexpected result')) {
    // The JSON.stringify(json) suffix reveals the server payload shape.
    console.error('Batch unexpected:', err.message);
  }
  throw err;
}

Prevention

When it happens

Trigger: Batching is enabled (batch: true or batch options passed to createClient) and the server returns a GraphQL response containing only `errors` (no `data`), or a top-level JSON shape the client does not expect (e.g. an error envelope from a gateway).

Common situations: Server-side GraphQL validation errors that omit `data`; an API gateway returning `{ error: ... }`; an empty 200 response parsed to `{}`; mismatches between batched query count and server batching support.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/fd743954daac043f. Report an issue: GitHub.