Ariadne
Ariadne is a Python library for implementing GraphQL servers using a schema-first approach. It emphasizes a simple, extensible API for defining GraphQL schemas using Schema Definition Language (SDL) and connecting business logic with minimal boilerplate. It supports queries, mutations, subscriptions, custom scalars, and integrates with ASGI/WSGI frameworks like Django, FastAPI, Flask, and Starlette. The project maintains an active and frequent release cadence, with regular patch, minor, and occasional alpha releases, as seen with versions like 1.0.1 and subsequent 1.1.0a2.
Warnings
- breaking Version 1.0.0 introduced several breaking changes including the removal of deprecated `EnumType.bind_to_default_values`, Apollo tracing, OpenTracing, and `extend_federated_schema`. It also made base handler class names consistent and adjusted `convert_names_case` behavior.
- breaking In version 0.29.0, deprecated utilities `FallbackResolvers` and `convert_kwargs_to_snake_case` were removed, along with legacy code paths for versions prior to 0.20.
- gotcha The `errors` key in GraphQL responses is intended for technical errors (e.g., parsing, validation, execution issues), not for communicating application-level business logic errors (like permission denied or validation failures to end-users).
Install
-
pip install ariadne uvicorn
Imports
- gql
from ariadne import gql
- QueryType
from ariadne import QueryType
- make_executable_schema
from ariadne import make_executable_schema
- start_dev_server
from ariadne import start_dev_server
Quickstart
from ariadne import gql, QueryType, make_executable_schema, start_dev_server
# Define GraphQL schema using Schema Definition Language (SDL)
type_defs = gql("""
type Query {
people: [Person!]!
}
type Person {
firstName: String!
lastName: String!
}
""")
# Create a QueryType instance to define query resolvers
query = QueryType()
# Define the resolver for the 'people' field
@query.field("people")
def resolve_people(*_):
return [
{"firstName": "John", "lastName": "Doe"},
{"firstName": "Jane", "lastName": "Smith"},
]
# Combine type definitions and resolvers into an executable schema
schema = make_executable_schema(type_defs, query)
# Run the development server
if __name__ == "__main__":
# Access the GraphQL endpoint and GraphiQL at http://127.0.0.1:8000
start_dev_server(schema, port=8000)