Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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<Resolver, Context> = try graphqlSchema()
app.graphql(
schema: graphqlSchema.schema,
rootValue: Resolver() // This must be included
) { _ in
Context()
}
```