diff --git a/README.md b/README.md index 5d420a1..ed03fc8 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ Then add it to your target: ## Usage +To use this package, you must already have a GraphQL schema. You can use [graphql-generator](https://github.com/GraphQLSwift/graphql-generator), [Graphiti](https://github.com/GraphQLSwift/Graphiti), or [GraphQL](https://github.com/GraphQLSwift/GraphQL) to construct one. + +See [the HelloWorld project](https://github.com/GraphQLSwift/graphql-vapor/tree/main/Examples/HelloWorld) for a full working example. + ### Basic Example ```swift @@ -43,7 +47,6 @@ import GraphQLVapor import Vapor // Define your GraphQL schema -// To construct schemas, consider using `Graphiti` or `graphql-generator` let schema = try GraphQLSchema( query: GraphQLObjectType( name: "Query", @@ -100,3 +103,29 @@ app.graphql(schema: schema) { inputs in ) } ``` + +### WebSockets + +Subscription support via WebSockets is provided, and can be enabled by in the `subscriptionProtocols` configuration: + +```swift +app.graphql(schema: schema, config: .init(subscriptionProtocols: [.websocket])) { _ in + GraphQLContext() +} +``` + +[`graphql-ws`](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md) and [`graphql-transport-ws`](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md) subprotocols are supported. + +### Graphiti + +If using Graphiti to build your GraphQL schema, you must provide an instance of the `Resolver` to the `rootValue` argument. For example: + +```swift +let graphqlSchema: Graphiti.Schema = try graphqlSchema() +app.graphql( + schema: graphqlSchema.schema, + rootValue: Resolver() // This must be included +) { _ in + Context() +} +```