Class ContentTypeBasedDataFetcher
java.lang.Object
org.craftercms.engine.graphql.impl.fetchers.RequestAwareDataFetcher<Object>
org.craftercms.engine.graphql.impl.fetchers.ContentTypeBasedDataFetcher
- All Implemented Interfaces:
graphql.schema.DataFetcher<Object>
Implementation of
DataFetcher that queries OpenSearch to retrieve content based on a content type.- Since:
- 3.1
- Author:
- joseross
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringprotected intThe default value for the 'limit' argumentprotected StringThe default value for the 'sortBy' argumentprotected StringThe default value for the 'sortOrder' argumentprotected org.craftercms.search.opensearch.client.OpenSearchClientWrapperThe instance ofOpenSearchClientWrapper -
Constructor Summary
ConstructorsConstructorDescriptionContentTypeBasedDataFetcher(int defaultLimit, String defaultSortField, String defaultSortOrder, org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClient) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFieldFilterFromMapEntry(String path, Map.Entry<String, Object> filter, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, graphql.schema.DataFetchingEnvironment env) protected voidaddFieldFilterFromObjectField(String path, graphql.language.ObjectField filter, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, graphql.schema.DataFetchingEnvironment env) doGet(graphql.schema.DataFetchingEnvironment env) Performs the actual fetching of the requested fields.Checks for fields containing the 'item' keyword and makes sure they are always a list even if there is only one value.protected org.opensearch.client.opensearch._types.query_dsl.QuerygetFilterQueryFromMapEntry(String fieldPath, Map.Entry<String, Object> filter) protected org.opensearch.client.opensearch._types.query_dsl.QuerygetFilterQueryFromObjectField(String fieldPath, graphql.language.ObjectField filter, graphql.schema.DataFetchingEnvironment env) protected ObjectgetRealValue(graphql.language.Value value, graphql.schema.DataFetchingEnvironment env) Extracts a scalar value, this is needed because of GraphQL strict typesprotected voidprocessSelection(String path, graphql.language.Selection currentSelection, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, List<String> queryFieldIncludes, graphql.schema.DataFetchingEnvironment env) Adds the required filters to the ES query for the given fieldMethods inherited from class org.craftercms.engine.graphql.impl.fetchers.RequestAwareDataFetcher
get
-
Field Details
-
CONTENT_TYPE_REGEX_PAGE
- See Also:
-
CONTENT_TYPE_REGEX_COMPONENT
- See Also:
-
COMPONENT_INCLUDE_REGEX
- See Also:
-
defaultLimit
protected int defaultLimitThe default value for the 'limit' argument -
defaultSortField
The default value for the 'sortBy' argument -
defaultSortOrder
The default value for the 'sortOrder' argument -
searchClient
protected org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClientThe instance ofOpenSearchClientWrapper
-
-
Constructor Details
-
ContentTypeBasedDataFetcher
-
-
Method Details
-
doGet
Performs the actual fetching of the requested fields.- Specified by:
doGetin classRequestAwareDataFetcher<Object>- Parameters:
env- theDataFetchingEnvironment- Returns:
- the resolved value
- Throws:
IOException
-
processSelection
protected void processSelection(String path, graphql.language.Selection currentSelection, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, List<String> queryFieldIncludes, graphql.schema.DataFetchingEnvironment env) Adds the required filters to the ES query for the given field -
addFieldFilterFromObjectField
protected void addFieldFilterFromObjectField(String path, graphql.language.ObjectField filter, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, graphql.schema.DataFetchingEnvironment env) -
addFieldFilterFromMapEntry
-
getFilterQueryFromObjectField
protected org.opensearch.client.opensearch._types.query_dsl.Query getFilterQueryFromObjectField(String fieldPath, graphql.language.ObjectField filter, graphql.schema.DataFetchingEnvironment env) -
getFilterQueryFromMapEntry
-
getRealValue
protected Object getRealValue(graphql.language.Value value, graphql.schema.DataFetchingEnvironment env) Extracts a scalar value, this is needed because of GraphQL strict types -
fixItems
Checks for fields containing the 'item' keyword and makes sure they are always a list even if there is only one value. This is needed because the GraphQL schema always needs to return the same type for a field.
-