forked from clayallsopp/graphqlhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphqlhub.js
67 lines (60 loc) · 1.55 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
56
57
58
59
60
61
62
63
64
65
66
67
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} from 'graphql';
import * as HN from './hn';
import * as HN2 from './hn2';
import * as REDDIT from './reddit';
import * as KEYVALUE from './keyvalue';
import * as GITHUB from './github';
import * as TWITTER from './twitter';
import * as GIPHY from './giphy';
let schemas = {
hn : HN,
hn2 : HN2,
reddit : REDDIT,
keyValue : KEYVALUE,
github : GITHUB,
twitter: TWITTER,
giphy: GIPHY,
};
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];
let mutations = Mutations;
if (mutations) {
Object.keys(mutations).forEach((mutationName) => {
let fixedName = `${schemaName}_${mutationName}`;
MUTATION_FIELDS[fixedName] = mutations[mutationName];
});
}
FIELDS[schemaName] = {
type : schemas[schemaName].QueryObjectType,
resolve() {
return {};
}
};
});
let queryObjectType = new GraphQLObjectType({
name : 'GraphQLHubAPI',
description : 'APIs exposed as GraphQL',
fields : () => FIELDS,
});
let mutationsType = new GraphQLObjectType({
name : 'GraphQLHubMutationAPI',
description : 'APIs exposed as GraphQL mutations',
fields : () => MUTATION_FIELDS,
});
export const QueryObjectType = queryObjectType;
export const MutationsType = mutationsType;