Swift GraphQL Handler
A simple handler implementation of GraphQL using Perfect
A simple route with a indexHandler
call when GET
on /graphql
route.
routes.add(method: .get, uri: "/graphql", handler: indexHandler)
Define your schema with RootQueries
, RootMutations
, CustomTypes
e etc...
let UserType = try! GraphQLObjectType(
name: "User",
description: "A user in system",
fields:[
"id": GraphQLField(
type: GraphQLNonNull(GraphQLString),
description: "The id of the user."
),
"name": GraphQLField(
type: GraphQLString,
description: "The name of the user."
),
"email": GraphQLField(
type: GraphQLString,
description: "The email of the user."
),
]
)
In handler you will call the GraphQL parser:
let result = try graphql(schema: schema, request: query)
GraphQL library returns a map
by default, to get a JSON you should use result.description
like @paulofaria
says here:
#1
make run
listen on :8080
http://localhost:8080/graphql?query=query{user(id: "3000"){id,name,email}}
- 0.0.2
- Improve Schema and add sample data
- 0.0.1
- Simple handler with basic schema
Vinicius Souza – @iamvsouza – hi@vsouza.com
Distributed under the MIT license. See License