API reference

Schema

class django_graph_api.Schema(query_root_classes=None)[source]
__init__(query_root_classes=None)[source]

Creates a schema that supports introspection.

If multiple query root objects are passed in, their fields will be combined into the schema’s root query.

Parameters:query_root_classes – an individual or list of query root objects

Request

class django_graph_api.Request(document, schema, variables=None, operation_name=None)[source]
__init__(document, schema, variables=None, operation_name=None)[source]

Creates a Request object that can be validated and executed.

Parameters:
  • document

    The query string to execute.

    e.g. "query episodeNames { episodes { name } }"

  • schema – A Schema object to run the query against
  • variables – A dict of variables to pass to the query (optional)
  • operation_name – If the document contains multiple named queries, the name of the query to execute (optional)
execute()[source]
Returns:data, errors
validate()[source]

Used to perform validation of a query before execution. Errors produced from validation can be accessed from request.errors.

If a Request object has been validated once, additional calls will not re-run validation.

Types

Non-scalar field types

class django_graph_api.Object(ast, data, fragments, variable_definitions=None, variables=None)[source]

Subclass this to define an object node in a schema.

e.g.

class Character(Object):
    name = CharField()
class django_graph_api.RelatedField(object_type, **kwargs)[source]

Defines a many-to-1 or 1-to-1 related field.

e.g.

class Character(Object):
    name = CharField()
    mother = RelatedField('self')

Can be queried like

...
character {
    mother {
        name
    }
}
...

And would return

...
"character": {
    "mother": {
        "name": "Joyce Summers"
    }
}
...
class django_graph_api.ManyRelatedField(object_type, **kwargs)[source]

Defines a 1-to-many or many-to-many related field.

e.g.

class Character(Object):
    name = CharField()
    friends = RelatedField('self')

Can be queried like

...
character {
    friends {
        name
    }
}
...

And would return

...
"character": {
    "friends": [
        {"name": "Luke Skywalker"},
        {"name": "Han Solo"}
    ]
}
...

Scalar field types

class django_graph_api.BooleanField(description=None, arguments=None, null=True)[source]

Defines a boolean field.

Querying on this field will return a bool or None.

class django_graph_api.CharField(description=None, arguments=None, null=True)[source]

Defines a string field.

Querying on this field will return a str or None.

class django_graph_api.IdField(description=None, arguments=None, null=True)[source]

Defines an id field.

Querying on this field will return a str or None.

class django_graph_api.IntegerField(description=None, arguments=None, null=True)[source]

Defines an integer field.

Querying on this field will return an int or None.

class django_graph_api.FloatField(description=None, arguments=None, null=True)[source]

Defines a float field.

Querying on this field will return a float or None.

Views

class django_graph_api.GraphQLView(**kwargs)[source]

Django view handles Graph API queries.

GET returns the HTML for the GraphiQL API explorer.

POST accepts a JSON body in the form of:

{
    "query": <query>,
    "variables": <variables>
}

and returns a JSON response with a “data” and/or “error” object.