ChainableQuery
public protocol ChainableQuery : AbstractQuery
Protocol which enables concrete query implementations to be ‘chained’ together so that results
can be filtered by more than one Query.Operation or other query. Protocol extensions give default implementation
so that all concrete types, Query, AssetQuery, FilterQuery, and QueryOn<EntryType>, can use the same implementation.
-
where(sys:Extension method_: ) Instance method for appending a
Query.Operationto aQuery. This variation for creating a query guarantees correct query construction when performing operations on “sys” members. See concrete typesQuery,FilterQuery,AssetQuery, andQueryOnfor more information and example usage.Declaration
Parameters
keyThe
Sys.CodingKeyof the system property you are performing the Query.Operation against. For instance,.id.operationThe query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(metadata:Extension method_: ) Instance method for appending a
Query.Operationto aQuery. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete typesQuery,FilterQuery,AssetQuery, andQueryOnfor more information and example usage.Declaration
Parameters
keyThe
Metadata.CodingKeyof the system property you are performing the Query.Operation against. For instance,.tags.operationThe query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(metadataTagsIds:Extension method) Instance method for appending a
Query.Operationto aQuery. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete typesQuery,FilterQuery,AssetQuery, andQueryOnfor more information and example usage.Declaration
Swift
@discardableResult func `where`(metadataTagsIds operation: Query.Operation) -> SelfParameters
metadataTagsIdsThe query operation used in the query against metadata tags ids.
Return Value
A reference to the receiving query to enable chaining.
-
where(field:Extension method_: ) Static method for creating a Query with a Query.Operation. This variation for creating a query guarantees correct query contruction when performing operations on “sys” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.
Declaration
Parameters
fieldNameThe string name of the field that the
Query.Operationis matching against. For instance, “.name”operationThe query operation used in the query.
Return Value
A newly initialized query.
-
where(field:Extension method_: ) Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query contruction when performing operations on “field” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.
Declaration
Parameters
fieldNameThe string name of the field that the
Query.Operationis matching against. For instance, “name”operationThe query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(valueAtKeyPath:Extension method_: ) Instance method for appending more
Query.Operations to further filter results on the API. Example usage:let query = Query.where(contentTypeId: "cat").where("fields.color", .doesNotEqual("gray")) // Mutate the query further. query.where(valueAtKeyPath: "fields.lives", .equals("9"))Declaration
Swift
@discardableResult func `where`(valueAtKeyPath keyPath: String, _ operation: Query.Operation) -> SelfParameters
keyPathThe key path for the property you are performing the Query.Operation against. For instance,
"sys.id" or“fields.yourFieldName”`.operationThe query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
searching(for:Extension method) Convenience initializer for querying entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Throws
AQueryErrorif the text being searched for is 1 character in length or less.Declaration
Swift
static func searching(for text: String) throws -> SelfParameters
textThe text string to match against.
Return Value
A newly initialized query.
-
searching(for:Extension method) Instance method for appending a full-text search query to an existing query. Returned results will contain either entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Throws
AQueryErrorif the text being searched for is 1 character in length or less.Declaration
Swift
@discardableResult func searching(for text: String) throws -> SelfParameters
textThe text string to match against.
Return Value
A reference to the receiving query to enable chaining.
-
include(_:Extension method) Static method for specifiying the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will limit the includes level at 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.
Declaration
Swift
static func include(_ includesLevel: UInt) -> SelfParameters
includesLevelAn unsigned integer specifying the level of includes to be resolved.
Return Value
A newly constructed query object specifying the level of includes to be linked.
-
include(_:Extension method) Specify the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will round down to the 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.
Declaration
Swift
@discardableResult func include(_ includesLevel: UInt) -> SelfParameters
includesLevelAn unsigned integer specifying the level of includes to be resolved.
Return Value
A reference to the receiving query to enable chaining.
-
skip(theFirst:Extension method) Static method for creating a query that specifies that the first
nitems in a collection should be skipped before returning the results. Use in conjunction with thelimit(to:)andorder(by:)methods to paginate responses.Example usage:
let query = Query.skip(theFirst: 9)Declaration
Swift
static func skip(theFirst numberOfResults: UInt) -> SelfParameters
numberOfResultsThe number of results that will be skipped in the query.
Return Value
A newly constructed query object specifying the number of items to skip.
-
skip(theFirst:Extension method) Instance method for further mutating a query to skip the first
nitems in a response. Use in conjunction with thelimit(to:)andorder(by:)methods to paginate responses.Example usage:
let query = Query().skip(theFirst: 10)Declaration
Swift
@discardableResult func skip(theFirst numberOfResults: UInt) -> SelfParameters
numberOfResultsThe number of results that will be skipped in the query.
Return Value
A reference to the receiving query to enable chaining.
-
order(by:Extension method) Convenience initializer for a ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.
Example usage:
let query = try! Query(orderBy: OrderParameter("sys.createdAt"))See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters
Declaration
Swift
static func order(by order: Ordering...) -> SelfParameters
orderThe specified
Ordering.Return Value
A newly constructed query object specifying the order of the results.
-
order(by:Extension method) Instance method for ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.
Example usage:
let query = try! Query().order(by: Ordering(sys: .createdAt))See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters
Declaration
Swift
@discardableResult func order(by order: Ordering...) -> SelfParameters
orderThe specified Ordering.
Return Value
A reference to the receiving query to enable chaining.
-
limit(to:Extension method) Static method for creating a query that limits responses to a certain number of values. Use in conjunction with the
skipmethod to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will limit your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API.Example usage:
let query = Query.limit(to: 10)Declaration
Swift
static func limit(to numberOfResults: UInt) -> SelfParameters
numberOfResultsThe number of results the response will be limited to.
Return Value
A newly constructed query object specifying the number of resuls to be returned.
-
limit(to:Extension method) Instance method for further mutating a query to limit responses to a certain number of values. Use in conjunction with the
skipmethod to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will truncate your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API. Use in conjunction with theskip(theFirst:)andorder(by:)methods to paginate responses. Example usage:let query = try! Query().limit(to: 10)Declaration
Swift
@discardableResult func limit(to numberOfResults: UInt) -> SelfParameters
numberOfResultsThe number of results the response will be limited to.
Return Value
A reference to the receiving query to enable chaining.
View on GitHub
ChainableQuery Protocol Reference