Are there any tools to dynamically generate graphQ

2019-04-10 13:55发布

I will have JSON from a CMS and using the JSON I want to be able to programmatically write a graphQl schema. Without needing to write the string directly.

Are there any JavaScript tools to do this?

I am referring to the string argument to the buildSchema function:

http://graphql.org/code/

2条回答
可以哭但决不认输i
2楼-- · 2019-04-10 14:34

The json-graphql-server project does that: Take a data JSON as input, infer types and fields from the data, write a schema containing types, queries and mutations, and start a GraphQL server schema based on that.

https://github.com/marmelab/json-graphql-server

I know of another tool that does just the JSON to schema part, but it does not generate queries or mutations:

https://github.com/aweary/json-to-graphql

查看更多
等我变得足够好
3楼-- · 2019-04-10 14:50

It depends on how does your JSON files look like. For me I had a similar case - a kind of complex json definition file - and I built my own json to graphql-js converter here

  • After building your server you can generate the schema string in .graphql file using this package gql-tools, using this command - after launching the server - :-

    gqlschema http://localhost:3000/graphql -t

  • Use the schema string along with graphql-server-express from apollo and link it with resolvers

查看更多
登录 后发表回答