diff --git a/src/Explorer.js b/src/Explorer.js index 01d8ff6..4afed65 100644 --- a/src/Explorer.js +++ b/src/Explorer.js @@ -2325,7 +2325,35 @@ function Attribution() { ); } +type TypeSearchBarProps = { + onSearch: (string) => void, + value: string, + style?: Object, +}; +class TypeSearchBar extends React.PureComponent { + render() { + return ( +
+ this.props.onSearch(e.target.value)} + style={{ + width: '100%', + fontSize: 12, + padding: '4px 8px', + boxSizing: 'border-box', + border: '1px solid #ccc', + borderRadius: 3, + ...this.props.style, + }} + /> +
+ ); + } +} class Explorer extends React.PureComponent { static defaultProps = { getDefaultFieldNames: defaultGetDefaultFieldNames, @@ -2336,6 +2364,7 @@ class Explorer extends React.PureComponent { newOperationType: 'query', operation: null, operationToScrollTo: null, + typeSearch: '' }; _ref: ?any; @@ -2366,6 +2395,19 @@ class Explorer extends React.PureComponent { el && el.scrollIntoView(); } }; + _setTypeSearch = (value: string) => { + this.setState({ typeSearch: value }); + }; + + // --- Utility to filter type names by search --- + _filterFields = (fields: ?GraphQLFieldMap, search: string) => { + if (!fields) return {}; + if (!search.trim()) return fields; + const lower = search.trim().toLowerCase(); + return Object.keys(fields) + .filter(fieldName => fieldName.toLowerCase().includes(lower)) + .reduce((acc, name) => { acc[name] = fields[name]; return acc; }, {}); + }; render() { const {schema, query, makeDefaultArg} = this.props; @@ -2698,7 +2740,10 @@ class Explorer extends React.PureComponent { const availableFragments = {...documentFragments, ...externalFragments}; const attribution = this.props.showAttribution ? : null; - + const { typeSearch } = this.state; + const filteredQueryFields = this._filterFields(queryFields, typeSearch); + const filteredMutationFields = this._filterFields(mutationFields, typeSearch); + const filteredSubscriptionFields = this._filterFields(subscriptionFields, typeSearch); return (
{ @@ -2717,6 +2762,11 @@ class Explorer extends React.PureComponent { height: '100%', }} className="graphiql-explorer-root"> +
{ ? fragmentType.getFields() : null; - const fields = + let fields = operationType === 'query' - ? queryFields + ? filteredQueryFields : operationType === 'mutation' - ? mutationFields + ? filteredMutationFields : operationType === 'subscription' - ? subscriptionFields + ? filteredSubscriptionFields : operation.kind === 'FragmentDefinition' - ? fragmentFields + ? this._filterFields(fragmentFields, typeSearch) : null; const fragmentTypeName =