Skip to content

Instantly share code, notes, and snippets.

@pmn4
Last active April 3, 2019 14:19
Show Gist options
  • Select an option

  • Save pmn4/5a40dcc11ca636aa70df411769d54e7b to your computer and use it in GitHub Desktop.

Select an option

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
.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