GraphQLInputObject

public protocol GraphQLInputObject : ConcreteResolvable, InputResolvable, KeyPathListable, ValueResolvable

GraphQLInputObject

A GraphQL Input Object is a Struct that can be used as an input for a method.

Example

If want to provide an API for sorting search results. We can create a struct for those options.

enum Order: String, CaseIterable, GraphQLEnum {
   case ascending
   case descending
}

struct SortOptions: GraphQLInputType {
   let field: KeyPath<SearchResult, Int>
   let order: Order
}

class Query: QueryType {
   func search(term: String, sortOptions: SortOptions?) -> [SearchResult] {
       ...
   }
}

Note

Input types can be useful to group arguments. We can also use them to group arguments that should always be provided together. Like in our search example, we don’t need the user to specify how to sort. But when the user wants the Results sorted by a field, we need to know if they should be sorted in an ascending or descending order. That’s why the Input Object makes sense in this scenario.

Details

  • A GraphQL Input Object is Input Resolvable and can be used in any method that should be available in GraphQL
  • An Input Object has to be a struct. If it’s not a struct, an error will be thrown.
  • All the properties in the struct have to be Input Resolvable as well. Otherwise an error will be thrown.
  • resolve(using:) Extension method

    Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public static func resolve(using context: inout Resolution.Context) throws -> GraphQLInputType
  • create(from:) Extension method

    Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public static func create(from map: Map) throws -> Self
  • map() Extension method

    Warning

    default implementation from GraphZahl. Do not override unless you know exactly what you are doing.

    Declaration

    Swift

    public func map() throws -> Map