-
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
feat(graphql-config): add graphql config extensions #1118
Conversation
This PR is a port of graphql/graphql-language-service#240 It adds GraphQL config extension support to the language server. This would enable the following scenarios (not-exhaustive): 1. Using environment variables (or variables in a custom format) 2. Supply customDirectives dynamically - can be tool specific like Gatsby 3. Supply customValidationRules dynamically 4. Add endpoints, headers dynamically
let config = getGraphQLConfig(rootPath); | ||
if (this._extensions && this._extensions.length > 0) { | ||
/* eslint-disable no-await-in-loop */ | ||
for (let i = 0; i < this._extensions.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have support for the latest language features now, so if you want to use for... await of here you can! I think Its node 9+.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped the loop to new syntax but kept /* eslint-disable no-await-in-loop */
becuase lint still disables it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@divyenduz interesting note, perhaps we should change this rule now that we have modern for...await of
this looks great @divyenduz, thanks! |
Codecov Report
@@ Coverage Diff @@
## master #1118 +/- ##
=========================================
Coverage ? 43.98%
=========================================
Files ? 64
Lines ? 3008
Branches ? 652
=========================================
Hits ? 1323
Misses ? 1414
Partials ? 271
Continue to review full report at Codecov.
|
oh dear, looks like codecov blocked it. but yeah this is right up our alley in terms of our intended route with graphql config. I’m looking forward to getting the LanguageService class and its own GraphQLCache working in the browser soon. We may end up figuring out how graphql config could be one config service, or you can bring your own, but that seems too complicated. different platforms want to have their own config formats, but maybe we can introduce something to graphql-config where they could specify different extensions and map their values to graphql-config values? |
That is interesting indeed, are you suggesting that we move this feature from here into the GraphQL config? IIRC they had some extension work done in GraphQL Config back then, we chose to do this feature back then in LSP because we wanted dynamic config changes (my memory on this is faded, but we can surely re-think it) |
@kamilkisiela has already introduced a start for extending GraphQL Config for different tools in the new alpha. @divyenduz we would love to chat and see if that fits your use case or should we change anything! |
@divyenduz just needs some more test coverage to get builds passing! maybe we can get this merged before the typescript conversion is merged? |
@acao When do you plan to merge your refactor? I am traveling over the weekend. I can maybe get to this on 26th? (or will see if I can find a moment from an airport or something 😅) |
it’s almost finished, just two more tests, but then itll need plenty of time to review. that should be plenty of time! enjoy your holidays, thank you @divyenduz ! |
@divyenduz this one should be relatively easy to update for typescript when you get a chance? can you update docs as well? |
@divyenduz I think they are deprecating the endpoints extension specifically, however I think https://graphql-config.com/docs/introduction so this feature is very useful. @ardatan @kamilkisiela agreed this is still compatible with 3.0.0-alpha-n? on top of the graphql-config migration PR @ardatan already created? |
@divyenduz an alpha release is now available :D |
@@ -46,10 +47,13 @@ type Options = { | |||
// port for the LSP server to run on | |||
port?: number; | |||
// socket, streams, or node (ipc). if socket, port is required | |||
method?: 'socket' | 'stream' | 'node'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks incorrect. I think this should be 'socket' | 'stream' | 'node'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed via f6d8a56
@acao I wonder why CI tests that blocked me last time didn't appear this time? 🤔 |
@divyenduz that is strange, i wonder if there's an issue with github actions? |
possibly because this PR pre-dates the switch to github actions? |
@acao haha, weird indeed, I was talking about this comment: #1118 (comment) Maybe GH actions don't run for older PRs. I can create a new PR and replace this one with that. Does that sounds good? |
oh right! i have not restored the codecov behavior in github actions, my bad, forgot to do that! yikes. |
But still, even the tests did not run! 🤔 I see that they are running for other PRs. I will just re-create this one to see if it runs. |
"Workflows in forked repositories don't run by default." via https://help.github.com/en/actions/getting-started-with-github-actions/about-github-actions I couldn't find the docs to enable it though, looking for it. ✅ Green in my fork: https://github.com/divyenduz/graphiql/runs/507245373?check_suite_focus=true Haha! Let me know how to proceed, we can
I would prefer 1 for now, just to get this PR out of the door, it has been looooong living 😄 Update: I think this is how we enable it on forked repos: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-events-for-forked-repositories By adding pull-request as an event to the workflow. But it looks like this doesn't work: https://github.community/t5/GitHub-Actions/Github-Workflow-not-running-from-pull-request-from-forked/td-p/32979 Quickly trying it out in this branch. |
Yes it works! Precioussssss! <3 |
if (this._extensions && this._extensions.length > 0) { | ||
/* eslint-disable no-await-in-loop */ | ||
for (const extension of this._extensions) { | ||
config = await extension(config); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is required here since we do the same thing in the getGraphQLCache
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it, nice, this was a code smell with duplicate code. Moving config to cache solves this 👍
nice work! thanks @divyenduz |
if (extensions && extensions.length > 0) { | ||
/* eslint-disable no-await-in-loop */ | ||
for (const extension of extensions) { | ||
graphQLConfig = await extension(graphQLConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@divyenduz so this is intended to re-declare graphQLConfig
on every invocation? I'm guessing the result of await extension(graphQLConfig)
returns the previous config plus the extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as of now, the signature of an extension is a function that takes a GraphQLConfig as input and returns a GraphQL config as its output with the modification (extension) applied.
extensions?: Array<(config: GraphQLConfig) => GraphQLConfig>
Which implies, extension: (config: GraphQLConfig) => GraphQLConfig
maybe we can update docs, as well? |
https://deploy-preview-1118--graphiql-test.netlify.com/lsp/modules/graphql_language_service_server.html#getgraphqlcache fyi, interesting how tsdoc handles this as |
Added a test, figuring out where the docs live! Does your tsdoc comment mean that we get docs for free (after we fix the array function representation?) or do I need to do something else as well? :) |
@divyenduz good question! let’s put the docs for this in graphql-language-service for now. there will be a doc site soon. the lsp api docs are nice but not instructive enough yet, or fully configured, and the readme’s come with |
@acao Added some docs to the README of |
@acao I did a split of CLI and Server docs as discussed. There is some duplication in the two readme files, please let me know if any further changes are needed :) |
@divyenduz looking great! we are ready to merge then |
This PR is a port of graphql/graphql-language-service#240
It adds GraphQL config extension support to the language server.
This would enable the following scenarios (not-exhaustive):
Gatsby