Files
probo/contrib/merge-graphql-schema.sh
Émile Ré 00b233aa03 Fix Relay generating null query text for mutations
Relay v20 treats extend type in server schema as client extensions,
causing all mutation fields to have "text": null in generated artifacts.

Replace the cat-based schema concatenation with a merge script that
collects all extend type Mutation blocks and produces a single
type Mutation definition. The split graphql/ files remain the source
of truth for gqlgen; the merged schema.graphql is generated for Relay.

Signed-off-by: Émile Ré <emile@getprobo.com>
2026-04-15 09:19:41 +04:00

45 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Merge split GraphQL schema files into a single file for Relay.
# Strips "type Mutation" and "extend type Mutation { ... }" blocks,
# then appends a single "type Mutation { ... }" with all collected fields.
#
# Usage: merge-graphql-schema.sh <output> <graphql-dir>
set -eu
output="$1"
graphql_dir="$2"
base="$graphql_dir/base.graphql"
mutation_fields=$(mktemp)
schema_body=$(mktemp)
trap 'rm -f "$mutation_fields" "$schema_body"' EXIT
process_file() {
awk -v mf="$mutation_fields" '
/^type Mutation$/ { next }
/^(extend )?type Mutation \{/ { skip=1; depth=1; next }
skip {
if (/\{/) depth++
if (/\}/) { depth--; if (depth==0) { skip=0; next } }
if (skip) { print >> mf; next }
}
{ print }
' "$1"
}
{
process_file "$base"
for f in "$graphql_dir"/*.graphql; do
[ "$f" = "$base" ] && continue
process_file "$f"
done
} > "$schema_body"
{
cat "$schema_body"
printf '\ntype Mutation {\n'
cat "$mutation_fields"
printf '}\n'
} > "$output"