Merge GraphQL queries.
NOTE: This is very much untested in anything else than the simplest scenarios
Transform
query {
topUsers {
firstName
lastName
}
}
and
query {
topUsers {
company
}
}
Into this:
query {
topUsers {
firstName
lastName
company
}
}
import { parse, print } from 'graphql';
import { merge } from 'graphql-merge';
const queryB = parse('{ users { name address } } }');
const queryA = parse('{ users { favoriteColor } }');
const mergedQuery = merge(queryA, queryB);
console.log(print(mergedQuery));
// { users { name address favoriteColor } }
- Arguments should be merged when allowed by configuration
- i.e.
users(first: 10) and users(first: 12)
should be merged intousers(first: 12)
given that some configuration contains{ joinArgumentNames: ['first'] }
- i.e.
- Rewrite variable names where possible