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>

public class ContentTypeBasedDataFetcher extends RequestAwareDataFetcher<Object>
Implementation of DataFetcher that queries OpenSearch to retrieve content based on a content type.
Since:
3.1
Author:
joseross
  • Field Details

    • CONTENT_TYPE_REGEX_PAGE

      public static final String CONTENT_TYPE_REGEX_PAGE
      See Also:
    • CONTENT_TYPE_REGEX_COMPONENT

      public static final String CONTENT_TYPE_REGEX_COMPONENT
      See Also:
    • COMPONENT_INCLUDE_REGEX

      public static final String COMPONENT_INCLUDE_REGEX
      See Also:
    • defaultLimit

      protected int defaultLimit
      The default value for the 'limit' argument
    • defaultSortField

      protected String defaultSortField
      The default value for the 'sortBy' argument
    • defaultSortOrder

      protected String defaultSortOrder
      The default value for the 'sortOrder' argument
    • searchClient

      protected org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClient
      The instance of OpenSearchClientWrapper
  • Constructor Details

    • ContentTypeBasedDataFetcher

      public ContentTypeBasedDataFetcher()
  • Method Details

    • setDefaultLimit

      public void setDefaultLimit(int defaultLimit)
    • setDefaultSortField

      public void setDefaultSortField(String defaultSortField)
    • setDefaultSortOrder

      public void setDefaultSortOrder(String defaultSortOrder)
    • setSearchClient

      public void setSearchClient(org.craftercms.search.opensearch.client.OpenSearchClientWrapper searchClient)
    • doGet

      public Object doGet(graphql.schema.DataFetchingEnvironment env) throws IOException
      Performs the actual fetching of the requested fields.
      Specified by:
      doGet in class RequestAwareDataFetcher<Object>
      Parameters:
      env - the DataFetchingEnvironment
      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

      protected void addFieldFilterFromMapEntry(String path, Map.Entry<String,Object> filter, org.opensearch.client.opensearch._types.query_dsl.BoolQuery.Builder query, graphql.schema.DataFetchingEnvironment env)
    • getFilterQueryFromObjectField

      protected org.opensearch.client.opensearch._types.query_dsl.Query getFilterQueryFromObjectField(String fieldPath, graphql.language.ObjectField filter, graphql.schema.DataFetchingEnvironment env)
    • getFilterQueryFromMapEntry

      protected org.opensearch.client.opensearch._types.query_dsl.Query getFilterQueryFromMapEntry(String fieldPath, Map.Entry<String,Object> filter)
    • 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

      protected Map<String,Object> fixItems(Map<String,Object> map)
      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.