graphql / graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
MIT License
16.13k stars 1.73k forks source link

Plugin[LSP]: selectively prefill arguments on auto-complete #1125

Open benjie opened 4 years ago

benjie commented 4 years ago

For example when autocompleting a Relay connection allFilms we could make it so that it auto-completes to allFilms(first: 10) to ensure that pagination limits are hinted. Needs thought on how this would actually work, but it'd be nice if our plugin system was capable of allowing someone to implement this.

acao commented 4 years ago

is it a required argument value? it could be like with required fields, where required arguments are automatically presented by default. i think the capability exists to extend the lsp this way somewhat. you can add additional validation rules to the lsp to say that arguments are required for specific fields or all fields with arguments. we dont have a way to extend code completion much yet. the code in monaco to add completion items is trivial, and usually i just pass the fieldname of the completion item, but you could do a lookup there real quick and have the completion replacement token include arguments. so you would choose allFilms from the dropdown, and it would automatically be added with required arguments

acao commented 4 years ago

if they arent required then it would make sense as a plugin that different frameworks could use. Ill add it to the core plugins list

benjie commented 4 years ago

They're not required; specifically with Relay cursor pagination you may specify first or last or neither. However it's best practices to ensure that you have added a pagination limit (you don't want to pull down thousands of records, for example); so it would be nice to have an opt-in plugin that automatically adds a limit to remind the programmer they should set that value (or replace it with last: 10 or whatever).