Closed graphan closed 7 years ago
Is it possible to get the schema for Apollo from .gql files?
Yes, you can split your schema files into multiple files and then generate full schema for apollo.
# comment.gql
type Comment {
id: Int!
message: String
}
# post.gql
type Post {
id: Int!
title: String
comments: [Comment]
}
# main.gql
type Query {
post(id: Int!): Post
}
schema {
query: Query
}
// .gqlconfig
{
schema: {
files: 'folder_containing_files/**/*.gql'
}
}
// generateSchema.js: this will generate full schema merging all small files
import generate from '@playlyfe/gql/lib/tools/generate';
generate({
configOptions: { cwd: path.resolve('path_to_folder_containing_gqlconfig') },
targets: [{ type: 'schemaGQL' }],
callback(err, result) {
if (err) {
console.error(err);
process.exit(1);
}
const [schemaGQL] = result;
fs.writeFileSync('./data/schema.js', `
export default \`${schemaGQL}\`;
`);
console.log('schema file generated');
},
});
// apollo makeExecutableSchema file
import Schema from './data/schema.js';
import Resolvers from './data/resolvers';
const executableSchema = makeExecutableSchema({
typeDefs: Schema,
resolvers: Resolvers,
});
@graphan Is your problem fixed. Can I close this issue?
Hi, interesting thing man!
I have a question if it is compatible with Apollo? I get used to creating a schema like this: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing
Is it possible to get the schema for Apollo from .gql files?
It would be awesome to do so and thanks to this the use of this plugin will be widespread.