Example #1
0
def print_schema(schema: BaseSchema) -> str:
    graphql_core_schema = schema._schema  # type: ignore

    directives = filter(lambda n: not is_specified_directive(n),
                        graphql_core_schema.directives)
    type_map = graphql_core_schema.type_map

    types = filter(is_defined_type, map(type_map.get,
                                        sorted(type_map)))  # type: ignore

    return "\n\n".join(
        chain(
            filter(None, [print_schema_definition(graphql_core_schema)]),
            (print_directive(directive) for directive in directives),
            (_print_type(type_, schema) for type_ in types),  # type: ignore
        ))
Example #2
0
def print_filtered_schema(
    schema: GraphQLSchema,
    directive_filter: Callable[[GraphQLDirective], bool],
    type_filter: Callable[[GraphQLNamedType], bool],
) -> str:
    directives = filter(directive_filter, schema.directives)
    type_map = schema.type_map

    types = filter(type_filter, map(type_map.get, sorted(type_map)))  # type: ignore

    return "\n\n".join(
        chain(
            filter(None, [print_schema_definition(schema)]),
            (print_directive(directive) for directive in directives),
            (print_type(type_) for type_ in types),  # type: ignore
        )
    )