Graphene: How do you introspect the schema?

Created on 9 Oct 2015  Â·  5Comments  Â·  Source: graphql-python/graphene

I see that the graphiql interface is able to introspect the schema, but I am not sure how you would export the schema form python. I see the introspect function on the Schema object, but that simply returns the objects from the type_map.

Most helpful comment

@ashinohara I've fixed the introspection method in the schema.
Just update your graphene package to 0.1.3 version and run schema.introspect() in your graphene.Schema:

import json

schema = graphene.Schema(....)

introspection_dict = schema.introspect()

# Print the schema in the console
print json.dump(introspection_dict)

# Or save the schema into some file
open('schema.json', ‘w’) as fp:
    json.dump(introspection_dict, fp)

All 5 comments

@ashinohara I've fixed the introspection method in the schema.
Just update your graphene package to 0.1.3 version and run schema.introspect() in your graphene.Schema:

import json

schema = graphene.Schema(....)

introspection_dict = schema.introspect()

# Print the schema in the console
print json.dump(introspection_dict)

# Or save the schema into some file
open('schema.json', ‘w’) as fp:
    json.dump(introspection_dict, fp)

Thanks @jhgg for showing me the way :wink:

No problem!

This should be automatically exposed by Graphene as a query that returns the file.

If you want to get schema in GraphQL SDL format:

>>> from your_project.schema_definition import schema
>>>  print(schema)
schema {
  query: Query
  mutation: Mutation
}

type CreateUser {
  user: User
  message: String
  success: Boolean
}
# and so on ...
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Globegitter picture Globegitter  Â·  4Comments

mraak picture mraak  Â·  3Comments

mingzhou picture mingzhou  Â·  3Comments

jloveric picture jloveric  Â·  4Comments

BossGrand picture BossGrand  Â·  4Comments