title: How to convert GraphQL schema to JSON and best to GraphQL schema?
body: <p>I have figured out that this gives me <code>GraphQLSchema</code>, which I expect I can convert to JSON. How?</p>
  
  <pre class="lang-js prettyprint-override"><code>// @flow
  
  import path from 'path';
  import fs from 'fs';
  import {
    buildSchema,
  } from 'graphql';
  
  const main = () =&gt; {
    const schemaPath = path.resolve(__dirname, '../schema.graphql');
  
    console.log(buildSchema(fs.readFileSync(schemaPath, 'UTF8')));
  };
  
  main();
  
  </code></pre>
  
  <p>And how to do the inverse – how to convert JSON representation of GraphQL schema to GraphQL markup?</p>
  
  <p>One way I have found to do it is:</p>
  
  <pre class="lang-js prettyprint-override"><code>import {
    printSchema,
    buildSchema,
    buildClientSchema,
    printIntrospectionSchema,
    introspectionFromSchema,
  } from 'graphql';
  
  printSchema(buildClientSchema(introspectionFromSchema(buildSchema(fs.readFileSync('./schema.graphql', 'UTF8')))))
  
  </code></pre>
  
  <p>However, this looses a lot of data, e.g.</p>
  
  <pre><code>type Venue implements Node @preLoad {
    # test
    id: ID!
    fuid: String!
    url: String!
    name: String!
    cinema: Cinema!
    futureEventCount: Int!
    globalCinemaVenue: GlobalCinemaVenue
  }
  
  </code></pre>
  
  <p>becomes:</p>
  
  <pre><code>type Venue implements Node {
    id: ID!
    fuid: String!
    url: String!
    name: String!
    cinema: Cinema!
    futureEventCount: Int!
    globalCinemaVenue: GlobalCinemaVenue
  }
  
  </code></pre>