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
Here's the content of a sample input file(we will call it test.graphql)
type User {
id: ID!
username: String
first_name: String
last_name: String
full_name: String
name: String
name: String
}
Now let's use SchemaGen to generate python code from it.
As a CLI tool:
schemagen parse test.graphql -o test.py
As a Python Package:
from schemagen import SchemaGen
gen = SchemaGen(
input_file='test.graphql',
output_file='test.py'
)
# parse input file
gen()
Output(test.py):
# This file was generated by CodegenTool
from graphene import *
class User(ObjectType):
id = Field(ID, required=True)
username = Field(String)
first_name = Field(String)
last_name = Field(String)
full_name = Field(String)
name = Field(String)
Notes
Here are some things you should know about using SchemaGen:
-
SchemaGen is not guaranteed to catch errors in your GraphQL schema file.
SchemaGen will only catch a very small percentage of errors that might occur in defining a GraphQL schema. It is the developer's responsibility to ensure the GraphQL schema file is error-free.
-
SchemaGen will not install the graphene package on your local machine however it will import it in the generated python file.
You can easily install the package by running:
pip install graphene
-
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 }
I plan to fix the last two issues stated above in the future. Pull requests are welcome!
Metadata
Release files for schemagen 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| schemagen-1.0.5.tar.gz | 39.0 kB | Without provenance | Details for schemagen-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| schemagen-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for schemagen-1.0.5-py3-none-any.whl |
Total release size: 79.7 kB
Release files / schemagen-1.0.5.tar.gz
| Download URL | schemagen-1.0.5.tar.gz |
|---|---|
| Size | 39.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
438a5f9fd5e8798667b43594e9ff9004bcd748ad953dc1eabb70a9cff460d7ea
|
|
BLAKE2b-256 checksum How to use checksums |
ecc2222d5b5acba48aa503868936254101058c14d6d58359582cfd449e09bc73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|
Release files / schemagen-1.0.5-py3-none-any.whl
| Download URL | schemagen-1.0.5-py3-none-any.whl |
|---|---|
| Size | 40.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df4044e86ae51f0bd3e73121e309ce1bbc91d403641a37ba8cf10cb403579180
|
|
BLAKE2b-256 checksum How to use checksums |
606bac349aac023498f52187607b1d8848264db2b5ed0a3122bc41254de9cfa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1
|
Security for schemagen 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.