-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2372 from FAIRsharing/curator_hiding_hack_2371
Curator hiding hack 2371
- Loading branch information
Showing
83 changed files
with
6,332 additions
and
98 deletions.
There are no files selected for viewing
310 changes: 310 additions & 0 deletions
310
..._work_FAIRsharing-Assistant_FAIRsharing-Assistant_src_lib_GraphClient_GraphClient.js.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>FAIRsharing.org Source: /home/runner/work/FAIRsharing-Assistant/FAIRsharing-Assistant/src/lib/GraphClient/GraphClient.js</title> | ||
|
||
<!--[if lt IE 9]> | ||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css"> | ||
|
||
<link type="text/css" rel="stylesheet" href="styles/site.yeti.css"> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<div class="navbar navbar-default navbar-fixed-top navbar-inverse"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<a class="navbar-brand" href="index.html">FAIRsharing.org</a> | ||
</div> | ||
<div class="navbar-collapse"> | ||
<ul class="nav navbar-nav"> | ||
|
||
<li class="dropdown"> | ||
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a> | ||
<ul class="dropdown-menu "> | ||
<li><a href="GraphQLClient.html">GraphQLClient</a></li> | ||
</ul> | ||
</li> | ||
|
||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="container"> | ||
<div class="row"> | ||
|
||
|
||
<div class="col-md-12"> | ||
|
||
<div id="main"> | ||
|
||
|
||
<h1 class="page-title">Source: /home/runner/work/FAIRsharing-Assistant/FAIRsharing-Assistant/src/lib/GraphClient/GraphClient.js</h1> | ||
|
||
<section> | ||
<article> | ||
<pre | ||
class="sunlight-highlight-javascript linenums">const axios = require("axios"); | ||
import Fragments from "./queries/fragments/fragments.json" | ||
|
||
/* istanbul ignore next */ | ||
class GraphQLClient { | ||
|
||
/** The GraphQLClient retrieves data from the FAIRSharing API and sends it to the front-end. | ||
* Be careful, this is a singleton and trying to cast new instances will return the existing instance. Be | ||
* also careful, its constructor is async !! | ||
* @returns {Promise} - to use this object you need to do "await new ClassName()" or use .then(callback) | ||
*/ | ||
constructor(){ | ||
this.initalizeHeader(); | ||
if (GraphQLClient._instance){ | ||
return GraphQLClient._instance | ||
} | ||
GraphQLClient._instance = this; | ||
this.url = process.env.VUE_APP_API_ENDPOINT + "/graphql"; | ||
} | ||
|
||
/** | ||
* Execute the given query (coming from a json file, see /queries/getRecords.json) | ||
* @param {Object} query - the query coming from the JSON file | ||
* sending to the API. | ||
* @returns {Promise} | ||
*/ | ||
async executeQuery(query){ | ||
let client = this; | ||
let queryString = { | ||
query: `{${client.buildQuery(query)}}` | ||
}; | ||
let resp = await this.getData(queryString); | ||
if (resp.data.errors) { | ||
return resp.data.errors; | ||
} | ||
return resp.data.data | ||
} | ||
|
||
/** | ||
* Takes the query, post it with axios and returns the raw data | ||
* @param {Object} queryString - processed request coming out of buildQuery() or a GraphQL query string | ||
* @returns {Promise} - an axios promise representing the server response. | ||
*/ | ||
async getData(queryString){ | ||
let client = this; | ||
const fullQuery = { | ||
method: "post", | ||
baseURL: client.url, | ||
data: queryString, | ||
headers: client.headers | ||
}; | ||
return axios(fullQuery); | ||
} | ||
|
||
/** | ||
* Transform the JSON query into a string for graphQL | ||
* @param {Object} query - the query coming from the JSON file | ||
* @returns {Object} {query: queryString} - a valid graphQL query string to execute | ||
*/ | ||
buildQuery(query){ | ||
let client = this; | ||
let queryString = `${query["queryName"]}`; // query name | ||
|
||
// Handle query parameters | ||
if (query.queryParam) { | ||
queryString += "("; | ||
Object.keys(query.queryParam).forEach(function(key){ | ||
if (typeof query.queryParam[key] === "boolean" || typeof query.queryParam[key] === "number"){ | ||
queryString += `${key}:${query.queryParam[key]} `; | ||
} | ||
else if (typeof query.queryParam[key] === "string") { | ||
queryString += `${key}:"${query.queryParam[key]}" `; | ||
} | ||
else { | ||
let param = []; | ||
query.queryParam[key].forEach(function(paramVal){ | ||
typeof paramVal !== "number" ? param.push("\"" + paramVal + "\"") : param.push(paramVal); | ||
}); | ||
queryString += `${key}:[${param.join(",")}]`; | ||
} | ||
}); | ||
queryString += ")"; | ||
} | ||
|
||
// Handle query fields | ||
if (query.fields){ | ||
queryString += "{"; | ||
query.fields.forEach(function(field){ | ||
if (typeof field === "string"){ | ||
queryString += ` ${field}`; | ||
} | ||
if (typeof field === "object"){ | ||
if ("$ref" in field){ | ||
let myRef = Fragments[field["$ref"]]; | ||
for (let subField of myRef){ | ||
if (typeof subField === "string"){ | ||
queryString += ` ${subField}`; | ||
} | ||
else { | ||
queryString += ` ${client.buildQuery(subField)}`; | ||
} | ||
} | ||
} | ||
else { | ||
queryString += ` ${field.name}{`; | ||
field.fields.forEach(function(subField){ | ||
if (typeof subField === "string"){ | ||
queryString += `${subField} `; | ||
} | ||
else { | ||
queryString += `${client.buildQuery(subField)}`; | ||
} | ||
}); | ||
queryString += "}"; | ||
} | ||
} | ||
}); | ||
queryString += "}"; | ||
} | ||
return queryString; | ||
} | ||
|
||
/** | ||
* Add the authorization token to the headers | ||
* @param {String} jwt - the user json web token | ||
*/ | ||
setHeader(jwt){ | ||
this.headers['Authorization'] = `Bearer ${jwt}`; | ||
} | ||
|
||
initalizeHeader(){ | ||
this.headers = { | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
this.headers['X-Client-Id'] = process.env.VUE_APP_CLIENT_ID; | ||
/* istanbul ignore if */ | ||
if (this.headers['X-Client-Id'] === undefined){ | ||
delete this.headers['X-Client-Id'] | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
export default GraphQLClient; | ||
</pre> | ||
</article> | ||
</section> | ||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
|
||
<div class="clearfix"></div> | ||
|
||
|
||
|
||
</div> | ||
</div> | ||
|
||
|
||
<footer> | ||
|
||
|
||
<span class="copyright"> | ||
DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects. | ||
</span> | ||
|
||
<span class="jsdoc-message"> | ||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> | ||
on Wed Aug 16th 2023 using the <a | ||
href="https://github.com/docstrap/docstrap">DocStrap template</a>. | ||
</span> | ||
</footer> | ||
|
||
<!--<script src="scripts/sunlight.js"></script>--> | ||
<script src="scripts/docstrap.lib.js"></script> | ||
<script src="scripts/bootstrap-dropdown.js"></script> | ||
<script src="scripts/toc.js"></script> | ||
|
||
<script> | ||
$( function () { | ||
$( "[id*='$']" ).each( function () { | ||
var $this = $( this ); | ||
|
||
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) ); | ||
} ); | ||
|
||
$( ".tutorial-section pre, .readme-section pre" ).each( function () { | ||
var $this = $( this ); | ||
|
||
var example = $this.find( "code" ); | ||
exampleText = example.html(); | ||
var lang = /{@lang (.*?)}/.exec( exampleText ); | ||
if ( lang && lang[1] ) { | ||
exampleText = exampleText.replace( lang[0], "" ); | ||
example.html( exampleText ); | ||
lang = lang[1]; | ||
} else { | ||
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/); | ||
lang = langClassMatch ? langClassMatch[1] : "javascript"; | ||
} | ||
|
||
if ( lang ) { | ||
|
||
$this | ||
.addClass( "sunlight-highlight-" + lang ) | ||
.addClass( "linenums" ) | ||
.html( example.html() ); | ||
|
||
} | ||
} ); | ||
|
||
Sunlight.highlightAll( { | ||
lineNumbers : true, | ||
showMenu : true, | ||
enableDoclinks : true | ||
} ); | ||
|
||
$( "#toc" ).toc( { | ||
anchorName : function ( i, heading, prefix ) { | ||
var id = $( heading ).attr( "id" ); | ||
return id && id.replace(/\~/g, '-inner-').replace(/\./g, '-static-') || ( prefix + i ); | ||
}, | ||
selectors : "h1,h2,h3,h4", | ||
showAndHide : false, | ||
navbarOffset: 10, | ||
smoothScrolling: true | ||
} ); | ||
|
||
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" ); | ||
$( "#main span[id^='toc']" ).addClass( "toc-shim" ); | ||
$( '.dropdown-toggle' ).dropdown(); | ||
// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" ); | ||
|
||
$( "table" ).each( function () { | ||
var $this = $( this ); | ||
$this.addClass('table'); | ||
} ); | ||
|
||
} ); | ||
</script> | ||
|
||
|
||
|
||
<!--Navigation and Symbol Display--> | ||
|
||
|
||
<!--Google Analytics--> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.