GraphQL to Java
Turn a GraphQL schema into Java classes with one private field per schema field, mapped to boxed types so nullable fields hold null.
What the GraphQL to Java does
Interfaces become empty interfaces, which is what a Java client can implement without inventing an accessor contract the schema never had.
Enums become Java enums with the schema's own value names, so an unknown value fails at the boundary instead of travelling as a forgotten string.
Unions and custom scalars are not emitted: Java has no closed union, and a scalar's payload type is the schema's choice rather than this page's.
How to use it
Paste the schema into the GraphQL schema box, or press Run with the example already there.
Read the Java below: every object and input type becomes one class, in declaration order.
Check a Java field you expected to be non-null — it is still boxed here, because the page cannot know how your client treats an absent field.
Worked example
Input:
type Query {
me: User
}
type User {
id: ID!
name: String
}
Output:
public class Query {
private User me;
}
public class User {
private String id;
private String name;
}
Why it runs in your browser
The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.
One class per object or input type, one private field per schema field, named exactly as the schema names it.
Scalars map to boxed types — Integer, Double, String, Boolean — so a nullable field can hold null instead of a primitive zero.
What it does, and what it does not
Interfaces become empty interfaces, which is what a Java client can implement without inventing an accessor contract the schema never had.
Enums become Java enums with the schema's own value names, so an unknown value fails at the boundary instead of travelling as a forgotten string.
Unions and custom scalars are not emitted: Java has no closed union, and a scalar's payload type is the schema's choice rather than this page's.
How to use GraphQL to Java
Paste the schema into the GraphQL schema box, or press Run with the example already there.
Read the Java below: every object and input type becomes one class, in declaration order.
Check a Java field you expected to be non-null — it is still boxed here, because the page cannot know how your client treats an absent field.
What to Expect
Best for
- Bootstrapping Java DTOs from a schema you already own
- Checking the Java type a schema field maps to
Not ideal for
- Generating accessors or builders — this page emits fields only
- Typing unions, which Java cannot express as a closed set
What this tool keeps
- Field names exactly as the schema spells them
- Enum value names preserved
What may need cleanup
- Every field needs an accessor written by hand
- A custom scalar is not emitted at all, so the field's type is a placeholder
Common errors
- The page refuses it: unknown type Missing referenced by Query.me
Example use cases
- Starting a Java client from a schema
- Reviewing a schema change as a Java diff
Sample input
GraphQL schema: type Query { …
Sample output
Java: public class Query { …
Who this is for
- Backend developers consuming a GraphQL API
- Anyone porting a schema into a Java service
Frequently asked questions
Why are the fields boxed rather than primitive?
A nullable schema field has no value at all when the server omits it, and a primitive cannot say that. Integer, Double, String and Boolean can hold null, so the Java type matches the schema.
Are interfaces emitted?
Yes, as empty interfaces. Implementing one gives you the marker the schema declares without inventing methods the schema never specified.
What happens to a union?
It is not emitted. Java has no closed union type, so the page would have to guess an inheritance tree; it leaves that decision to you.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.