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