-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaliased.js
60 lines (52 loc) · 1 KB
/
aliased.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
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { graphql } from 'graphql';
import mergeResolvers from './mergeResolvers';
const schemaString = `
type Query {
user(id: String): User
}
type User {
name: String
kname: String
friends(count: Int): [User]
}
`;
function getSchema() {
return makeExecutableSchema({ typeDefs: schemaString });
}
function log(object) {
console.dir(object, { depth: null });
}
// Simple example with aliased fields in Query mock
let schema = getSchema();
addMockFunctionsToSchema({
schema,
mocks: {
Query: () => ({
user1: () => ({
name: 'User 1'
}),
user2: () => ({
name: 'User 2'
})
})
}
});
graphql(
schema,
`
query {
user1: user(id: "1") {
name
}
user2: user(id: "2") {
name
}
}
`,
{}
).then(result => log(result));
// ->
// { data:
// { user1: { name1: 'Hello World' },
// user2: { name2: 'Hello World' } } }