Open FrontMage opened 6 years ago
I don't think this library has built-in support for exporting GraphQL schema files, but you definitely don't need to write your schema twice. There are tools that can generate schemas from running servers or from JSON introspection results. So for example, if you install graphql-cli, you can run graphql init
, give it a project name and the endpoint for your server, then run graphql get-schema
to get a GraphQL schema language file for your server.
@ccbrown Thanks for the advice. But the graphql-cli
is using __Type
to query schemas.
Query err=Unknown type "__Type".
Query err=Unknown type "__InputValue".
Query err=Unknown type "__Type".
Apparently this lib does not implement these by default. I'm thinking a __Type
field for the query and then use reflect
to return types.
I'd also like this. At the moment, you have to fire up a server and run a tool such as graphql-cli
or (more conveniently) get-graphql-schema
to get the schema printed, which is awkward.
Interestingly, this repo does have a parser that parses a schema grammar into an AST, which can then be printed. But there's no way to print a schema that's expressed as Go types.
You can get the schema with a standard introspection query such as this by running it through graphql.Do()
, but the results are, of course, JSON, not GraphQL's grammar.
I've found a way to print the schema
import { buildASTSchema, printSchema } from 'graphql';
import gql from 'gql-tag';
const typeDefs = gql`
type Query {
hello: String
}
`;
const schema = buildASTSchema(typeDefs);
const printedSchema = printSchema(buildASTSchema);
console.log(printedSchema);
This process can combine the utilities makeExecutableSchema
, mergeTypeDefs
, stitchSchemas
, etc. from 'graphql-tools' to print your stiched schemas.
Wonder if there is a way to export schemas or just have to write it twice.