# Why renaming breaks a GraphQL schema


Here is a GraphQL server that works perfectly until the day you obfuscate it:

```csharp
public class Query
{
    public IQueryable<Product> GetProducts(CatalogContext db) => db.Products;
    public Task<Product?> GetProductById(int id, IProductRepository repo)
        => repo.FindAsync(id);
}

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public decimal Price { get; set; }
    public ProductStatus Status { get; set; }
}

public enum ProductStatus { Draft, Published, Archived }
```

Register it with `AddGraphQLServer().AddQueryType<Query>()` and HotChocolate emits this schema:

```graphql
type Query {
  products: [Product!]!
  productById(id: Int!): Product
}
type Product {
  id: Int!
  name: String!
  price: Decimal!
  status: ProductStatus!
}
enum ProductStatus { DRAFT PUBLISHED ARCHIVED }
```

Run the assembly through a renamer and start it again, and the schema becomes `type a { b: Int! c: String! … }` with a query field called `d`. Nothing threw. The server started cleanly and the schema is perfectly valid. But every client query you have ever shipped — `{ products { id name } }` — now fails with *"The field `products` does not exist on the type `Query`."* The contract broke at runtime, in a place no compiler and no build step could see.

This is the single most common way obfuscation "breaks GraphQL", and like the serialization version of the problem it is worth pinning down precisely — because the fix is not a blunt keep rule. It is one attribute, and it lets every symbol keep renaming.

## Why the rename reaches the wire

Internal calls survive renaming because they are linked by *metadata token*: the compiler emits `call` against a token, and a renamer that rewrites the callee rewrites every token that points at it, so the call graph stays connected. HotChocolate does not build the schema from tokens. At schema-build time it reflects over each registered type, reads the member's actual CLR `Name`, runs it through the naming convention, and uses *that string* as the GraphQL name. The default `DefaultNamingConventions` does three things worth knowing:

- a **type** name is used as-is (`Product` → `Product`);
- a **field** name is camel-cased, and a leading `Get` on a resolver method is stripped first (`GetProducts` → `products`, `GetProductById` → `productById`);
- an **enum value** is converted to CONSTANT_CASE (`Draft` → `DRAFT`); a resolver **parameter** name becomes the argument name (`id` → `id`).

So the wire name is a pure function of the CLR name. The renamer rewrites the CLR name to `a`; the naming convention faithfully turns `a` into the field `a`. HotChocolate has no idea a client ever called it `products`, because the only record of that name *was* the method name, and the method name is gone.

<figure class="my-8"><svg viewBox="0 0 760 300" role="img" aria-label="How a .NET member name flows into a GraphQL field name, and where GraphQLName pins it" xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="760" height="300" fill="none"/><text x="20" y="28" fill="#64748b" font-family="sans-serif" font-size="13" font-weight="bold">CLR member</text><rect x="20" y="40" width="150" height="54" rx="6" fill="none" stroke="#6366f1" stroke-width="2"/><text x="95" y="66" fill="#6366f1" font-family="monospace" font-size="13" text-anchor="middle">GetProducts()</text><text x="95" y="84" fill="#64748b" font-family="monospace" font-size="11" text-anchor="middle">method Name</text><text x="250" y="28" fill="#64748b" font-family="sans-serif" font-size="13" font-weight="bold">naming convention</text><rect x="250" y="40" width="170" height="54" rx="6" fill="none" stroke="#0891b2" stroke-width="2"/><text x="335" y="62" fill="#0891b2" font-family="sans-serif" font-size="11" text-anchor="middle">strip Get, camelCase</text><text x="335" y="82" fill="#0891b2" font-family="monospace" font-size="12" text-anchor="middle">reflect over Name</text><line x1="170" y1="67" x2="248" y2="67" stroke="#64748b" stroke-width="2" marker-end="url(#ar)"/><line x1="420" y1="67" x2="498" y2="67" stroke="#64748b" stroke-width="2" marker-end="url(#ar)"/><defs><marker id="ar" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path d="M0,0 L8,4 L0,8 z" fill="#64748b"/></marker></defs><rect x="500" y="40" width="240" height="54" rx="6" fill="#10b981"/><text x="620" y="62" fill="#ffffff" font-family="monospace" font-size="13" text-anchor="middle">products: [Product!]!</text><text x="620" y="82" fill="#ffffff" font-family="sans-serif" font-size="11" text-anchor="middle">GraphQL field (the contract)</text><text x="20" y="150" fill="#64748b" font-family="sans-serif" font-size="13" font-weight="bold">after obfuscation renames the method</text><rect x="20" y="162" width="150" height="40" rx="6" fill="none" stroke="#6366f1" stroke-width="2"/><text x="95" y="187" fill="#6366f1" font-family="monospace" font-size="13" text-anchor="middle">a()</text><line x1="170" y1="182" x2="498" y2="182" stroke="#64748b" stroke-width="2" stroke-dasharray="4 3" marker-end="url(#ar)"/><rect x="500" y="162" width="240" height="40" rx="6" fill="none" stroke="#64748b" stroke-width="2"/><text x="620" y="187" fill="#64748b" font-family="monospace" font-size="13" text-anchor="middle">a: [a!]!  — clients break</text><text x="20" y="246" fill="#64748b" font-family="sans-serif" font-size="13" font-weight="bold">with [GraphQLName("products")]</text><rect x="20" y="258" width="150" height="34" rx="6" fill="none" stroke="#6366f1" stroke-width="2"/><text x="95" y="280" fill="#6366f1" font-family="monospace" font-size="13" text-anchor="middle">a()</text><rect x="250" y="258" width="170" height="34" rx="6" fill="none" stroke="#0891b2" stroke-width="2"/><text x="335" y="280" fill="#0891b2" font-family="monospace" font-size="11" text-anchor="middle">read #Blob literal</text><line x1="170" y1="275" x2="248" y2="275" stroke="#64748b" stroke-width="2" marker-end="url(#ar)"/><line x1="420" y1="275" x2="498" y2="275" stroke="#64748b" stroke-width="2" marker-end="url(#ar)"/><rect x="500" y="258" width="240" height="34" rx="6" fill="#10b981"/><text x="620" y="280" fill="#ffffff" font-family="monospace" font-size="13" text-anchor="middle">products: [Product!]!  — stable</text><figcaption class="text-sm text-muted mt-2">The GraphQL name is derived from the reflected CLR name — so renaming moves it, unless an attribute pins it in the #Blob heap.</figcaption></svg></figure>

