Add client schema support to vscode extension#1433
Add client schema support to vscode extension#1433JakeDawkins merged 13 commits intoapollographql:masterfrom jasonpaulos:vscode-client-schema
Conversation
There was a problem hiding this comment.
This is looking great! 🙌
From a Relay perspective, it would be great if the default client directives could entirely be overridden and ideally by assigning the SDL (as a string) to the project config–which would make it possible to create a vscode-apollo-relay package which would know how to fetch the SDL for Relay’s directives from the Relay packages. Currently my vscode looks like this:
|
Just did a bit more testing to see if I could at least define all of Relay’s directives by adding a But then if I add the definition of Relay’s |
|
Great feedback @alloy! It's clear to me now that hardcoded definitions of Apollo directives may not be the best choice. I've made some changes so that the Apollo directives are no longer included in the base extension; rather, the extension now includes as a default search path The advantages of this approach are:
And of course, if you override the I'm interested to hear thoughts about this approach and any potential downsides! Edit: looks like some tests are failing because |
|
After discussing with @jbaxleyiii, we concluded that having the extension automatically check for Since it's still very important to allow developers and package authors to configure, override, and include custom client schema like directives, I am currently figuring out a way we can support these processes in the |
|
Sorry for the delay in replying, but moving it to the config file echoes my thoughts entirely 👍 |
Specifically, * Augment the client schema with metadata about which fields/objects are client-only. * Show information about client-only fields on hover. * Add auto complete support for injecting client directives when appropriate. * Add a validation rule to detect missing client directives. * Add a code action to suggest the addition of a clienet directive if it is missing. Also add the ability in general for validation rules to do this. * Add go to definition support for custom client-only directives. * Add information on hover for directives. * Add auto complete support for directives. * Forbid unknown directives.
This reverts commit a24220e.
trevor-scheer
left a comment
There was a problem hiding this comment.
Just some non-blocking nitpicks, this LGTM!
|
(@jasonpaulos Let me know when I should give it another go.) |
|
@alloy Feel free to review this again! Now the extension will add in Apollo directives like |
|
I'm confused why this isn't being built by azure 🤔 |
|
@jasonpaulos checked this on windows, and everything seems to be working properly :) |
|
@alloy any update here? Have you gotten a chance to give it another pass? |
|
I have not. I’ll try to do so later today, but as I’m on holiday I may not get to it and you should just merge. Reading @jasonpaulos’ description it seems like Apollo specific directives may still be auto-completed/recognized in schemas that don’t support those, unless they happen to provide their own copy, is that correct? |
alloy
left a comment
There was a problem hiding this comment.
I had a bit of a problem running the vscode extension directly from the repo (missing apollo-env), so I ended up testing after running npm run-script package-extension. Let me know if that was an unreliable way to test.
-
I think, if I read the source right, that none of the apollo directives get defined if any directive clashes, which seems to work for relay 👍 It still feels a bit odd to me that in other situations the directives do end up getting defined perhaps wrongly–is there no good heuristic for the extension to know when somebody is using apollo server?
-
Was there a 'no unknown directives' validation rule previously, or am I imagining that? Currently I'm able to write any directive in any place and no problems are reported.
-
It is not clear to me how I can provide the directive definitions programatically via the config file, other than specifying a
.graphqlfile that contains them.
|
@alloy thanks for taking the time to review! You are correct that none of the Apollo directives will be defined if there's any name collisions with already defined directives. We want to make the extension as useful as possible for Apollo users, so it made sense for us to always try to include those directives. Perhaps we could introduce a config option to explicitly disable them, like Also, by default the extension does now include the graphql Lastly, the only way to add in extra definitions is by including them in your config like below, which I think is pretty reasonable. var apolloRestSchema = require.resolve('apollo-link-rest/schema.graphql'); // or some other way to get to a file containing SDL
module.exports = {
client: {
name: 'Space Explorer [web]',
service: 'apollographql-8341',
includes: [
'src/**/*.{ts,tsx,js,jsx,graphql,gql}',
apolloRestSchema
]
},
}; |
Had to reclone in order to get a working build again, but after that indeed the
It’s definitely not unreasonable 😄 I’m unsure what other frameworks might do, but Relay doesn’t define all of its directives in graphql files, but rather as strings inside JS modules. For example, here’s the I’m fine going with that as a first version and see how it pans out, though, if you think having a way of specifying such schema extensions as a string would be tough 👍 I just now realised another tougher issue in combination with Relay, which is its The problem with these directives is that their parameters are by definition unknown upfront, which is probably also why I don’t see a solution other than disabling the Having said all that, this all is in no way a blocker for this PR imo, which is looking like a great next step forward for this vscode extension 👏 |
|
(I think the |
* Augment the client schema with metadata about which fields/objects are client-only. * Show information about client-only fields on hover. * Add auto complete support for injecting client directives when appropriate. * Add a validation rule to detect missing client directives. * Add a code action to suggest the addition of a clienet directive if it is missing. Also add the ability in general for validation rules to do this. * Add go to definition support for custom client-only directives. * Add information on hover for directives. * Add auto complete support for directives. * Forbid unknown directives. * Add built-in apollo directives as a fallback
|
Following up on my earlier comments, I was able to make it all work. E.g. here’s a |
|
Hey guys, we've found this commit to be the cause of a huge performance regression in codegen. See #1554 (comment) for more details, hopefully we can improve this approach. |
|
Any thought about putting this back in at some point? |




Specifically,
are client-only.
appropriate.
if it is missing. Also add the ability in general for validation
rules to do this.
Since this update forbids unknown directives from being used, libraries like
apollo-link-restthat provide their own client directives used for links will have to make the extension aware of their directives. This can be done like so (assuming the package comes with aschema.graphqlfile [which none do currently]):To make it easier to use the vscode extension with
apollo-client, the extension has a baked-in copy of its directive definitions which are included if it detects that none of theapollo-clientdirectives are already defined (either from Relay's@connectionor someone including theapollo-clientschema like above). This means that no config changes should be needed for developers who are only usingapollo-client's directives.Fixes #847.
Progress:
KnownDirectivesRulevalidation rule causes more good than harm.apollo-link-restcan add custom client directives (should we bake them into the extension or should they live in their own plugin?)🙅♂ No to baked in directives!Client schema extensions need to be configurable in theapollo.config.jsconfig file.Figure out if I can use permalinks to our docs instead of the current linking in the baked in descriptions of client directives.