@@ -2,12 +2,13 @@ import { expect } from 'chai';
22import { graphql } from 'graphql' ;
33import { Logger , LoggerProvider } from '../../src/config/logging' ;
44import { DatabaseAdapter , FlexSearchTokenizable } from '../../src/database/database-adapter' ;
5- import { FlexSearchLanguage , Model } from '../../src/model' ;
5+ import { Model } from '../../src/model' ;
66import { Project } from '../../src/project/project' ;
77import { ProjectSource } from '../../src/project/source' ;
88import { QueryNode } from '../../src/query-tree' ;
99import { FlexSearchTokenization } from '../../src/query-tree/flex-search' ;
10- import { createSchema } from '../../src/schema/schema-builder' ;
10+ import gql from 'graphql-tag' ;
11+ import { expectSingleError , expectToBeValid } from '../model/implementation/validation-utils' ;
1112
1213class FakeDBAdatper implements DatabaseAdapter {
1314 async execute ( queryTree : QueryNode ) : Promise < any > {
@@ -30,6 +31,99 @@ class FakeDBAdatper implements DatabaseAdapter {
3031}
3132
3233describe ( 'project' , ( ) => {
34+ describe ( 'validate' , ( ) => {
35+ it ( 'accepts a valid simple project' , async ( ) => {
36+ const project = new Project ( [
37+ gql `
38+ type Test @rootEntity {
39+ key: String @key
40+ }
41+ ` . loc ! . source ,
42+ ] ) ;
43+ expectToBeValid ( project ) ;
44+ } ) ;
45+
46+ it ( 'accepts a valid project with multiple sources' , async ( ) => {
47+ const project = new Project ( [
48+ gql `
49+ type Test @rootEntity {
50+ key: String @key
51+ children: [Child]
52+ }
53+ ` . loc ! . source ,
54+ gql `
55+ # make sure this file is not skipped just because it begins with a comment
56+ type Child @childEntity {
57+ key: String
58+ }
59+ ` . loc ! . source ,
60+ ] ) ;
61+ expectToBeValid ( project ) ;
62+ } ) ;
63+
64+ it ( 'rejects an invalid project with multiple sources' , async ( ) => {
65+ const project = new Project ( [
66+ gql `
67+ type Test @rootEntity {
68+ key: String @key
69+ children: [Child]
70+ }
71+ ` . loc ! . source ,
72+ gql `
73+ type OtherChild @childEntity {
74+ key: String
75+ }
76+ ` . loc ! . source ,
77+ ] ) ;
78+ expectSingleError ( project , 'Type "Child" not found.' ) ;
79+ } ) ;
80+
81+ it ( 'accepts a valid project with an additional empty file' , async ( ) => {
82+ const project = new Project ( [
83+ gql `
84+ type Test @rootEntity {
85+ key: String @key
86+ }
87+ ` . loc ! . source ,
88+ {
89+ name : 'other.graphqls' ,
90+ body : '' ,
91+ } ,
92+ ] ) ;
93+ expectToBeValid ( project ) ;
94+ } ) ;
95+
96+ it ( 'accepts a valid project with an additional file that only contains comments' , async ( ) => {
97+ const project = new Project ( [
98+ gql `
99+ type Test @rootEntity {
100+ key: String @key
101+ }
102+ ` . loc ! . source ,
103+ {
104+ name : 'other.graphqls' ,
105+ body : '# this is a comment' ,
106+ } ,
107+ ] ) ;
108+ expectToBeValid ( project ) ;
109+ } ) ;
110+
111+ it ( 'accepts a project without any source' , async ( ) => {
112+ const project = new Project ( [ ] ) ;
113+ expectToBeValid ( project ) ;
114+ } ) ;
115+
116+ it ( 'accepts a project with just a comment-only source' , async ( ) => {
117+ const project = new Project ( [
118+ {
119+ name : 'other.graphqls' ,
120+ body : '# this is a comment' ,
121+ } ,
122+ ] ) ;
123+ expectToBeValid ( project ) ;
124+ } ) ;
125+ } ) ;
126+
33127 describe ( 'createSchema' , ( ) => {
34128 it ( 'schema resolvers log to logger specified in project' , async ( ) => {
35129 let logs : string [ ] = [ ] ;
0 commit comments