-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
45 lines (38 loc) · 943 Bytes
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { resolvers } from './resolvers';
import { makeExecutableSchema } from 'graphql-tools';
import * as fs from 'fs';
import * as path from 'path';
import { mergeStrings } from 'gql-merge';
// const typeDefs = `
// type Query {
// hello: String
// user(id: Int): User
// }
// type Mutation {
// createUser(name: String!, age: Int!): User!
// }
// type User {
// id: Int!
// firstName: String!
// lastName: String!
// posts: [Post]
// }
// type Post {
// id: Int!
// title: String!
// text: String!
// author: User!
// }
// schema {
// query: Query
// mutation: Mutation
// }
// `;
const typesDir = path.resolve(__dirname, 'schema');
const typeFiles = fs.readdirSync(typesDir);
const types = typeFiles.map(file => fs.readFileSync(path.join(typesDir, file), 'utf-8'));
const typeDefs = mergeStrings(types);
export const schema = makeExecutableSchema({
typeDefs,
resolvers
});