9
9
10
10
import { expect } from 'chai' ;
11
11
import { describe , it } from 'mocha' ;
12
- import { parseSchemaIntoAST } from '../parser' ;
12
+ import { parse } from '../parser' ;
13
13
14
14
function createLocFn ( body ) {
15
15
return ( start , end ) => ( {
@@ -80,13 +80,13 @@ describe('Schema Parser', () => {
80
80
type Hello {
81
81
world: String
82
82
}` ;
83
- var doc = parseSchemaIntoAST ( body ) ;
83
+ var doc = parse ( body ) ;
84
84
var loc = createLocFn ( body ) ;
85
85
var expected = {
86
- kind : 'SchemaDocument ' ,
86
+ kind : 'Document ' ,
87
87
definitions : [
88
88
{
89
- kind : 'TypeDefinition ' ,
89
+ kind : 'ObjectDefinition ' ,
90
90
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
91
91
interfaces : [ ] ,
92
92
fields : [
@@ -110,12 +110,12 @@ type Hello {
110
110
world: String!
111
111
}` ;
112
112
var loc = createLocFn ( body ) ;
113
- var doc = parseSchemaIntoAST ( body ) ;
113
+ var doc = parse ( body ) ;
114
114
var expected = {
115
- kind : 'SchemaDocument ' ,
115
+ kind : 'Document ' ,
116
116
definitions : [
117
117
{
118
- kind : 'TypeDefinition ' ,
118
+ kind : 'ObjectDefinition ' ,
119
119
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
120
120
interfaces : [ ] ,
121
121
fields : [
@@ -141,12 +141,12 @@ type Hello {
141
141
it ( 'Simple type inheriting interface' , ( ) => {
142
142
var body = `type Hello implements World { }` ;
143
143
var loc = createLocFn ( body ) ;
144
- var doc = parseSchemaIntoAST ( body ) ;
144
+ var doc = parse ( body ) ;
145
145
var expected = {
146
- kind : 'SchemaDocument ' ,
146
+ kind : 'Document ' ,
147
147
definitions : [
148
148
{
149
- kind : 'TypeDefinition ' ,
149
+ kind : 'ObjectDefinition ' ,
150
150
name : nameNode ( 'Hello' , loc ( 5 , 10 ) ) ,
151
151
interfaces : [ typeNode ( 'World' , loc ( 22 , 27 ) ) ] ,
152
152
fields : [ ] ,
@@ -161,12 +161,12 @@ type Hello {
161
161
it ( 'Simple type inheriting multiple interfaces' , ( ) => {
162
162
var body = `type Hello implements Wo, rld { }` ;
163
163
var loc = createLocFn ( body ) ;
164
- var doc = parseSchemaIntoAST ( body ) ;
164
+ var doc = parse ( body ) ;
165
165
var expected = {
166
- kind : 'SchemaDocument ' ,
166
+ kind : 'Document ' ,
167
167
definitions : [
168
168
{
169
- kind : 'TypeDefinition ' ,
169
+ kind : 'ObjectDefinition ' ,
170
170
name : nameNode ( 'Hello' , loc ( 5 , 10 ) ) ,
171
171
interfaces : [
172
172
typeNode ( 'Wo' , loc ( 22 , 24 ) ) ,
@@ -184,9 +184,9 @@ type Hello {
184
184
it ( 'Single value enum' , ( ) => {
185
185
var body = `enum Hello { WORLD }` ;
186
186
var loc = createLocFn ( body ) ;
187
- var doc = parseSchemaIntoAST ( body ) ;
187
+ var doc = parse ( body ) ;
188
188
var expected = {
189
- kind : 'SchemaDocument ' ,
189
+ kind : 'Document ' ,
190
190
definitions : [
191
191
{
192
192
kind : 'EnumDefinition' ,
@@ -203,9 +203,9 @@ type Hello {
203
203
it ( 'Double value enum' , ( ) => {
204
204
var body = `enum Hello { WO, RLD }` ;
205
205
var loc = createLocFn ( body ) ;
206
- var doc = parseSchemaIntoAST ( body ) ;
206
+ var doc = parse ( body ) ;
207
207
var expected = {
208
- kind : 'SchemaDocument ' ,
208
+ kind : 'Document ' ,
209
209
definitions : [
210
210
{
211
211
kind : 'EnumDefinition' ,
@@ -227,10 +227,10 @@ type Hello {
227
227
interface Hello {
228
228
world: String
229
229
}` ;
230
- var doc = parseSchemaIntoAST ( body ) ;
230
+ var doc = parse ( body ) ;
231
231
var loc = createLocFn ( body ) ;
232
232
var expected = {
233
- kind : 'SchemaDocument ' ,
233
+ kind : 'Document ' ,
234
234
definitions : [
235
235
{
236
236
kind : 'InterfaceDefinition' ,
@@ -255,13 +255,13 @@ interface Hello {
255
255
type Hello {
256
256
world(flag: Boolean): String
257
257
}` ;
258
- var doc = parseSchemaIntoAST ( body ) ;
258
+ var doc = parse ( body ) ;
259
259
var loc = createLocFn ( body ) ;
260
260
var expected = {
261
- kind : 'SchemaDocument ' ,
261
+ kind : 'Document ' ,
262
262
definitions : [
263
263
{
264
- kind : 'TypeDefinition ' ,
264
+ kind : 'ObjectDefinition ' ,
265
265
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
266
266
interfaces : [ ] ,
267
267
fields : [
@@ -292,13 +292,13 @@ type Hello {
292
292
type Hello {
293
293
world(flag: Boolean = true): String
294
294
}` ;
295
- var doc = parseSchemaIntoAST ( body ) ;
295
+ var doc = parse ( body ) ;
296
296
var loc = createLocFn ( body ) ;
297
297
var expected = {
298
- kind : 'SchemaDocument ' ,
298
+ kind : 'Document ' ,
299
299
definitions : [
300
300
{
301
- kind : 'TypeDefinition ' ,
301
+ kind : 'ObjectDefinition ' ,
302
302
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
303
303
interfaces : [ ] ,
304
304
fields : [
@@ -333,13 +333,13 @@ type Hello {
333
333
type Hello {
334
334
world(things: [String]): String
335
335
}` ;
336
- var doc = parseSchemaIntoAST ( body ) ;
336
+ var doc = parse ( body ) ;
337
337
var loc = createLocFn ( body ) ;
338
338
var expected = {
339
- kind : 'SchemaDocument ' ,
339
+ kind : 'Document ' ,
340
340
definitions : [
341
341
{
342
- kind : 'TypeDefinition ' ,
342
+ kind : 'ObjectDefinition ' ,
343
343
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
344
344
interfaces : [ ] ,
345
345
fields : [
@@ -374,13 +374,13 @@ type Hello {
374
374
type Hello {
375
375
world(argOne: Boolean, argTwo: Int): String
376
376
}` ;
377
- var doc = parseSchemaIntoAST ( body ) ;
377
+ var doc = parse ( body ) ;
378
378
var loc = createLocFn ( body ) ;
379
379
var expected = {
380
- kind : 'SchemaDocument ' ,
380
+ kind : 'Document ' ,
381
381
definitions : [
382
382
{
383
- kind : 'TypeDefinition ' ,
383
+ kind : 'ObjectDefinition ' ,
384
384
name : nameNode ( 'Hello' , loc ( 6 , 11 ) ) ,
385
385
interfaces : [ ] ,
386
386
fields : [
@@ -414,10 +414,10 @@ type Hello {
414
414
415
415
it ( 'Simple union' , ( ) => {
416
416
var body = `union Hello = World` ;
417
- var doc = parseSchemaIntoAST ( body ) ;
417
+ var doc = parse ( body ) ;
418
418
var loc = createLocFn ( body ) ;
419
419
var expected = {
420
- kind : 'SchemaDocument ' ,
420
+ kind : 'Document ' ,
421
421
definitions : [
422
422
{
423
423
kind : 'UnionDefinition' ,
@@ -433,10 +433,10 @@ type Hello {
433
433
434
434
it ( 'Union with two types' , ( ) => {
435
435
var body = `union Hello = Wo | Rld` ;
436
- var doc = parseSchemaIntoAST ( body ) ;
436
+ var doc = parse ( body ) ;
437
437
var loc = createLocFn ( body ) ;
438
438
var expected = {
439
- kind : 'SchemaDocument ' ,
439
+ kind : 'Document ' ,
440
440
definitions : [
441
441
{
442
442
kind : 'UnionDefinition' ,
@@ -455,10 +455,10 @@ type Hello {
455
455
456
456
it ( 'Scalar' , ( ) => {
457
457
var body = `scalar Hello` ;
458
- var doc = parseSchemaIntoAST ( body ) ;
458
+ var doc = parse ( body ) ;
459
459
var loc = createLocFn ( body ) ;
460
460
var expected = {
461
- kind : 'SchemaDocument ' ,
461
+ kind : 'Document ' ,
462
462
definitions : [
463
463
{
464
464
kind : 'ScalarDefinition' ,
@@ -476,10 +476,10 @@ type Hello {
476
476
input Hello {
477
477
world: String
478
478
}` ;
479
- var doc = parseSchemaIntoAST ( body ) ;
479
+ var doc = parse ( body ) ;
480
480
var loc = createLocFn ( body ) ;
481
481
var expected = {
482
- kind : 'SchemaDocument ' ,
482
+ kind : 'Document ' ,
483
483
definitions : [
484
484
{
485
485
kind : 'InputObjectDefinition' ,
@@ -505,16 +505,7 @@ input Hello {
505
505
input Hello {
506
506
world(foo: Int): String
507
507
}` ;
508
- expect ( ( ) => parseSchemaIntoAST ( body ) ) . to . throw ( 'Error' ) ;
508
+ expect ( ( ) => parse ( body ) ) . to . throw ( 'Error' ) ;
509
509
} ) ;
510
510
511
- it ( 'Reject query keywords' , ( ) => {
512
- var body = `query Foo { field }` ;
513
- expect ( ( ) => parseSchemaIntoAST ( body ) ) . to . throw ( 'Error' ) ;
514
- } ) ;
515
-
516
- it ( 'Reject query shorthand' , ( ) => {
517
- var body = `{ field }` ;
518
- expect ( ( ) => parseSchemaIntoAST ( body ) ) . to . throw ( 'Error' ) ;
519
- } ) ;
520
511
} ) ;
0 commit comments