* add base class for Graphql APIs * add GithubAuthV4Service + updates to GH token pool * update github forks to use GithubAuthV4Service * rename GithubAuthService to GithubAuthV3Service
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
'use strict'
|
|
/**
|
|
* @module
|
|
*/
|
|
|
|
/**
|
|
* Utility function to merge two graphql queries together
|
|
* This is basically copied from
|
|
* [graphql-query-merge](https://www.npmjs.com/package/graphql-query-merge)
|
|
* but can't use that due to incorrect packaging.
|
|
*
|
|
* @param {...object} queries queries to merge
|
|
* @returns {object} merged query
|
|
*/
|
|
function mergeQueries(...queries) {
|
|
const merged = {
|
|
kind: 'Document',
|
|
definitions: [
|
|
{
|
|
directives: [],
|
|
operation: 'query',
|
|
variableDefinitions: [],
|
|
kind: 'OperationDefinition',
|
|
selectionSet: { kind: 'SelectionSet', selections: [] },
|
|
},
|
|
],
|
|
}
|
|
|
|
queries.forEach(query => {
|
|
const parsedQuery = query
|
|
parsedQuery.definitions.forEach(definition => {
|
|
merged.definitions[0].directives = [
|
|
...merged.definitions[0].directives,
|
|
...definition.directives,
|
|
]
|
|
|
|
merged.definitions[0].variableDefinitions = [
|
|
...merged.definitions[0].variableDefinitions,
|
|
...definition.variableDefinitions,
|
|
]
|
|
|
|
merged.definitions[0].selectionSet.selections = [
|
|
...merged.definitions[0].selectionSet.selections,
|
|
...definition.selectionSet.selections,
|
|
]
|
|
})
|
|
})
|
|
|
|
return merged
|
|
}
|
|
|
|
module.exports = { mergeQueries }
|