2017-10-18 55 views
0

我是Relay的新手,正在嘗試將我的第一個應用放在一起。我已經有了一個GraphQL服務器(使用Graphene),它由PostgreSQL數據庫通過SQLAlchemy自動映射支持,並作爲Flask應用程序發佈。現在,我試圖將前端放在一起,它看起來像relay-compiler期望客戶端上的GraphQL架構文件。我想知道是否有辦法讓這個模式文件被動態地自動生成,以及如何設置它。自動生成用於中繼的Graphql模式(Graphene服務器)

我使用https://github.com/kriasoft/react-static-boilerplate作爲我的應用程序的起點。

謝謝。

回答

0

圍繞石墨烯的代碼庫瀏覽後,我發現graphql-蟒utils的模塊中schema_printer是得到對我所做的工作:

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()