GraphQL Server Core
graphql-server-core is a Python library that provides the core logic and utilities for building a GraphQL server, compatible with graphql-core. It handles request parsing, execution, and error formatting, acting as a foundation for framework-specific integrations. The current stable version is 2.0.0, but development has largely shifted to its successor, 'graphql-server' (v3.x).
Warnings
- breaking The `graphql-server-core` package (v2.x) has been effectively superseded by `graphql-server` (v3.x). `graphql-server` is a refactored and consolidated library that bundles all framework integrations (Flask, Aiohttp, Sanic, etc.) directly into a single package, simplifying dependencies and usage.
- deprecated This `graphql-server-core` library is considered to be in maintenance mode, with active development having shifted to its successor, `graphql-server` (v3.x). While functional, it may not receive new features or extensive updates.
- gotcha For `graphql-server-core` v2.x, integrating with specific web frameworks (like Flask or Aiohttp) required installing separate companion packages (e.g., `graphql-server-flask`, `graphql-server-aiohttp`). This is unlike `graphql-server` v3.x, where framework integrations are bundled.
- gotcha `graphql-server-core` v2.x specifically depends on `graphql-core>=3.1,<3.2`. Incompatibilities can arise if using other versions of `graphql-core`.
Install
-
pip install graphql-server-core
Imports
- create_app
from graphql_server_core import create_app
- GraphQLResponse
from graphql_server_core import GraphQLResponse
- format_error
from graphql_server_core.errors import format_error
Quickstart
from graphql import build_schema
from graphql_server_core import create_app
def resolve_hello(root, info):
return 'Hello from GraphQL-Server-Core!'
# Define your GraphQL schema
schema = build_schema('''
type Query {
hello: String
}
''')
# Attach a resolver to the 'hello' field
schema.query.set_field('hello', resolve_hello)
# Create a basic GraphQL application handler
# For actual serving, this `app` object would be integrated with a WSGI/ASGI server
# e.g., using Flask or FastAPI, which would require separate packages
app = create_app(
schema=schema,
pretty=True, # Optional: format output nicely
enable_graphiql=False # Optional: disable GraphiQL interface
)
# Example of how to simulate a request (for demonstration, not a full server)
# In a real application, a web framework would handle the request/response cycle.
# This library primarily provides the 'app' handler.
# print("App handler created, integrate with a web framework to serve.")