Schema#

Cannula levelages schema first design to generate schema. This allows your schema to have maximum portability and also is very easy to read and document.

Schema Utilities#

cannula.schema.assert_has_query_and_mutation(ast)#

Assert that schema has query and mutation types defined.

The schema is pretty much useless without them and rather than causing an error we’ll just add in an empty one so they can be extended.

Return type:

DocumentNode

cannula.schema.build_and_extend_schema(type_defs)#

Build and Extend Schema

When splitting schema into multiple files it is helpful to be able to extend an existing type. This is most commonly done with the Query and Mutation types.

For example in one schema file you add a Query type:

type Book {
    name: String
}

type Query {
    books: [Books]
}

Now in another schema file you can extend the Query:

type Movie {
    name: String
}

extend type Query {
    movies: [Movie]
}
Parameters:

type_defs (Iterable[Union[str, DocumentNode]]) – list of schema or document nodes

Return type:

GraphQLSchema

cannula.schema.load_schema(directory)#

Load Schema

This utility will load schema from a directory or a single pathlib.Path

Parameters:

directory (Union[str, Path]) – Directory to load schema files from

Return type:

List[DocumentNode]