File tree Expand file tree Collapse file tree 1 file changed +29
-7
lines changed Expand file tree Collapse file tree 1 file changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ let schema = try GraphQLSchema(
47
47
query : GraphQLObjectType (
48
48
name : " RootQueryType" ,
49
49
fields : [
50
- " hello" : GraphQLFieldConfig (
50
+ " hello" : GraphQLField (
51
51
type : GraphQLString,
52
52
resolve : { _ in " world" }
53
53
)
@@ -64,25 +64,47 @@ Then, serve the result of a query against that type schema.
64
64
``` swift
65
65
let query = " { hello }"
66
66
let result = try graphql (schema : schema, request : query)
67
-
68
- // Prints
69
- // {"data":{"hello":"world"}}
70
67
print (result)
71
68
```
72
69
70
+ Output:
71
+
72
+ ``` json
73
+ {
74
+ "data" : {
75
+ "hello" : " world"
76
+ }
77
+ }
78
+ ```
79
+
73
80
This runs a query fetching the one field defined. The ` graphql ` function will
74
81
first ensure the query is syntactically and semantically valid before executing
75
82
it, reporting errors otherwise.
76
83
77
84
``` swift
78
85
let query = " { boyhowdy }"
79
86
let result = try graphql (schema : schema, request : query)
80
-
81
- // Prints
82
- // {"errors":[{"message":"Cannot query field "boyhowdy" on type "RootQueryType"."}]}
83
87
print (result)
84
88
```
85
89
90
+ Output:
91
+
92
+ ``` json
93
+ {
94
+ "errors" : [
95
+ {
96
+ "locations" : [
97
+ {
98
+ "column" : 3 ,
99
+ "line" : 1
100
+ }
101
+ ],
102
+ "message" : " Cannot query field \" boyhowdy\" on type \" RootQueryType\" ."
103
+ }
104
+ ]
105
+ }
106
+ ```
107
+
86
108
## License
87
109
88
110
This project is released under the MIT license. See [ LICENSE] ( LICENSE ) for details.
You can’t perform that action at this time.
0 commit comments