Manage Schema For Configuration Version
You can get the graphql schema for a configuration version - draft or published - by using getConfigurationSchema
query. This will return the schema as a JSON string. The returned schema can then be parsed and consumed using standard Graphql libraries.
Get Schema For Specific Version
Below is a sample query to get the schema of a specific version
query GetConfigurationSchema {
getConfigurationSchema(version: 2)
}
Sample response:
{
"data": {
"getConfigurationSchema": "\"interface CurationMetadata {\\n external_id: String\\n sets(limit: Int, next_token: String): SetListing\\n slug: String\\n uid: String!\\n}\\n\\ninterface Entertainment {\\n assets(language: String, limit: Int, next_token: String): AssetListing\\n availability(limit: Int, next_token: String): AvailabilityListing\\n credits(language: String, limit: Int, next_token: String): CreditListing\\n genres(language: String, limit: Int, next_token: String): GenreListing\\n images(language: String, limit: Int, next_token: String): ImageListing\\n ratings(language: String, limit: Int, next_token: String): RatingListing\\n release_date: String\\n synopsis_long: String\\n synopsis: String\\n synopsis_short: String\\n tags(language: String, limit: Int, next_token: String): TagListing\\n themes(language: String, limit: Int, next_token: String): ThemeListing\\n title: String\\n title_long: String\\n title_medium: String\\n title_short: String\\n}....."
}
}
Consume Schema
Below is a sample code to consume the schema
from graphql import build_ast_schema, parse
parsed_result = parse(result)
schema = build_ast_schema(parsed_result)
Use Introspection For Specific Schema Version
You can also use introspection query on the schema of a specific version. Below is an example query to get the fields and their types of Episode object.
query GetConfigurationSchema {
getConfigurationSchema(version: 2, query: "{ __type(name:\"Episode\"){ fields {name type{name kind}}}}")
}
Sample response:
{
"data": {
"getConfigurationSchema": "{\"__type\":{\"fields\":[{\"name\":\"_meta\",\"type\":{\"name\":\"_EpisodeMeta\",\"kind\":\"OBJECT\"}},{\"name\":\"assets\",\"type\":{\"name\":\"AssetListing\",\"kind\":\"OBJECT\"}},{\"name\":\"availability\",\"type\":{\"name\":\"AvailabilityListing\",\"kind\":\"OBJECT\"}},{\"name\":\"brands\",\"type\":{\"name\":\"BrandListing\",\"kind\":\"OBJECT\"}},{\"name\":\"credits\",\"type\":{\"name\":\"CreditListing\",\"kind\":\"OBJECT\"}},{\"name\":\"episode_number\",\"type\":{\"name\":\"Int\",\"kind\":\"SCALAR\"}},{\"name\":\"external_id\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"genres\",\"type\":{\"name\":\"GenreListing\",\"kind\":\"OBJECT\"}},{\"name\":\"images\",\"type\":{\"name\":\"ImageListing\",\"kind\":\"OBJECT\"}},{\"name\":\"ratings\",\"type\":{\"name\":\"RatingListing\",\"kind\":\"OBJECT\"}},{\"name\":\"release_date\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"seasons\",\"type\":{\"name\":\"SeasonListing\",\"kind\":\"OBJECT\"}},{\"name\":\"sets\",\"type\":{\"name\":\"SetListing\",\"kind\":\"OBJECT\"}},{\"name\":\"slug\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"synopsis\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"synopsis\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"synopsis\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"tags\",\"type\":{\"name\":\"TagListing\",\"kind\":\"OBJECT\"}},{\"name\":\"themes\",\"type\":{\"name\":\"ThemeListing\",\"kind\":\"OBJECT\"}},{\"name\":\"title\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"title_long\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"title_medium\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"title_short\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"uid\",\"type\":{\"name\":null,\"kind\":\"NON_NULL\"}},{\"name\":\"episode_type\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}},{\"name\":\"additional_name\",\"type\":{\"name\":\"String\",\"kind\":\"SCALAR\"}}]}}"
}
}
Updated 6 months ago