graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

Plugin: search within description

Open nguyenm100 opened this issue 5 years ago • 9 comments

It would be great to also be able to search the schema by description

nguyenm100 avatar Nov 06 '19 21:11 nguyenm100

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.

benjie avatar Nov 07 '19 08:11 benjie

fair enough. any chance we show the description during the search in the result list? even if just partial (say the first 40 chars + ...)?

nguyenm100 avatar Nov 07 '19 10:11 nguyenm100

^^ @orta some good UX feedback, to note for the redesign

acao avatar Nov 07 '19 18:11 acao

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

acao avatar Nov 26 '19 03:11 acao

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))) {

acao avatar Nov 26 '19 03:11 acao

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.

benjie avatar Dec 10 '19 11:12 benjie

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.

thomasheyenbrock avatar May 09 '22 16:05 thomasheyenbrock

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

lshwayne96 avatar Oct 19 '23 08:10 lshwayne96

search with description was not included in the redesign unfortunately

acao avatar Oct 19 '23 09:10 acao