mirror of
https://github.com/badges/shields.git
synced 2026-11-21 16:06:35 +03:00
* chore(deps): bump graphql from 16.14.1 to 17.0.2 Bumps [graphql](https://github.com/graphql/graphql-js) from 16.14.1 to 17.0.2. - [Release notes](https://github.com/graphql/graphql-js/releases) - [Commits](https://github.com/graphql/graphql-js/compare/v16.14.1...v17.0.2) --- updated-dependencies: - dependency-name: graphql dependency-version: 17.0.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Support collections that can be undefined rather than empty --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pierre-Yves Bigourdan <10694593+PyvesB@users.noreply.github.com>
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
/**
|
|
* @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
|
|
}
|
|
|
|
export { mergeQueries }
|