-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
109 lines (104 loc) · 2.23 KB
/
test.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { buildSchema } from 'graphql';
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { jsonSchemaFromGraphQlType } from './mod.js';
test('test1', () => {
const schema = buildSchema(`
type Query {
campaign: Campaign
}
type Campaign {
created_at: DateTime!
description: String
end: DateTime
id: ID!
locale: String
localizations(
sort: String
limit: Int
start: Int
where: JSON
): [Campaign]
name: String
start: DateTime
updated_at: DateTime!
}
scalar DateTime
scalar JSON
`);
const expected = {
type: 'object',
properties: {
campaign: {
type: 'string',
title: 'campaign',
},
__typename: {
const: 'Query',
title: '__typename',
},
},
required: [],
$defs: {
Campaign: {
type: 'object',
properties: {
created_at: {
title: 'created_at',
},
description: {
type: 'string',
title: 'description',
},
end: {
title: 'end',
},
id: {
type: 'string',
title: 'id',
},
locale: {
type: 'string',
title: 'locale',
},
localizations: {
type: 'array',
items: {
oneOf: [
{
type: 'null',
title: 'Null',
},
{
type: 'string',
title: 'Campaign_id',
},
],
},
title: 'localizations',
},
name: {
type: 'string',
title: 'name',
},
start: {
title: 'start',
},
updated_at: {
title: 'updated_at',
},
__typename: {
const: 'Campaign',
title: '__typename',
},
},
required: [
'created_at',
'id',
'updated_at',
],
},
},
};
assert.deepEqual(jsonSchemaFromGraphQlType(schema.getQueryType()!), expected);
});