Description
I'd like to be able to append to editor's query text (or more generally transform it) before sending it to graphql-language-service-interface
.
Motivation
In https://github.com/gatsbyjs/gatsby we allow supplying fragments that users can use freely in their queries (we transform queries and attach used fragment definitions before query execution with the help of relay-compiler
). This works well in queries to users write in their source code, but doesn't work currently in graphiql because those 3rd party fragments are not in document and codemirror-graphql/lint
report errors (missing fragment definitoins) and codemirror-graphql/hint
also can't provide autocompletion hints for those fragments it doesn't know about.
Proposed design
Allow passing extra option to addons - for example transformQueryText
function (that will default to identity transform if not specified), that will be exucuted before passing query text to graphql-language-service-interface
functions (getDiagnostics
for lint / getAutocompleteSuggestions
for hint):
CodeMirror.fromTextArea(myTextarea, {
mode: 'graphql',
lint: {
schema: myGraphQLSchema,
transformQueryText: queryText => doSomethingWithQueryText(queryText)
},
hintOptions: {
schema: myGraphQLSchema,
transformQueryText: queryText => doSomethingWithQueryText(queryText)
}
});
Example of this in action:
In here I make use of fragments that are not in document, but are supplied by Gatsby, and both lint (no "unknown fragment" error) and hint (autocompletion for fragments supplied by Gatsby) works as expected for Gatsby usecase:
Above screenshot is result of some monkey patching (just to to make proof of concept that this can work).
I would be happy to submit pull request, but wanted to check first if this is something that would be welcome here.