GraphQLObject
public protocol GraphQLObject : AnyObject, ConcreteResolvable, KeyPathListable, OutputResolvable
GraphQLObject
A GraphQL Object is a Class that can be used as an output in GraphQL.
It behaves as follows:
- All properties of types that are
OutputResolvable
(can be outputs in GraphQL) will be added to the Schema. - All methods where all arguments are of types that are
InputResolvable
(can be inputs in GraphQL) and the return type isOutputResolvable
(can be outputs in GraphQL) will be added to the Schema.
Example
If we are implementing a Todo App, a Todo and User in our API would be two classes:
class Author: GraphQLObject {
var name: String
func store() { ... }
func todos() -> [Todo] { ... }
}
class Todo: GraphQLObject {
var title: String
var completed: Bool
func store() { ... }
func author() -> User { ... }
}
The previous code would then be exported to GraphQL like so:
type User {
name: String!
todos: [Todo!]!
}
type Todo {
title: String!
completed: Boolean!
author: User!
}
As can be seen in the example:
- All the properties are scalar values that can be outputs in GraphQL.
- All the properties are included.
- And all the functions that return GraphQL Values are also included
- The store functions return
Void
, which is not a GraphQL Output. These methods are therefore not included.
-
object(from:
Default implementation) Loads object from source.
Warning
default implementation from
GraphZahl
. Do not override unless you know exactly what you are doing.Default Implementation
Warning
default implementation fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
static func object(from source: Any) -> AnyObject
Parameters
source
In most cases it’s just an instance of
Self
, except with Root Types, where it’s an instance of theViewerContext
Return Value
the object that will be used for method dispatching
-
additionalArguments
Extension methodWarning
default implementation fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
public static var additionalArguments: [String : InputResolvable.Type] { get }
-
resolve(using:
Extension method) Warning
default implementation fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
public static func resolve(using context: inout Resolution.Context) throws -> GraphQLOutputType
-
resolve(source:
Extension methodarguments: context: eventLoop: ) Warning
default implementation fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
public func resolve(source: Any, arguments: [String : Map], context: MutableContext, eventLoop: EventLoopGroup) throws -> Output