QueryOn

public final class QueryOn<EntryType>: ChainableQuery where EntryType: EntryModellable

A concrete implementation of AbstractQuery which requires that a model class conforming to EntryType be passed in as a generic parameter.

The content_type parameter of the query will be set to the contentTypeID of your EntryType conforming model class. QueryOn<EntryType> are chainable so complex queries can be constructed. Operations that are only available when querying Entrys on specific content types (i.e. content_type must be set) are available through this class.

  • The parameters dictionary that are converted to URLComponents (HTTP parameters/arguments) on the HTTP URL. Useful for debugging.

    Declaration

    Swift

    public var parameters: [String: String] = [String: String]()
  • Designated initializer for QueryOn<EntryType>.

    Declaration

    Swift

    public init()
  • Convenience intializer for creating a QueryOn with a QueryOperation. Example usage:

    let query = QueryOn<Cat>(where: "fields.color", .doesNotEqual("gray"))
    

    Declaration

    Swift

    public convenience init(where name: String, _ operation: QueryOperation, for locale: String? = nil)

    Parameters

    name

    The name of the property you are performing the QueryOperation against. For instance, "sys.id" or "fields.yourFieldName"

    operation

    The QueryOperation.

    locale

    An optional locale argument to return localized results. If unspecified, the locale originally set on the Client instance is used.

  • Instance method for appending more QueryOperation’s to further filter results on the API. Example usage:

    let query = QueryOn<Cat>(where: "fields.color", .doesNotEqual("gray"))
    
    // Mutate the query further.
    query.where("fields.lives", .equals("9"))
    

    Declaration

    Swift

    public func `where`(_ name: String, _ operation: QueryOperation, for locale: String? = nil)

    Parameters

    name

    The name of the property you are performing the QueryOperation against. For instance, "sys.id" orfields.yourFieldName`

    operation

    the QueryOperation

    locale

    An optional locale argument to return localized results. If unspecified, the locale originally set on the Client instance is used.

  • Convenience initalizer for performing searches where Linked objects at the specified linking field match the filtering query. For instance, if you want to query all Entry’s of type cat where cat’s linked via the bestFriend field have names that match Happy Cat the code would look like the following:

    let filterQuery = FilterQuery<Cat>(where: "fields.name", .matches("Happy Cat"))
    let query = QueryOn<Cat>(whereLinkAt: "bestFriend", matches: filterQuery)
    client.fetchMappedEntries(with: query).observable.then { catsWithHappyCatAsBestFriendResponse in
       let catsWithHappyCatAsBestFriend = catsWithHappyCatAsBestFriendResponse.items
       // Do stuff with catsWithHappyCatAsBestFriend
    }
    

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references

    Declaration

    Swift

    public convenience init<LinkType>(whereLinkAt fieldNameForLink: String, matches filterQuery: FilterQuery<LinkType>? = nil,
                                for locale: String? = nil) where LinkType: EntryModellable

    Parameters

    fieldNameForLink

    The name of the property which contains a link to another Entry.

    filterQuery

    The optional filter query applied to the linked objects which are being searched.

    locale

    An optional locale argument to return localized results. If unspecified, the locale originally set on the Client instance is used.