FORMAT: 1A HOST: http://farmanimals.apiblueprint.org/
Animals is a simple API allowing consumers to view information about the animals on a farm.
class PropertyResourceProvider implements SwaggerResourcesProvider { | |
// application.yml props get wired into this config | |
@Autowired | |
private SwaggerServicesConfig config | |
@Override | |
List get() { | |
config.services.collect { svc -> | |
new SwaggerResource( | |
name: svc.name, |
# retrieve all keepers names and the names of their animals | |
{ | |
"query":"{ keepers { name animals { name } } }" | |
} | |
# retrieve keeper 1's name and their animals' name and birthdate | |
{ | |
"query":"{ keepers(id: 1) { name animals { name birthdate } } }" | |
} |
graphql | |
|---- controller - exposes /v1/graphql POST endpoint | |
|---- executor - picks apart the request and executes the query against the schema | |
|---- schema - builds up the schema and provides it to the executor | |
|---- datafetcher - wraps calls to the database, external APIs, etc |
schema { | |
query: QueryType | |
} | |
type QueryType { | |
# (id: Long) allows for these fields to be filtered by id | |
animals(id: Long): [Animal] | |
keepers(id : Long) : [Keeper] | |
} |
GraphQLObjectType keeperType = newObject() | |
.name("keeper") // required | |
.description("A Zoo Keeper") // optional | |
.field(newFieldDefinition() | |
.name("id") | |
.description("Keeper ID") | |
.type(GraphQLLong) | |
.build()) | |
.field(newFieldDefinition() | |
.name("name") |
# Keeper | |
{ | |
id: Long, | |
name: String, | |
animals: Animal[] | |
} | |
# Animal | |
{ | |
id: Long, |
FORMAT: 1A HOST: http://farmanimals.apiblueprint.org/
Animals is a simple API allowing consumers to view information about the animals on a farm.