Skip to content

Commit 11bc529

Browse files
committed
#402 - put a next version README in place
1 parent a981a10 commit 11bc529

3 files changed

Lines changed: 817 additions & 129 deletions

File tree

README.md

Lines changed: 20 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,25 @@ GraphQLInterfaceType comicCharacter = newInterface()
189189

190190
##### Creating a new Union Type
191191

192-
Example:
193-
Example:
192+
Example: (a snippet from [here](src/test/groovy/graphql/GarfieldSchema.java))
194193
```java
195194
GraphQLUnionType PetType = newUnionType()
196-
.name("Pet")
197-
.possibleType(CatType)
198-
.possibleType(DogType)
199-
.typeResolver(new TypeResolver() {
200-
@Override
201-
public GraphQLObjectType getType(TypeResolutionEnvironment env) {
202-
if (env.getObject() instanceof Cat) {
203-
return CatType;
204-
}
205-
if (env.getObject() instanceof Dog) {
206-
return DogType;
207-
}
208-
return null;
195+
.name("Pet")
196+
.possibleType(CatType)
197+
.possibleType(DogType)
198+
.typeResolver(new TypeResolver() {
199+
@Override
200+
public GraphQLObjectType getType(Object object) {
201+
if (object instanceof Cat) {
202+
return CatType;
209203
}
210-
})
211-
.build();
204+
if (object instanceof Dog) {
205+
return DogType;
206+
}
207+
return null;
208+
}
209+
})
210+
.build();
212211

213212
```
214213

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

739627
### Details
740628

741-
The implementation is in Java 6, but the tests are in Groovy and [Spock](https://github.com/spockframework/spock).
629+
The implementation is in Java 8, but the tests are in Groovy and [Spock](https://github.com/spockframework/spock).
742630

743631
The query parsing is done with [ANTLR](http://www.antlr.org). The grammar is [here](src/main/antlr/Graphql.g4).
744632

745633
The only runtime dependencies are ANTLR and Slf4J.
634+
635+
This readme shows information on the latest released version of the library. The 'master' branch however contains the
636+
code for the upcoming version. The readme for that upcoming version can be found [here](src/test/groovy/readme/README.next.md)
746637

747638
### Acknowledgment
748639

0 commit comments

Comments
 (0)