@@ -3565,6 +3565,19 @@ var Logger = /** @class */ (function () {
35653565 console . log . apply ( console , this . PREFIX . concat ( messages ) ) ;
35663566 }
35673567 } ;
3568+ /**
3569+ * Wrapper for console.warn.
3570+ * @param {Array<any> } messages
3571+ */
3572+ Logger . prototype . warn = function ( ) {
3573+ var messages = [ ] ;
3574+ for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
3575+ messages [ _i ] = arguments [ _i ] ;
3576+ }
3577+ if ( this . enabled ) {
3578+ console . warn . apply ( console , this . PREFIX . concat ( messages ) ) ;
3579+ }
3580+ } ;
35683581 /**
35693582 * Logs a graphql query in a readable format and with all information like fetch policy and variables.
35703583 * @param {string | DocumentNode } query
@@ -9832,6 +9845,42 @@ var Apollo = /** @class */ (function () {
98329845 return Apollo ;
98339846} ( ) ) ;
98349847
9848+ var Schema = /** @class */ ( function ( ) {
9849+ function Schema ( schema ) {
9850+ var _this = this ;
9851+ this . schema = schema ;
9852+ this . types = new Map ( ) ;
9853+ this . mutations = new Map ( ) ;
9854+ this . queries = new Map ( ) ;
9855+ this . schema . types . forEach ( function ( t ) { return _this . types . set ( t . name , t ) ; } ) ;
9856+ this . getType ( 'Query' ) . fields . forEach ( function ( f ) { return _this . queries . set ( f . name , f ) ; } ) ;
9857+ this . getType ( 'Mutation' ) . fields . forEach ( function ( f ) { return _this . mutations . set ( f . name , f ) ; } ) ;
9858+ }
9859+ Schema . prototype . getType = function ( name ) {
9860+ name = upcaseFirstLetter ( name ) ;
9861+ var type = this . types . get ( name ) ;
9862+ if ( ! type )
9863+ throw new Error ( "Couldn't find Type of name " + name + " in the GraphQL Schema." ) ;
9864+ return type ;
9865+ } ;
9866+ Schema . prototype . getMutation = function ( name ) {
9867+ var mutation = this . mutations . get ( name ) ;
9868+ if ( ! mutation )
9869+ throw new Error ( "Couldn't find Mutation of name " + name + " in the GraphQL Schema." ) ;
9870+ return mutation ;
9871+ } ;
9872+ Schema . prototype . getQuery = function ( name ) {
9873+ var query = this . types . get ( name ) ;
9874+ if ( ! query )
9875+ throw new Error ( "Couldn't find Query of name " + name + " in the GraphQL Schema." ) ;
9876+ return query ;
9877+ } ;
9878+ Schema . prototype . returnsConnection = function ( field ) {
9879+ return field . type . name . endsWith ( 'TypeConnection' ) ;
9880+ } ;
9881+ return Schema ;
9882+ } ( ) ) ;
9883+
98359884var __awaiter$1 = ( undefined && undefined . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
98369885 return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
98379886 function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
@@ -9941,8 +9990,11 @@ var Context = /** @class */ (function () {
99419990 return [ 4 /*yield*/ , this . apollo . simpleQuery ( introspectionQuery , { } , true , context ) ] ;
99429991 case 1 :
99439992 result = _a . sent ( ) ;
9944- this . schema = result . data . __schema ;
9945- this . logger . log ( 'GraphQL Schema successful fetched' , this . schema ) ;
9993+ this . schema = new Schema ( result . data . __schema ) ;
9994+ this . logger . log ( 'GraphQL Schema successful fetched' , result ) ;
9995+ this . logger . log ( 'Starting to process the schema ...' ) ;
9996+ this . processSchema ( ) ;
9997+ this . logger . log ( 'Schema procession done ...' ) ;
99469998 _a . label = 2 ;
99479999 case 2 : return [ 2 /*return*/ ] ;
994810000 }
@@ -9978,6 +10030,29 @@ var Context = /** @class */ (function () {
997810030 Model . augment ( model ) ;
997910031 } ) ;
998010032 } ;
10033+ Context . prototype . processSchema = function ( ) {
10034+ var _this = this ;
10035+ this . models . forEach ( function ( model ) {
10036+ var type ;
10037+ try {
10038+ type = _this . schema . getType ( model . singularName ) ;
10039+ }
10040+ catch ( error ) {
10041+ _this . logger . warn ( "Ignoring entity " + model . singularName + " because it's not in the schema." ) ;
10042+ return ;
10043+ }
10044+ model . fields . forEach ( function ( field , fieldName ) {
10045+ if ( ! type . fields . find ( function ( f ) { return f . name === fieldName ; } ) ) {
10046+ _this . logger . warn ( "Ignoring field " + model . singularName + "." + fieldName + " because it's not in the schema." ) ;
10047+ // TODO: Move skipFields to the model
10048+ model . baseModel . skipFields = model . baseModel . skipFields ? model . baseModel . skipFields : [ ] ;
10049+ if ( ! model . baseModel . skipFields . includes ( fieldName ) ) {
10050+ model . baseModel . skipFields . push ( fieldName ) ;
10051+ }
10052+ }
10053+ } ) ;
10054+ } ) ;
10055+ } ;
998110056 return Context ;
998210057} ( ) ) ;
998310058
0 commit comments