@@ -518,6 +518,117 @@ public Object executeOperation(@RequestBody Map body) {
518518}
519519```
520520
521+ ### Schema IDL support
522+
523+ This library allows for "schema driven" development of graphql applications.
524+
525+ It allows you to compile a set of schema files into a executable `GraphqlSchema`.
526+
527+
528+ So given a graphql schema input file like :
529+
530+ ```graphql
531+
532+ schema {
533+ query: QueryType
534+ }
535+
536+ type QueryType {
537+ hero(episode: Episode): Character
538+ human(id : String) : Human
539+ droid(id: ID!): Droid
540+ }
541+
542+
543+ enum Episode {
544+ NEWHOPE
545+ EMPIRE
546+ JEDI
547+ }
548+
549+ interface Character {
550+ id: ID!
551+ name: String!
552+ friends: [Character]
553+ appearsIn: [Episode]!
554+ }
555+
556+ type Human implements Character {
557+ id: ID!
558+ name: String!
559+ friends: [Character]
560+ appearsIn: [Episode]!
561+ homePlanet: String
562+ }
563+
564+ type Droid implements Character {
565+ id: ID!
566+ name: String!
567+ friends: [Character]
568+ appearsIn: [Episode]!
569+ primaryFunction: String
570+ }
571+
572+
573+ ```
574+
575+ You could compile and generate an executable schema via
576+
577+ ```java
578+ SchemaCompiler schemaCompiler = new SchemaCompiler();
579+ SchemaGenerator schemaGenerator = new SchemaGenerator();
580+
581+ File schemaFile = loadSchema("starWarsSchema.graphqls");
582+
583+ TypeDefinitionRegistry typeRegistry = schemaCompiler.compile(schemaFile);
584+ RuntimeWiring wiring = buildRuntimeWiring();
585+ GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeRegistry, wiring);
586+
587+ ```
588+
589+ The static schema definition file has the field and type definitions but you need a runtime wiring to make
590+ it a truly executable schema.
591+
592+ The runtime wiring contains `DataFetchers`, `TypeResolvers` and custom `Scalars` that are needed to make a fully
593+ executable schema.
594+
595+ You wire this together using this builder pattern
596+
597+ ```java
598+
599+ RuntimeWiring buildRuntimeWiring() {
600+ return RuntimeWiring.newRuntimeWiring()
601+ .scalar(CustomScalar)
602+ // this uses builder function lambda syntax
603+ .type(typeWiring -> typeWiring.typeName("QueryType")
604+ .dataFetcher("hero", new StaticDataFetcher(StarWarsData.getArtoo()))
605+ .dataFetcher("human", StarWarsData.getHumanDataFetcher())
606+ .dataFetcher("droid", StarWarsData.getDroidDataFetcher())
607+ )
608+ .type(typeWiring -> typeWiring.typeName("Human")
609+ .dataFetcher("friends", StarWarsData.getFriendsDataFetcher())
610+ )
611+ // you can use builder syntax if you don' t like the lambda syntax
612+ .type(typeWiring - > typeWiring. typeName(" Droid" )
613+ .dataFetcher(" friends" , StarWarsData . getFriendsDataFetcher())
614+ )
615+ // or full builder syntax if that takes your fancy
616+ .type(
617+ newTypeWiring(" Character" )
618+ .typeResolver(StarWarsData . getCharacterTypeResolver())
619+ .build()
620+ )
621+ .build();
622+ }
623+
624+
625+ ```
626+
627+ NOTE : IDL is not currently part of the [formal graphql spec](https: // facebook.github.io/graphql/#sec-Appendix-Grammar-Summary.Query-Document).
628+ The implementation in this library is based off the [reference implementation](https: // github.com/graphql/graphql-js). However plenty of
629+ code out there is based on this IDL syntax and hence you can be fairly confident that you are building on solid technology ground.
630+
631+
521632#### Contributions
522633
523634Every contribution to make this project better is welcome: Thank you!
0 commit comments