GraphQLRootType
public protocol GraphQLRootType : GraphQLObject
GraphQL Root Type
An GraphQL Object that is at the Root of a Schema. Can either be a Query Type or a Mutation Type
The only additional requirement for a GraphQLType
is that it can be initialized with a ViewerContext
.
The ViewerContext
in this scenario refers to a Context Object, that tells the Query/Mutation Type what it needs to know about the User who is requesting the data.
Example
If we are building a Todo App and want allow users to request their Todos. We can use the User as a ViewerContext
class Query: GraphQLRootType {
let user: User
func myTodos() -> [Todo] { ... }
init(viewerContext user: User) {
self.user = user
}
}
This is then translated into:
type Query {
myTodos: [Todo!]!
}
-
Type that tells the Query/Mutation type everything about the User. This defaults to Void, to signal that all requests are treated the same, and this API does not compute anything different on a by user basis.
Declaration
Swift
associatedtype ViewerContext = Void
-
Initializes the type based on the Viewer Context.
Declaration
Swift
init(viewerContext: ViewerContext)
Parameters
viewerContext
Viewer Context for this Type
-
object(from:
Extension method) Warning
default implementation fromGraphZahl
. Do not override unless you know exactly what you are doing.Declaration
Swift
public static func object(from source: Any) -> AnyObject