sample-proxies/graphql-sample/graphql-proxy/apiproxy/resources/jsc/graphql.jsc.js
/***
     * This function takes a GraphQL query and checks that all the selections
     * in the query are satisfied by the given list of entitlements.
     *
     *
     * Each entitlement itself is structured as a Dot separated hierarchy of Fields
     *
     *     e.g.
     *     GrandParent.Parent.Child
     *
     * You can use a single wildcard as place-holder for a single field
     *
     *     e.g.
     *     GrandParent.*.Child
     *     (This would match the Child field who has a GrandParent, two levels up)
     *
     * You can use double wildcard as placeholder for multiple fields
     *
     *     e.g.
     *     GrandParent.**
     *     (This would match any hierarchy that starts with GrandParent)
     *
     *
     *
     * @param query
     * @param entitlements
     * @return
     *
     * Returns empty array [], if all the query entitlements are satisfied by the given list of entitlements
     * Otherwise, it returns the list of query entitlements which have not been satisfied.
     */
This function takes a GraphQL query and checks that all the selections
in the query are satisfied by the given list of entitlements.

Each entitlement itself is structured as a Dot separated hierarchy of Fields



You can use a single wildcard as place-holder for a single field



You can use double wildcard as placeholder for multiple fields





@param query
@param entitlements
@return

Returns empty array [], if all the query entitlements are satisfied by the given list of entitlements
Otherwise, it returns the list of query entitlements which have not been satisfied.
This function takes a GraphQL query and checks that all the selections in the query are satisfied by the given list of entitlements . Each entitlement itself is structured as a Dot separated hierarchy of Fields You can use a single wildcard as place - holder for a single field You can use double wildcard as placeholder for multiple fields @param query @param entitlements @return Returns empty array [] if all the query entitlements are satisfied by the given list of entitlements Otherwise it returns the list of query entitlements which have not been satisfied .
function authorize(query) {
      var entitlements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      if (typeof entitlements == 'string') {
        entitlements = entitlements.split(/[\s,;]+/);
      }
      query = parse$1(query);
      var query_entitlements = getPaths(query); 
      entitlements.forEach(function (entitlement) {
        if (query_entitlements.length == 0) {
          return;
        }
        var elements_to_remove = [];
        for (var i = 0; i < query_entitlements.length; i++) {
          var query_entitlement = query_entitlements[i];
          if (entitlement_equals(entitlement, query_entitlement)) {
            elements_to_remove.push(i);
          }
        } 
        for (var j = elements_to_remove.length - 1; j >= 0; j--) {
          var element_to_remove = elements_to_remove[j];
          query_entitlements.splice(element_to_remove, 1);
        }
      });
      return query_entitlements;
    }
function authorize ( query ) { var entitlements = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : [ ] ; if ( typeof entitlements == 'string' ) { entitlements = entitlements . split ( / [\s,;]+ / ) ; } query = parse$1 ( query ) ; var query_entitlements = getPaths ( query ) ; entitlements . forEach ( function ( entitlement ) { if ( query_entitlements . length == 0 ) { return ; } var elements_to_remove = [ ] ; for ( var i = 0 ; i < query_entitlements . length ; i ++ ) { var query_entitlement = query_entitlements [ i ] ; if ( entitlement_equals ( entitlement , query_entitlement ) ) { elements_to_remove . push ( i ) ; } } for ( var j = elements_to_remove . length - 1 ; j >= 0 ; j -- ) { var element_to_remove = elements_to_remove [ j ] ; query_entitlements . splice ( element_to_remove , 1 ) ; } } ) ; return query_entitlements ; }
This function takes a GraphQL query and checks that all the selections
 in the query are satisfied by the given list of entitlements.
This function takes a GraphQL query and checks that all the selections in the query are satisfied by the given list of entitlements .
// perform a comparison between given entitlements and requested entitlements from query // whenever a match is found, the element is removed from the array // if the request array is empty, it means all the erquests match/overlap w/entitelments  //exit early if there are no more query entitlements to match //remove matched elements