CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ariadne

Ariadne is a Python library for implementing GraphQL servers using a schema-first approach.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

core-schema.mddocs/

Core Schema Creation

Essential functionality for creating executable GraphQL schemas from type definitions and binding Python logic to schema elements. This is the foundation of Ariadne's schema-first approach.

Capabilities

Schema Creation

Creates a GraphQLSchema instance from SDL type definitions and bindable objects that provide Python logic for the schema.

def make_executable_schema(
    type_defs: Union[str, list[str]],
    *bindables: Union[SchemaBindable, type[Enum], list[Union[SchemaBindable, type[Enum]]]],
    directives: Optional[dict[str, type[SchemaDirectiveVisitor]]] = None,
    convert_names_case: Union[bool, SchemaNameConverter] = False,
) -> GraphQLSchema:
    """
    Create a GraphQLSchema instance that can be used to execute queries.

    Parameters:
    - type_defs: SDL string or list of SDL strings defining GraphQL schema
    - bindables: Instances of schema bindables (ObjectType, ScalarType, etc.)
    - directives: Dict mapping directive names to SchemaDirectiveVisitor classes
    - convert_names_case: Enable automatic case conversion between camelCase and snake_case

    Returns:
    GraphQLSchema instance with Python logic bound to schema elements
    """

Schema Loading

Loads GraphQL schema definitions from .graphql files on disk.

def load_schema_from_path(path: str) -> str:
    """
    Load GraphQL schema from .graphql, .gql, or .graphqls files.

    Parameters:
    - path: Path to file or directory containing GraphQL schema files

    Returns:
    Combined SDL string from all loaded schema files
    """

Schema Validation

Helper function that provides GraphQL syntax validation and improved error messages.

def gql(string: str) -> str:
    """
    Validate GraphQL SDL string and provide enhanced error messages.

    Parameters:
    - string: GraphQL SDL string to validate

    Returns:
    The same SDL string if validation passes

    Raises:
    GraphQLSyntaxError: If SDL contains syntax errors
    """

Name Conversion

Utilities for converting field names between camelCase (GraphQL convention) and snake_case (Python convention).

class SchemaNameConverter:
    """Base class for schema name conversion strategies."""
    def convert_schema_names(self, schema: GraphQLSchema) -> GraphQLSchema: ...

def convert_schema_names(
    schema: GraphQLSchema,
    name_converter: SchemaNameConverter
) -> GraphQLSchema:
    """
    Apply name conversion to existing schema.

    Parameters:
    - schema: GraphQL schema to convert
    - name_converter: Strategy for name conversion

    Returns:
    New schema with converted names
    """

def convert_camel_case_to_snake(name: str) -> str:
    """Convert camelCase string to snake_case."""

def convert_kwargs_to_snake_case(func: Callable) -> Callable:
    """Decorator that converts camelCase kwargs to snake_case."""

def type_implements_interface(
    graphql_type: GraphQLObjectType,
    interface: GraphQLInterfaceType
) -> bool:
    """Check if GraphQL object type implements specific interface."""

Enum Default Values

Utilities for handling enum default values in GraphQL schemas.

def repair_schema_default_enum_values(schema: GraphQLSchema) -> GraphQLSchema:
    """
    Repair enum default values in schema to ensure GraphQL compliance.

    Parameters:
    - schema: GraphQL schema to repair

    Returns:
    Schema with corrected enum default values
    """

def validate_schema_default_enum_values(schema: GraphQLSchema) -> None:
    """
    Validate that enum default values in schema are valid.

    Parameters:
    - schema: GraphQL schema to validate

    Raises:
    ValueError: If invalid enum default values are found
    """

Usage Examples

Basic Schema Creation

from ariadne import gql, make_executable_schema, ObjectType

# Define schema using SDL
type_defs = gql("""
    type Query {
        hello: String!
        user(id: ID!): User
    }
    
    type User {
        id: ID!
        name: String!
        email: String!
    }
""")

# Create bindables
query = ObjectType("Query")

@query.field("hello")
def resolve_hello(*_):
    return "Hello, World!"

@query.field("user")
def resolve_user(_, info, id):
    return {"id": id, "name": "John Doe", "email": "john@example.com"}

# Create executable schema
schema = make_executable_schema(type_defs, query)

Loading Schema from Files

from ariadne import load_schema_from_path, make_executable_schema

# Load schema from .graphql files
type_defs = load_schema_from_path("./schema/")

# Create schema with loaded definitions
schema = make_executable_schema(type_defs, query, user_type)

Automatic Case Conversion

from ariadne import make_executable_schema, SnakeCaseFallbackResolversSetter

# Enable automatic camelCase to snake_case conversion
schema = make_executable_schema(
    type_defs,
    query,
    convert_names_case=True  # or pass custom SchemaNameConverter
)

# Using snake_case fallback resolvers
schema = make_executable_schema(
    type_defs,
    query,
    SnakeCaseFallbackResolversSetter()
)

Install with Tessl CLI

npx tessl i tessl/pypi-ariadne

docs

asgi.md

core-schema.md

error-handling.md

execution.md

explorer.md

federation.md

file-uploads.md

index.md

relay.md

resolvers.md

type-bindables.md

validation.md

tile.json