モジュール化されたgraphqlスキーマをjsonスキーマに変換するためのスタンドアロンツールはありますか?サーバーを起動せずにjsonスキーマを生成しますか?
私は、apollo-graphqlとgraphql-tools makeExecutableSchema
を使用しているgraphqlサーバーを持っています。パターンがhere
// 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: { ... },
});
どのように私はschema.json
フォームtypeDefs
またはschema
のいずれかを作成することができますを説明し、次の?
私はrelay-compiler
かapollo-codegen
を使用するJSONスキーマを必要としています。 apollo-codegen
は... graphqlサーバーからスキーマを作成するには、このスクリプトを含んで
apollo-codegen introspect-schema http://localhost:8080/graphql --output schema.json
...しかし、私は、スキーマを作成し、自動ビルドでは、アポロ・コード生成を実行したいです。私はサーバーを作りたくありません。
私は答えとしてこれを提出するだろうが、質問がオフトピック¯マークされている\ _(ツ)_ /¯
ダニエル・rearden @からの答えは私を指摘正しい方向に。 makeExecutableSchema
はGraphQLSchema
を返します。graphql
のprintSchema
とintrospectionQuery
を使用して、スキーマのjsonまたはgraphql言語表現を取得できます。
// export.js
import { schema } from './schema.js'
import { graphql, introspectionQuery, printSchema } from 'graphql';
// Save json schema
graphql(schema, introspectionQuery).then(result => {
fs.writeFileSync(
`${yourSchemaPath}.json`,
JSON.stringify(result, null, 2)
);
});
// Save user readable type system shorthand of schema
fs.writeFileSync(
`${yourSchemaPath}.graphql`,
printSchema(schema)
);
'makeExecutableSchema'はGraphQLSchemaを返します。 [relays docs](https://facebook.github.io/relay/docs/guides-babel-plugin.html#schema-json)の例を参考にしてください。 – everett1992