-
Notifications
You must be signed in to change notification settings - Fork 33
/
get-directives.spec.ts
83 lines (70 loc) · 2.69 KB
/
get-directives.spec.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { GraphQLSchema } from 'graphql';
import { makeExecutableSchema } from '@graphql-toolkit/schema';
import { getDirectives } from '../src';
describe('getDirectives', () => {
it('should return the correct directives map when no directives specified', () => {
const typeDefs = `
type Query {
test: String
}
`;
const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;
const directivesMap = getDirectives(schema, schema.getQueryType());
expect(directivesMap).toEqual({});
});
it('should return the correct directives map when built-in directive specified over FIELD_DEFINITION', () => {
const typeDefs = `
type Query {
test: String @deprecated
}
`;
const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;
const directivesMap = getDirectives(schema, schema.getQueryType().getFields()['test']);
expect(directivesMap).toEqual({
deprecated: {
reason: 'No longer supported',
},
});
});
it('should return the correct directives map when using custom directive without arguments', () => {
const typeDefs = `
type Query {
test: String @mydir
}
directive @mydir on FIELD_DEFINITION
`;
const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;
const directivesMap = getDirectives(schema, schema.getQueryType().getFields()['test']);
expect(directivesMap).toEqual({
mydir: {},
});
});
it('should return the correct directives map when using custom directive with optional argument', () => {
const typeDefs = `
type Query {
test: String @mydir(f1: "test")
}
directive @mydir(f1: String) on FIELD_DEFINITION
`;
const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;
const directivesMap = getDirectives(schema, schema.getQueryType().getFields()['test']);
expect(directivesMap).toEqual({
mydir: {
f1: 'test',
},
});
});
it('should return the correct directives map when using custom directive with optional argument an no value', () => {
const typeDefs = `
type Query {
test: String @mydir
}
directive @mydir(f1: String) on FIELD_DEFINITION
`;
const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;
const directivesMap = getDirectives(schema, schema.getQueryType().getFields()['test']);
expect(directivesMap).toEqual({
mydir: {},
});
});
});