-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow transforming query text before passing it to graphql-language-service-interface
#862
Comments
Hey ! Is this feature considered ? |
yes, though it might be a bit before it lands in the GraphQL IDE ecosystem. |
Ok, thanks for the input ! I'd be very interested in any way (even hacky !) to provide fragments somehow. |
@Neitsch I feel like there was an issue or PR for GLS that addressed this via GraphQL Config but I couldn't find it - either way, do you feel like this is something that could be (better) addressed further down the stack in GLS, in the interface or service perhaps? It seems there is a wide demand for tooling that allows users to supply custom directives. I would like to implement something that works across the IDE stack, rather than just in a web IDE implementation |
#612 here it is - I haven't looked closely enough to be sure, but it seems like these are working towards the same goal, just with very different paths to implementation? |
I think I understand better the need for this, and potentially in |
this would have been a far more powerful API to expose than what I introduced with |
@acao Looking at this, I think the external fragments solution should be sufficient for this? Are there potentially any other use cases where this ability to transform the query before sending to LSP (which specifically means affecting the linting and hinting only) makes sense? |
i agree. it seems powerful to manipulate the AST before requesting language features from these service levels, but I don't see that as the purpose of the LSP, beyond what |
though.. for just the purpose of manipulating operations... I'm remembering that this is a goal of @OneGraph folks for explorer, and it provides us a cleaner way of implementing when it makes sense to manipulate graphql documents - when executing operations - which happens using other thoughts:
|
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 andcodemirror-graphql/lint
report errors (missing fragment definitoins) andcodemirror-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 tographql-language-service-interface
functions (getDiagnostics
for lint /getAutocompleteSuggestions
for hint):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.
The text was updated successfully, but these errors were encountered: