Skip to content

Commit

Permalink
Updated the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed May 24, 2023
1 parent 67d21ca commit 252bf79
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,33 @@ export default function Example() {
}
```

## Subscriptions

### With Server-Sent-Events

```
npm i graphql-sse
```

```ts
import { createClient as createSubscriptionsClient } from 'graphql-sse'

export const { useSubscription, ... } = createClient<ClientTypes>({
generatedSchema: createGeneratedSchema(schema),
scalarsEnumsHash: createScalarsEnumsHash(schema),
url: 'http://localhost:4000/graphql',
subscriptionClient: createSubscriptionsClient({
url: process.env.NODE_ENV === 'production' ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}/api/graphql/stream` : 'http://localhost:3000/api/graphql/stream'
})
})
```

## Using the Babel plugin (alpha)

In production, you might want to use the babel plugin in order to replace the runtime dependencies (such as `generatedSchema`, `scalarsEnumsHash`) in your client config with statically-generated artifacts.

**.babelrc**

```json
{
"plugins": [["@garph/gqty/dist/plugin", {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { buildSchema } from 'graphql'
import { createClient } from '../src/index'
import { createGeneratedSchema, createScalarsEnumsHash } from '../src/utils'
import { readFileSync } from 'fs'

const schema = buildSchema(readFileSync('./test/schema.gql', 'utf8'))

createClient({
schema,
generatedSchema: createGeneratedSchema(schema),
scalarsEnumsHash: createScalarsEnumsHash(schema),
url: 'http://localhost:4000/graphql',
})

0 comments on commit 252bf79

Please sign in to comment.