AbstractResourceQuery

public protocol AbstractResourceQuery : ChainableQuery

A base abtract type which holds methods and constructors for all valid queries against resource: i.e. Contentful entries and assets.

KeyPath/Value operations.

  • Static method to create a query which specifies the locale of the entries that should be returned. If there’s no content available for the requested locale the API will try the fallback locale of the requested locale.

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/localization/retrieve-localized-entries

    Declaration

    Swift

    static func localizeResults(withLocaleCode localeCode: LocaleCode) -> Self

    Parameters

    localeCode

    The code for the locale you would like to specify.

    Return Value

    A newly created query with the results restricted to the specified locale.

  • Instance method for further mutating a query which specifies the locale of the entries that should be returned If there’s no content available for the requested locale the API will try the fallback locale of the requested locale.

    See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/localization/retrieve-localized-entries

    Declaration

    Swift

    @discardableResult
    func localizeResults(withLocaleCode localeCode: LocaleCode) -> Self

    Parameters

    localeCode

    The code for the locale you would like to specify.

    Return Value

    A reference to the receiving query to enable chaining.

  • select(fieldsNamed:) Extension method

    Initializes a select operation query in which only the fields specified in the fieldNames property will be returned in the JSON response. The "sys" property is always requested by the SDK. Note that if you are using the select operator with an instance QueryOn<EntryType> that your model types must have optional types for properties that you are omitting in the response (by not including them in your selections array). If you are not using the QueryOn type while querying entries, make sure to specify the content type id. Example usage:

    let query = try! Query.select(fieldsNamed: ["bestFriend", "color", "name"]).where(contentTypeId: "cat")
    client.fetchMappedEntries(with: query).observable z { catsResponse in
        let cats = catsResponse.items
        // Do stuff with cats.
    }
    

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

    Throws

    An error if selections go more than 1 level deep within the fields container (“bestFriend.sys” is not valid), or if more than 99 properties are selected.

    Declaration

    Swift

    static func select(fieldsNamed fieldNames: [FieldName]) throws -> Self

    Parameters

    fieldNames

    An array of field names to include in the JSON response.

    Return Value

    A newly initialized query selecting only certain fields to be returned in the response.

  • select(fieldsNamed:) Extension method

    Instance method for select operation in which only the fields specified in the fieldNames parameter will be returned in the JSON response. The "sys" dictionary is always requested by the SDK. Note that if you are using the select operator with an instance QueryOn<EntryType> that you must make properties that you are ommitting in the response (by not including them in your selections array) optional properties. Example usage:

    let query = try! Query().select(fieldsNamed: ["bestFriend", "color", "name"])
    client.fetchEntries(with: query) { (result: Result<ArrayResponse<Cat>>) in
        switch result {
        case .success(let arrayResponse):
            let cats = arrayResponse.items
            // Do stuff with cats.
        case .failure(let error):
            print(error)
        }
    }
    

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

    Throws

    An error if selections go more than 1 level deep within the fields container (“bestFriend.sys” is not valid), or if more than 99 properties are selected.

    Declaration

    Swift

    @discardableResult
    func select(fieldsNamed fieldNames: [FieldName]) throws -> Self

    Parameters

    fieldNames

    An array of field names to include in the JSON response.

    Return Value

    A reference to the receiving query to enable chaining.