-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclass.test.js
More file actions
46 lines (41 loc) · 1.2 KB
/
class.test.js
File metadata and controls
46 lines (41 loc) · 1.2 KB
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
// @ts-check
const { makeExecutableSchema } = require('graphql-tools')
const { GraphQLSchema } = require('graphql')
const { constraint } = require('../src/index')
describe('constraint directive class', () => {
it('should provide its own graphql SDL', () => {
const sdl = constraint.getSDL()
expect(sdl).toMatch('directive @constraint')
})
it('should work when used properly in other graphql schema', () => {
const withOtherSchema = `
${constraint.getSDL()}
type Mutation {
signup(
name: String @constraint(maxLength:20)
): Boolean
}
`
const schema = makeExecutableSchema({
typeDefs: withOtherSchema,
schemaDirectives: { constraint }
})
expect(schema).toBeInstanceOf(GraphQLSchema)
})
it('should NOT work when using unknown parameter', () => {
const withOtherSchema = `
${constraint.getSDL()}
type Mutation {
signup(
name: String @constraint(DUMMY:123)
): Boolean
}
`
expect(() =>
makeExecutableSchema({
typeDefs: withOtherSchema,
schemaDirectives: { constraint }
})
).toThrowError('Unknown argument "DUMMY" on directive "@constraint"')
})
})