File tree Expand file tree Collapse file tree 4 files changed +20
-3
lines changed
Expand file tree Collapse file tree 4 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " graphql-js-tree" ,
3- "version" : " 0.1.7 " ,
3+ "version" : " 0.1.8 " ,
44 "private" : false ,
55 "license" : " MIT" ,
66 "description" : " GraphQL Parser providing simplier structure" ,
Original file line number Diff line number Diff line change @@ -67,7 +67,10 @@ export class Parser {
6767 static parse = ( schema : string , excludeRoots : string [ ] = [ ] , libraries = '' ) : ParserTree => {
6868 let parsedSchema : DocumentNode | undefined ;
6969 const compiledSchema = [ libraries , schema ] . join ( '\n' ) ;
70-
70+ const isEmptySchema = compiledSchema . replace ( / \s + / gm, '' ) . length === 0 ;
71+ if ( isEmptySchema ) {
72+ return { nodes : [ ] } ;
73+ }
7174 try {
7275 parsedSchema = parse ( compiledSchema ) ;
7376 } catch ( error ) {
Original file line number Diff line number Diff line change 1+ import { Parser } from '../../Parser' ;
2+
3+ describe ( 'Empty schema tests on parser' , ( ) => {
4+ it ( 'Creates empty tree from schema' , ( ) => {
5+ const schema = ` ` ;
6+ const tree = Parser . parse ( schema ) ;
7+ expect ( tree . nodes . length ) . toEqual ( 0 ) ;
8+ } ) ;
9+ it ( 'Creates empty tree from schema' , ( ) => {
10+ const schema = ` \t\t \n\n\n ` ;
11+ const tree = Parser . parse ( schema ) ;
12+ expect ( tree . nodes . length ) . toEqual ( 0 ) ;
13+ } ) ;
14+ } ) ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export const decompileType = (typeName: string): FieldType => {
3939} ;
4040
4141export const generateNodeId = ( name : string , dataType : AllTypes , args : ParserField [ ] ) => {
42- const s = [ name , dataType , args . map ( ( a ) => a . name ) ] . join ( '-' ) ;
42+ const s = [ name , dataType , args . map ( ( a ) => a . name ) . join ( '-' ) ] . join ( '-' ) ;
4343 return cyrb53 ( s ) ;
4444} ;
4545const cyrb53 = ( str : string , seed = 0 ) => {
You can’t perform that action at this time.
0 commit comments