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(
4747 query : GraphQLObjectType (
4848 name : " RootQueryType" ,
4949 fields : [
50- " hello" : GraphQLFieldConfig (
50+ " hello" : GraphQLField (
5151 type : GraphQLString,
5252 resolve : { _ in " world" }
5353 )
@@ -64,25 +64,47 @@ Then, serve the result of a query against that type schema.
6464``` swift
6565let query = " { hello }"
6666let result = try graphql (schema : schema, request : query)
67-
68- // Prints
69- // {"data":{"hello":"world"}}
7067print (result)
7168```
7269
70+ Output:
71+
72+ ``` json
73+ {
74+ "data" : {
75+ "hello" : " world"
76+ }
77+ }
78+ ```
79+
7380This runs a query fetching the one field defined. The ` graphql ` function will
7481first ensure the query is syntactically and semantically valid before executing
7582it, reporting errors otherwise.
7683
7784``` swift
7885let query = " { boyhowdy }"
7986let result = try graphql (schema : schema, request : query)
80-
81- // Prints
82- // {"errors":[{"message":"Cannot query field "boyhowdy" on type "RootQueryType"."}]}
8387print (result)
8488```
8589
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+
86108## License
87109
88110This project is released under the MIT license. See [ LICENSE] ( LICENSE ) for details.
You can’t perform that action at this time.
0 commit comments