graphiql
graphiql copied to clipboard
Plugin: search within description
It would be great to also be able to search the schema by description
This could make a good plugin for the new GraphiQL. I'd be hesitant to add it to the default GraphiQL because some of the schemas GraphiQL has to deal with are humumgous and so searching over descriptions as well as fields/types could be a performance issue.
fair enough. any chance we show the description during the search in the result list? even if just partial (say the first 40 chars + ...)?
^^ @orta some good UX feedback, to note for the redesign
so, i think this could be accomplished by fuse.js, and there was some debate about it on graphql twitter today.
it could also be accomplished more simply by regexing both the name and the description using the existing pattern we are using just for name. i think components/DocExplorer/SearchResults.js needs a good rewrite overall, so that will happen as part of the doc explorer plugin
this is actually possible with a very small change, however this change would likely slow down search noticably. the choice of whether to accomplish this with a proper indexed search or otherwise stands.
on line 58 of SearchResults component, change:
const type = typeMap[typeName];
if (withinType !== type && isMatch(typeName, searchValue)) {
to
const type = typeMap[typeName];
const description = typeMap[typeName].description
if (withinType !== type && (isMatch(typeName, searchValue) || description && isMatch(description, searchValue))) {
I don't think that solution would work well with the current isMatch
function primarily because searching for a 100% match on a type name is different to searching for matches in prose. Instead I'd concatenate the searchable text typeName + ' ' + description
and then split the search terms on word boundaries and perform the matching per search term. Doing so, however, would definitely be a lot slower than the current search and so would likely need indexed search as you say.
The new docs explorer planned in #2327 will also return result based on descriptions when searching, so this will be built into GraphiQL without needing a plugin for it.
Hi, may I know if the latest version 3.0.6
supports searching within description in the docs explorer?
I tested with the API linked below but the search does not seem to pick up field descriptions.
https://swapi-graphql.netlify.app/.netlify/functions/index
search with description was not included in the redesign unfortunately