Last active
April 3, 2019 14:19
-
-
Save pmn4/5a40dcc11ca636aa70df411769d54e7b to your computer and use it in GitHub Desktop.
Copy/Paste/Execute in your Node REPL (or `meteor shell`) to create a method for converting an instance of `SimpleSchema` to a Graph QL Schema definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .editor | |
| var os = require("os"); | |
| function schemaToGraphQl(schema) { | |
| const definitions = Object.keys(schema._schema).map((name) => { | |
| const s = schema._schema[name]; | |
| return [ | |
| s.label && ` "${s.label}"`, | |
| ` ${name}: ${s.type.definitions[0].type.name}` // brittle | |
| ].filter(s => s).join(os.EOL) | |
| }); | |
| console.log(`"auto-generated GraphQL schema (replace with a proper description)"`); | |
| console.log("type YourSchema implements Node {"); | |
| console.log(definitions.join(os.EOL.repeat(2))); | |
| console.log("}"); | |
| return "if running Meteor/Reaction, check the terminal window where your server is running for the output" | |
| }; | |
| `generate GraphQL schema with: ${schemaToGraphQl.name}(YourSchema)` | |
| // ^D to execute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment