GraphQL Server Core

2.0.0 · maintenance · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a basic GraphQL application handler using `create_app`. For a fully functional server, this handler needs to be integrated with a web framework (like Flask, Django, etc.), which, for `graphql-server-core` v2.x, typically required additional framework-specific packages (e.g., `graphql-server-flask`).

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.")

view raw JSON →