@@ -12,6 +12,7 @@ const { getMainDefinition } = require('apollo-utilities');
1212const { createUploadLink } = require ( 'apollo-upload-client' ) ;
1313const { SubscriptionClient } = require ( 'subscriptions-transport-ws' ) ;
1414const { WebSocketLink } = require ( '@apollo/client/link/ws' ) ;
15+ const { mergeSchemas } = require ( '@graphql-tools/schema' ) ;
1516const {
1617 ApolloClient,
1718 InMemoryCache,
@@ -133,28 +134,31 @@ describe('ParseGraphQLServer', () => {
133134 } ) ;
134135
135136 describe ( 'applyGraphQL' , ( ) => {
136- it ( 'should require an Express.js app instance' , ( ) => {
137- expect ( ( ) => parseGraphQLServer . applyGraphQL ( ) ) . toThrow (
137+ it ( 'should require an Express.js app instance' , async ( ) => {
138+ await expectAsync ( parseGraphQLServer . applyGraphQL ( ) ) . toBeRejectedWith (
138139 'You must provide an Express.js app instance!'
139140 ) ;
140- expect ( ( ) => parseGraphQLServer . applyGraphQL ( { } ) ) . toThrow (
141+ await expectAsync ( parseGraphQLServer . applyGraphQL ( { } ) ) . toBeRejectedWith (
141142 'You must provide an Express.js app instance!'
142143 ) ;
143- expect ( ( ) => parseGraphQLServer . applyGraphQL ( new express ( ) ) ) . not . toThrow ( ) ;
144+ await expectAsync ( parseGraphQLServer . applyGraphQL ( new express ( ) ) ) . toBeResolved ( ) ;
144145 } ) ;
145146
146- it ( 'should apply middlewares at config.graphQLPath' , ( ) => {
147+ it ( 'should apply middlewares at config.graphQLPath' , async ( ) => {
147148 let useCount = 0 ;
148- expect ( ( ) =>
149- new ParseGraphQLServer ( parseServer , {
150- graphQLPath : 'somepath' ,
151- } ) . applyGraphQL ( {
152- use : path => {
153- useCount ++ ;
154- expect ( path ) . toEqual ( 'somepath' ) ;
155- } ,
156- } )
157- ) . not . toThrow ( ) ;
149+ const gqlServer = new ParseGraphQLServer ( parseServer , {
150+ graphQLPath : 'somepath' ,
151+ } ) ;
152+ gqlServer . applyGraphQL ( {
153+ use : server => {
154+ useCount ++ ;
155+ if ( typeof server === 'string' ) {
156+ expect ( server ) . toEqual ( 'somepath' ) ;
157+ } else {
158+ expect ( server . stack [ 1 ] . regexp . toString ( ) ) . toEqual ( '/^somepath\\/?(?=\\/|$)/i' ) ;
159+ }
160+ } ,
161+ } ) ;
158162 expect ( useCount ) . toBeGreaterThan ( 0 ) ;
159163 } ) ;
160164 } ) ;
@@ -7697,8 +7701,8 @@ describe('ParseGraphQLServer', () => {
76977701 . map ( call => call . args [ 0 ] )
76987702 . sort ( )
76997703 ) . toEqual ( [
7700- 'Function 1NumberInTheBeggning could not be added to the auto schema because GraphQL names must match /^[_a-zA- Z][_a-zA-Z0-9]*$ /.' ,
7701- 'Function double-barrelled could not be added to the auto schema because GraphQL names must match /^[_a-zA- Z][_a-zA-Z0-9]*$ /.' ,
7704+ 'Function 1NumberInTheBeggning could not be added to the auto schema because GraphQL names must match /^ [_a - zA - Z][_a - zA - Z0 - 9] * $ /.' ,
7705+ 'Function double-barrelled could not be added to the auto schema because GraphQL names must match /^ [_a - zA - Z][_a - zA - Z0 - 9] * $ /.' ,
77027706 ] ) ;
77037707 } catch ( e ) {
77047708 handleError ( e ) ;
@@ -10381,7 +10385,7 @@ describe('ParseGraphQLServer', () => {
1038110385 } ) ;
1038210386
1038310387 describe ( 'Custom API' , ( ) => {
10384- describe ( 'GraphQL Schema Based ' , ( ) => {
10388+ describe ( 'SDL based ' , ( ) => {
1038510389 let httpServer ;
1038610390 const headers = {
1038710391 'X-Parse-Application-Id' : 'test' ,
@@ -10504,7 +10508,7 @@ describe('ParseGraphQLServer', () => {
1050410508 } ) ;
1050510509 } ) ;
1050610510
10507- describe ( 'SDL Based' , ( ) => {
10511+ describe ( 'GraphQL Schema Based' , ( ) => {
1050810512 let httpServer ;
1050910513 const headers = {
1051010514 'X-Parse-Application-Id' : 'test' ,
@@ -10801,8 +10805,7 @@ describe('ParseGraphQLServer', () => {
1080110805 httpServer = http . createServer ( expressApp ) ;
1080210806 parseGraphQLServer = new ParseGraphQLServer ( parseServer , {
1080310807 graphQLPath : '/graphql' ,
10804- graphQLCustomTypeDefs : ( { autoSchema, stitchSchemas } ) =>
10805- stitchSchemas ( { subschemas : [ autoSchema ] } ) ,
10808+ graphQLCustomTypeDefs : ( { autoSchema } ) => mergeSchemas ( { schemas : [ autoSchema ] } ) ,
1080610809 } ) ;
1080710810
1080810811 parseGraphQLServer . applyGraphQL ( expressApp ) ;
0 commit comments