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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ 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-hummingbird/tree/main/Examples/HelloWorld) for a full working example.

### Basic Example
Expand All @@ -45,7 +47,6 @@ import GraphQLHummingbird
import Hummingbird

// 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 @@ -141,6 +142,22 @@ let app = Application(

The example above follows Hummingbird best practices when it uses a separate router for HTTP and WebSocket requests. For more details, see the [Hummingbird WebSocket documentation](https://docs.hummingbird.codes/2.0/documentation/hummingbird/websocketserverupgrade#Overview).

[`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()
router.graphql(
schema: graphqlSchema.schema,
rootValue: Resolver() // This must be included
) { _ in
Context()
}
```

### Custom Encoding/Decoding

You can set custom encoders and decoders using the `Config.coders` argument:
Expand Down