## The fix: pin the name, keep the rename

The decoupling you want is: *the resolver method renames (it is your logic, protect it), but the field name it exposes is frozen.* HotChocolate gives you exactly that with `[GraphQLName]`. Annotate every public surface with the name the schema must keep:

```csharp
[GraphQLName("Product")]
public class Product
{
    [GraphQLName("id")]     public int Id { get; set; }
    [GraphQLName("name")]   public string Name { get; set; } = "";
    [GraphQLName("price")]  public decimal Price { get; set; }
    [GraphQLName("status")] public ProductStatus Status { get; set; }
}

[GraphQLName("ProductStatus")]
public enum ProductStatus
{
    [GraphQLName("DRAFT")]     Draft,
    [GraphQLName("PUBLISHED")] Published,
    [GraphQLName("ARCHIVED")]  Archived,
}

public class Query
{
    [GraphQLName("products")]
    public IQueryable<Product> GetProducts(CatalogContext db) => db.Products;

    [GraphQLName("productById")]
    public Task<Product?> GetProductById(
        [GraphQLName("id")] int id, IProductRepository repo)
        => repo.FindAsync(id);
}
```

Why this holds under obfuscation is a metadata detail worth understanding. The string `"products"` is a custom-attribute argument, so it is stored in the assembly's `#Blob` heap and reached through the `CustomAttribute` table — it is **not** an `ldstr` instruction in any method body. HotChocolate reads that blob with reflection at schema-build time and uses it *in preference to* the member's CLR name. So the renamer is free to turn `GetProducts` into `a`; the schema builder never consults the CLR name because the attribute answered first. The field stays `products`.

This also means **string encryption cannot touch it**. Nebula's string encryption rewrites `ldstr` in method bodies into a decrypt call; it does not route custom-attribute blobs through the encryptor, because those are consumed by reflection and the framework expects the plain value. Your `[GraphQLName]` literals survive renaming *and* string encryption with no special configuration — which is precisely what you want, because the whole point is to protect the resolver bodies while leaving the public contract legible on the wire.

## The surfaces people forget

The type and field names are the obvious ones. Three others break the same way and are easy to miss:

- **Resolver arguments.** `GetProductById(int id, …)` exposes an argument named `id` derived from the *parameter* name. Nebula leaves parameter names alone by default, but if you enable parameter renaming the argument becomes `a`; `[GraphQLName("id")]` on the parameter pins it regardless.
- **Input objects.** An input type binds incoming values to properties by GraphQL name, and HotChocolate appends an `Input` suffix by convention (`AddProductInput`). Attribute the type and every property, exactly as you would an output type — an un-attributed input property silently drops the client's value and leaves the field at its default.
- **Relay global IDs.** If you expose nodes with `[Node]` and `[ID]`, the global ID is a base64 of the *type name* plus the key. Rename the type without pinning its schema name and every previously issued global ID becomes unresolvable, because the decoder looks for a type whose schema name matches the embedded string. Pin the node type's name and the IDs stay stable across builds.

## Verifying it, and the keep-rule fallback

Treat the schema as a contract artifact: export the SDL in CI before and after the protected build and diff them. HotChocolate ships `dotnet graphql schema export` (and you can print `ISchema` in a test), so a byte-for-byte SDL diff of the plain vs. obfuscated build is a hard gate — if any name moved, the diff is non-empty and the build fails. You can confirm the attribute literals survived at the metadata level by opening the protected assembly in [Glass.NET](https://delta1labs.com/products/glass) and reading the `CustomAttribute` blobs on the renamed members; the `[GraphQLName]` strings are plainly there while the member names are `a`, `b`, `c`.

There is a fallback for the rare type you genuinely cannot annotate — a schema stitched from a type you do not own, say. Add it to Nebula's keep-list so its names are excluded from renaming:

```json
{
  "rename": { "keep": [ "MyApp.Api.ExternalType", "MyApp.Api.ExternalType.*" ] }
}
```

But reach for `[GraphQLName]` first and the keep-list almost never. A keep rule preserves the CLR name in metadata — it leaks the symbol you obfuscated for and protects nothing. The attribute is strictly better: the member renames, the metadata is scrubbed, and only an opaque string in the blob heap carries the public name.

## Takeaway

A GraphQL schema built by convention is a reflection contract wearing a different hat: HotChocolate reads your CLR names and your CLR names *are* the wire API, so a renamer rewrites the API. Make the wire name explicit with `[GraphQLName]` on every type, field, argument, enum value, and input property, and the relationship inverts — the names become data in the blob heap that renaming and string encryption both leave alone, and the resolver logic you actually wanted to protect renames underneath a frozen schema. Export the SDL on both sides of the build and diff it, and you never ship a silently renamed contract. See the [Nebula.NET](https://delta1labs.com/products/nebula) obfuscation guide for the full rename and string-encryption configuration.

