SchemaGenerator { public String generate() { final StringBuilder sb = new StringBuilder(); this.j.types() .filter(t -> !t.typeName().startsWith("__")) .forEach(nt -> { switch (nt.logicalKind()) { case OUTPUT: this.generate((ExecutableOutputType) nt, sb); break; case SCALAR: this.generate((ExecutableScalarType) nt, sb); break; case ENUM: this.generate((ExecutableEnumType) nt, sb); break; case INPUT: case INTERFACE: case UNION: default: break; } }); if (!this.j.operationTypes().isEmpty()) { sb.append("schema {\n"); this.j.operationTypes() .forEach((op, type) -> { sb.append(" "); sb.append(op); sb.append(": "); sb.append(type.typeName()); sb.append("\n"); }); sb.append("}\n\n"); } return sb.toString(); } SchemaGenerator(final ExecutableSchema j); String generate();  }
@Test public void test() { ExecutableSchemaBuilder j = new ExecutableSchemaBuilder(); j.setRootType(GQLOpType.Mutation, MutationRoot.class); j.extensionGenerator(new ExtensionGenerator() { @Override public Stream<JavaOutputField> generateExtensions(TypeToken<?> type) { if (!type.equals(TypeToken.of(MutationRoot.class))) { return Stream.empty(); } return Stream.of(new JavaOutputField() { @Override public TypeToken<?> returnType() { return TypeToken.of(String.class); } @Override public <T, C, V> T invoke(V request, C context, Object... args) { return (T) "boo"; } @Override public String fieldName() { return "xyz"; } }); } }); ExecutableSchema schema = j.build(); System.err.println(new SchemaGenerator(schema).generate()); String res = schema.rootType(GQLOpType.Query) .get() .field("hello") .get() .invoke(null, new QueryRoot()); assertEquals("hey there", res); assertEquals("boo", schema.rootType(GQLOpType.Mutation) .get() .field("xyz") .get() .invoke(null, new MutationRoot()) ); }