I have created a basic GraphQL Express app and I'm wanting to bundle pre defined data from pre defined queries with specific routes.
Ideally the query should allow providing arguments so it can be used flexibly, I would like to be able to save the query to a file and run it on demand but provide arguments specific to the current data required.
I can query the api with the following query
query authors(ids: [1337, 42]) {
name,
id
}
The query.graphql file should be something like the following:
getAuthorsById($ids: Int[]) {
authors(ids: $ids) {
name,
id
}
}
What I want to do within the Node server is get the content from a query.graphql file and execute it when a specific route is fired eg.
const query = somehowImportTheQuery('./query.graphql')
graphql(schema, query([1337, 42]))
The above code somehowImportTheQuery should import the query and return a function getAuthorsById that can be called with arguments.
Does something like this already exist? or are there any tools or documentation that can help me achieve the desired functionality?
Thanks for any help!