GraphQL-core

3.2.8 · active · verified Sat Mar 28

GraphQL-core 3 is a Python port of GraphQL.js, the JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook. It provides a faithful and up-to-date implementation of the GraphQL specification for current Python versions, including schema definition, parsing, validation, and execution. The library maintains an active release cadence, issuing stable patch releases alongside ongoing alpha development for future major versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple GraphQL schema with a 'hello' field that resolves to 'world', and then execute a query against it using `graphql_sync`.

from graphql import (
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLField,
    GraphQLString,
    graphql_sync
)

# 1. Define your GraphQL schema
schema = GraphQLSchema(
    query=GraphQLObjectType(
        name='RootQueryType',
        fields={
            'hello': GraphQLField(
                GraphQLString,
                resolve=lambda obj, info: 'world'
            )
        }
    )
)

# 2. Define a GraphQL query
source = '{ hello }'

# 3. Execute the query synchronously
result = graphql_sync(schema, source)

# 4. Print the result
print(result.data['hello']) # Expected: world

view raw JSON →