I am new to Relay and am trying to put together my first app. I already have a GraphQL server (using Graphene) that is backed by a PostgreSQL DB via SQLAlchemy automap, and published as a Flask app. Now, I'm trying to put together the front end, and it looks like the relay-compiler is expecting a GraphQL schema file on the client-side. I'm wondering if there is a way to have this schema file be dynamically auto generated, and how that could be set up.
I'm using https://github.com/kriasoft/react-static-boilerplate as the starting point for my app.
Thanks.
After browsing around the Graphene codebase I found schema_printer in the utils module of graphql-python that gets the job done for me:
import json
from schema import schema
import sys
from graphql.utils import schema_printer
my_schema_str = schema_printer.print_schema(schema)
fp = open("schema.graphql", "w")
fp.write(my_schema_str)
fp.close()
For me, https://docs.graphene-python.org/projects/django/en/latest/introspection/ was helpful. In my case schema was defined in the schema.py file of apiApp, and so the command to retrieve schema.json was as following.
./manage.py graphql_schema --schema apiApp.schema.schema --out schema.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With