A Command line tool for generating Python GraphQL implementations(with Graphene) from GraphQL schema files
Project description
SchemaGen
Schema Gen is a simple CLI tool that generates Python GraphQL implementations(using Graphene) from a Graphql Schema file.
Installation
pip install schemagen
Usage
As a CLI tool:
schemagen parse test.graphql -o test.py
As a Python Package:
from schema_gen import SDLParser
sdl_parser = SDLParser(
input_file='test.graphql',
output_file='test.py'
)
# parse input file
sdl_parser()
Notes
SchemaGen is currently in its first version so there are some things you need to know:
-
GraphQL type declarations in your schema file must be ordered.
Because of the way Python and SchemaGen works, you cannot use a GraphQL type before declaring it. For example, the following graphql schema definition would be invalid because we are using the Url scalar in our User type before declaring it:
type User { id: ID! username: String avatar_url: Url } scalar Url
The correct version of the above code is:
scalar Url type User { id: ID! username: String avatar_url: Url }
-
Using a GraphQL SDL keyword as an object field name in your schema will throw an error.
For example, doing this:
enum UserType { Example } type User{ name: String type: UserType }
will throw an error.
Do this instead:
enum UserType { Example } type User{ name: String user_type: UserType }
We plan to fix these issues in the future. Pull requests are welcome!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for schemagen-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc94e31d6197df3ce743277b55c9d706d7cc946f7f2ce22424fb4773d26f24b9 |
|
MD5 | 4ac3603acb76e90734c1f8f66e6c4f16 |
|
BLAKE2b-256 | 93b10199c34350aae0d4a907e2c4ed1533477fd3ef738727f708831e1f7a82fb |