Skip to main content

Graphene is a Python library for creating GraphQL schemas/types easly. It maps the models/fields to internal GraphQL objects without effort. Including automatic Django models conversion.

Installation

For instaling graphene, just run this command in your shell

pip install graphene

Usage

Example code of a GraphQL schema using Graphene:

Schema definition

class Character(graphene.Interface):
    id = graphene.IDField()
    name = graphene.StringField()
    friends = graphene.ListField('self')

    def resolve_friends(self, args, *_):
        return [Human(f) for f in self.instance.friends]

class Human(Character):
    homePlanet = graphene.StringField()

class Query(graphene.ObjectType):
    human = graphene.Field(Human)

schema = graphene.Schema(query=Query)

Querying

Querying graphene.Schema is as simple as:

query = '''
    query HeroNameQuery {
      hero {
        name
      }
    }
'''
result = schema.execute(query)

Relay Schema

Graphene also supports Relay, check the Starwars Relay example!

class Ship(relay.Node):
    '''A ship in the Star Wars saga'''
    name = graphene.StringField(description='The name of the ship.')

    @classmethod
    def get_node(cls, id):
        return Ship(getShip(id))


class Query(graphene.ObjectType):
    ships = relay.ConnectionField(Ship, description='The ships used by the faction.')
    node = relay.NodeField()

    @resolve_only_args
    def resolve_ships(self):
        return [Ship(s) for s in getShips()]

Django+Relay Schema

If you want to use graphene with your Django Models check the Starwars Django example!

class Ship(DjangoNode):
    class Meta:
        model = YourDjangoModelHere
        # only_fields = ('id', 'name') # Only map this fields from the model
        # excluxe_fields ('field_to_excluxe', ) # Exclude mapping this fields from the model

class Query(graphene.ObjectType):
    node = relay.NodeField()

Contributing

After cloning this repo, ensure dependencies are installed by running:

python setup.py install

After developing, the full test suite can be evaluated by running:

python setup.py test # Use --pytest-args="-v -s" for verbose mode

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphene-0.1.5.2.tar.gz (19.5 kB view details)

Uploaded Source

File details

Details for the file graphene-0.1.5.2.tar.gz.

File metadata

  • Download URL: graphene-0.1.5.2.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for graphene-0.1.5.2.tar.gz
Algorithm Hash digest
SHA256 5ed2c67ce7deb33ca5beb77382138f9340764a2793945a0413c52211d639d3e8
MD5 211f20d237c9bb138e93164b8cbe395f
BLAKE2b-256 42d9e849896aedf4bcd6277f160be40b2d78a346217d59005d4f50cf2e74b8a1

See more details on using hashes here.

Release history Release notifications | RSS feed

3.4.3

2 files

3.4.2

2 files

3.4.1

2 files

3.4

2 files

3.3

2 files

3.2.2

2 files

3.2.1

2 files

3.2

2 files

3.1.1

2 files

3.1

2 files

3.0

2 files

2.1.9

2 files

2.1.8

2 files

2.1.7

2 files

2.1.6

2 files

2.1.5

2 files

2.1.3

2 files

2.1.2

2 files

2.1.1

2 files

2.1

2 files

2.0.1

2 files

2.0

2 files

1.4.2

1 file

1.4.1

1 file

1.4

1 file

1.3

1 file

1.2

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1

1 file

1.0.2

1 file

1.0.1

1 file

1.0

1 file

0.10.2

1 file

0.10.1

1 file

0.10.0

1 file

0.9.1

1 file

0.9

1 file

0.8.1

1 file

0.8.0

1 file

0.7.3

1 file

0.7.2

1 file

0.7.1

1 file

0.7.0

1 file

0.6.1

1 file

0.6.0

1 file

0.5.0

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1.1

1 file

0.4.1

1 file

0.4.0.1

1 file

0.4.0

1 file

0.3.0

1 file

0.1.6.1

1 file

0.1.6.0

1 file

0.1.6

0.1.5.3

1 file

This release

0.1.5.2 This release

1 file

0.1.5.1

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

0.0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page