sample-proxies/graphql-sample/graphql-proxy/apiproxy/resources/jsc/graphql.jsc.js
/***
     * This function derives the entitlements from a GraphQL schema that is annotated with @scope directives
     **
     * The location of the @scope directive indicates the paths that are accessible by the given scope.
     *
     * The @scope directive to a GraphQL type, or a field within a type.
     * Depending on where you put the @scope directive, it has different meaning.
     *
     * 1) If the @scope directive appears on a GraphQL type, then it applies to all fields of this GraphQL type
     *  (NOTE: this is not the same as all the fields within the GraphQL type)
     *
     * 2) If the @scope directive appears on a field, then it applies only the field itself (regardless of the GraphQL type)
     *
     *
     * The @scope directive is defined as follows:
     *
     *  directive  @scope(name: String!, query: Boolean, mutation: Boolean, cascade: Boolean)
     *
     *  name - This is the name of the scope
     *  query (default: false) - Whether or not this scope is relevant to GraphQL queries
     *  mutation (default: false) - Whether or not this scope is relevant to GraphQL mutations
     *  cascade - (default: true) Whether or not this scope is applicable to all the descendants of the field.
     *
     *
     * @param schemaText
     * @return
     *
     * Returns an object containing a map of scope name to a list of entitlements from the schema.
     *
     * { "scopeA": [ "query.employee","query.employee.**"],
     *   "scopeB" : [ "query.company","query.company.**"]
     *  }
     *
     */
This function derives the entitlements from a GraphQL schema that is annotated with @scope directives
The location of the @scope directive indicates the paths that are accessible by the given scope.

The @scope directive to a GraphQL type, or a field within a type.
Depending on where you put the @scope directive, it has different meaning.

1) If the @scope directive appears on a GraphQL type, then it applies to all fields of this GraphQL type
(NOTE: this is not the same as all the fields within the GraphQL type)

2) If the @scope directive appears on a field, then it applies only the field itself (regardless of the GraphQL type)

The @scope directive is defined as follows.

directive  @scope(name: String!, query: Boolean, mutation: Boolean, cascade: Boolean)

This is the name of the scope
query (default: false) - Whether or not this scope is relevant to GraphQL queries
mutation (default: false) - Whether or not this scope is relevant to GraphQL mutations
cascade - (default: true) Whether or not this scope is applicable to all the descendants of the field.

@param schemaText
@return

Returns an object containing a map of scope name to a list of entitlements from the schema.


This function derives the entitlements from a GraphQL schema that is annotated with @scope directives The location of the @scope directive indicates the paths that are accessible by the given scope . The @scope directive to a GraphQL type or a field within a type . Depending on where you put the @scope directive it has different meaning . 1 ) If the @scope directive appears on a GraphQL type then it applies to all fields of this GraphQL type ( NOTE : this is not the same as all the fields within the GraphQL type ) 2 ) If the @scope directive appears on a field then it applies only the field itself ( regardless of the GraphQL type ) The @scope directive is defined as follows . directive @scope ( name : String! query : Boolean mutation : Boolean cascade : Boolean ) This is the name of the scope query ( default : false ) - Whether or not this scope is relevant to GraphQL queries mutation ( default : false ) - Whether or not this scope is relevant to GraphQL mutations cascade - ( default : true ) Whether or not this scope is applicable to all the descendants of the field . @param schemaText @return Returns an object containing a map of scope name to a list of entitlements from the schema .
function schemaToEntitlements(schema) {
      schema = parse$1(schema);
      var graph = schemaToGraph(schema); 
      var stack = [];
      var paths = {};
      graph.forEach(function (node) {
        if (node.origin) {
          stack.push([node]);
        }
      });
      var _loop2 = function _loop2() {
        var path = stack.pop();
        var last_node = path[path.length - 1]; 
        if (last_node.scopes.length > 0) {
          last_node.scopes.forEach(function (scope) {
            if (!paths[scope.name]) {
              paths[scope.name] = [];
            }
            if (is_mutation_path(path) && !scope.mutation) {
              return;
            }
            if (is_query_path(path) && !scope.query) {
              return;
            }
            paths[scope.name] = paths[scope.name].concat(make_entitlements(path, scope));
          });
        }
        last_node.children.forEach(function (child) {
          var found_loop = false;
          path.forEach(function (element) {
            if (element === child) {
              found_loop = true;
              return;
            }
          });
          if (found_loop) {
            return;
          }
          stack.push(path.concat([child]));
        });
      };
      while (stack.length > 0) {
        _loop2();
      }
      return paths;
    }
function schemaToEntitlements ( schema ) { schema = parse$1 ( schema ) ; var graph = schemaToGraph ( schema ) ; var stack = [ ] ; var paths = { } ; graph . forEach ( function ( node ) { if ( node . origin ) { stack . push ( [ node ] ) ; } } ) ; var _loop2 = function _loop2 ( ) { var path = stack . pop ( ) ; var last_node = path [ path . length - 1 ] ; if ( last_node . scopes . length > 0 ) { last_node . scopes . forEach ( function ( scope ) { if ( ! paths [ scope . name ] ) { paths [ scope . name ] = [ ] ; } if ( is_mutation_path ( path ) && ! scope . mutation ) { return ; } if ( is_query_path ( path ) && ! scope . query ) { return ; } paths [ scope . name ] = paths [ scope . name ] . concat ( make_entitlements ( path , scope ) ) ; } ) ; } last_node . children . forEach ( function ( child ) { var found_loop = false ; path . forEach ( function ( element ) { if ( element === child ) { found_loop = true ; return ; } } ) ; if ( found_loop ) { return ; } stack . push ( path . concat ( [ child ] ) ) ; } ) ; } ; while ( stack . length > 0 ) { _loop2 ( ) ; } return paths ; }
This function derives the entitlements from a GraphQL schema that is annotated with @scope directives
 The location of the @scope directive indicates the paths that are accessible by the given scope.
This function derives the entitlements from a GraphQL schema that is annotated with @scope directives The location of the @scope directive indicates the paths that are accessible by the given scope .
// starting at origins, find all possible paths to any scopes. // When ready to add a path, see if scope exists in object. If not, // create entry. //arbitrarily using stack for DFS //all scopes will be strings //check if child exists in path already to avoid loops