I'm not aware of any way to do that specifically with existing tools.
That being said, you could make a module out of these queries (assuming you're using ES6+ and the package graphql-tag
):
// queries.js
export const GetAllTodos = gql`...`
export const GetAllTests = gql`...`
// Where you do a query
import { GetAllTodos, GetAllTests } from './queries.js';
apollo.query({ query: GetAllTodos }).then(( { data } => data);
If you needed more dynamic-ness, the queries.js
module could export a function that can map to these perhaps:
// queries.js
export const queries = {
'GetAllTodos': gql`...`,
'GetAllTests': gql`...`'
};
export default function selectQuery(key) {
return queries[key];
}
// Where you do a query
import selectQuery from './queries.js';
apollo.query({ query: selectQuery('GetAllTodos') }).then(( { data } => data);
You could then expand on this to try and search for a query that matched 'TodoQuery' but name the queries something else like in your original example then.