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
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
protected int
The default value for the 'limit' argumentprotected String
The default value for the 'sortBy' argumentprotected String
The default value for the 'sortOrder' argumentprotected org.craftercms.search.opensearch.client.OpenSearchClientWrapper
The instance ofOpenSearchClientWrapper
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFieldFilterFromMapEntry
(String path, Map.Entry<String, Object> filter, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, graphql.schema.DataFetchingEnvironment env) protected void
addFieldFilterFromObjectField
(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.Query
getFilterQueryFromMapEntry
(String fieldPath, Map.Entry<String, Object> filter) protected org.opensearch.client.opensearch._types.query_dsl.Query
getFilterQueryFromObjectField
(String fieldPath, graphql.language.ObjectField filter, graphql.schema.DataFetchingEnvironment env) protected Object
getRealValue
(graphql.language.Value value, graphql.schema.DataFetchingEnvironment env) Extracts a scalar value, this is needed because of GraphQL strict typesprotected 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 fieldvoid
setDefaultLimit
(int defaultLimit) void
setDefaultSortField
(String defaultSortField) void
setDefaultSortOrder
(String defaultSortOrder) void
setSearchClient
(org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClient) Methods 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
public ContentTypeBasedDataFetcher()
-
-
Method Details
-
setDefaultLimit
public void setDefaultLimit(int defaultLimit) -
setDefaultSortField
-
setDefaultSortOrder
-
setSearchClient
public void setSearchClient(org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClient) -
doGet
Performs the actual fetching of the requested fields.- Specified by:
doGet
in 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.
-