title: Generate a json schema without starting a server?
body: <p>Is there a standalone tool to convert a modularized graphql schema to a json schema?</p>
  
  <p>I have a graphql server using apollo-graphql and graphql-tools <code>makeExecutableSchema</code>. It follows the pattern described <a href="http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing" rel="nofollow noreferrer">here</a></p>
  
  <pre class="lang-js prettyprint-override"><code>// schema.js
  import { makeExecutableSchema } form 'graphql-tools';
  const Author = `type Author { ... }`;
  const Post   = `type Post   { ... }`;
  const Query  = `type Query  { ... }`;
  
  export const typeDefs = [Author, Post, Query];
  
  export const schema = makeExecutableSchema({
    typeDefs: typeDefs,
    resolvers: { ... },
  });
  </code></pre>
  
  <p>How can I create a <code>schema.json</code> form either <code>typeDefs</code> or <code>schema</code>?</p>
  
  <hr>
  
  <p>I need a json schema to use <code>relay-compiler</code> or <code>apollo-codegen</code>. <code>apollo-codegen</code> includes this script to create a schema from a graphql server...</p>
  
  <pre><code>apollo-codegen introspect-schema http://localhost:8080/graphql --output schema.json
  </code></pre>
  
  <p>...but I want to create the schema, and run apollo-codegen, in an automated build. I don't want to create a server.</p>
  
  <hr>
  
  <blockquote>
    <p>I would submit this as an answer, but the question has been marked off-topic ¯\_(ツ)_/¯</p>
  </blockquote>
  
  <p>The answer from @daniel-rearden pointed me in the correct direction. <code>makeExecutableSchema</code> returns a <code>GraphQLSchema</code> so one can use <code>graphql</code>'s <code>printSchema</code> and <code>introspectionQuery</code> to get json or graphql language representations of the schema.</p>
  
  <pre class="lang-js prettyprint-override"><code>// export.js
  import { schema } from './schema.js'
  import { graphql, introspectionQuery, printSchema } from 'graphql';
  
  // Save json schema
  graphql(schema, introspectionQuery).then(result =&gt; {
    fs.writeFileSync(
      `${yourSchemaPath}.json`,
      JSON.stringify(result, null, 2)
    );
  });
  
  // Save user readable type system shorthand of schema
  fs.writeFileSync(
    `${yourSchemaPath}.graphql`,
    printSchema(schema)
  );
  </code></pre>