forked from clayallsopp/graphqlhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphqlhub.js
55 lines (50 loc) · 1.35 KB
/
graphqlhub.js
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
46
47
48
49
50
51
52
53
54
55
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} from 'graphql';
import { Schema as HN } from './hn';
import { Schema as REDDIT } from './reddit';
import { Schema as KEYVALUE } from './keyvalue';
import { Schema as GITHUB } from './github';
import { Schema as TWITTER } from './twitter';
let schemas = {
hn : HN,
reddit : REDDIT,
keyValue : KEYVALUE,
github : GITHUB,
twitter: TWITTER
};
let FIELDS = {
graphQLHub : {
type : GraphQLString,
description : 'About GraphQLHub',
resolve() {
return 'Use GraphQLHub to explore popular APIs with GraphQL! Created by Clay Allsopp @clayallsopp'
}
}
};
let MUTATION_FIELDS = {};
Object.keys(schemas).forEach((schemaName) => {
let { mutations } = schemas[schemaName];
if (mutations) {
Object.keys(mutations).forEach((mutationName) => {
let fixedName = `${schemaName}_${mutationName}`;
MUTATION_FIELDS[fixedName] = mutations[mutationName];
});
}
FIELDS[schemaName] = schemas[schemaName].query;
});
export let Schema = new GraphQLSchema({
query: new GraphQLObjectType({
name : 'GraphQLHubAPI',
description : 'APIs exposed as GraphQL',
fields : () => FIELDS,
}),
mutation: new GraphQLObjectType({
name : 'GraphQLHubMutationAPI',
description : 'APIs exposed as GraphQL mutations',
fields : () => MUTATION_FIELDS,
}),
});