You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -52,15 +52,15 @@ One of the main design decisions behind Graphiti is **not** to polute your entit
52
52
53
53
#### Defining the context
54
54
55
-
Second step is to create your application's **context**. The context will be passed to all of your field resolver functions. This allows you to apply dependency injection to your API. You will usually use the Context as the state holder of your API. Therefore, this will often be a `class`. We're calling it a store here, because that's the only thing that it does, but you should name it in a way that is appropriate to what your context does.
55
+
Second step is to create your application's **context**. The context will be passed to all of your field resolver functions. This allows you to apply dependency injection to your API. You will usually use the Context as the state holder of your API. Therefore, this will often be a `class`.
56
56
57
57
```swift
58
58
/**
59
59
* This data is hard coded for the sake of the demo, but you could imagine
60
60
* fetching this data from a database or a backend service instead.
61
61
*/
62
-
finalclassMessageStore {
63
-
funcgetMessage() -> Message {
62
+
finalclassMessageContext {
63
+
funcmessage() -> Message {
64
64
Message(content: "Hello, world!")
65
65
}
66
66
}
@@ -75,25 +75,9 @@ Now that we have our entities and context we can create the API itself.
75
75
```swift
76
76
importGraphiti
77
77
78
-
// We make Message adopt Keyable so we can
79
-
// provide keys to be used in the schema.
80
-
// This allows you to have different names between
81
-
// your properties and the fields you expose in the schema.
82
-
extensionMessage : Keyable {
83
-
enumKeys : String{
84
-
casecontent
85
-
}
86
-
}
87
-
88
-
structMessageRoot : Keyable {
89
-
enumKeys : String{
90
-
casegetMessage
91
-
}
92
-
93
-
// The first parameter is the context, you can name it anything you want.
94
-
// We're calling it `store` here because the context type is `MessageStore`.
`API.execute` returns a `GraphQLResult` which adopts `Encodable`. You can use it with a `JSONEncoder` to send the response back to the client using JSON.
@@ -165,17 +149,9 @@ To use async resolvers, just add one more parameter with type `EventLoopGroup` t
0 commit comments