-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds separate components for query and subscription
- Loading branch information
1 parent
50c73dd
commit 252675e
Showing
7 changed files
with
57 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createClient, Provider } from "urql"; | ||
import fetch from "isomorphic-unfetch"; | ||
|
||
const client = createClient({ | ||
url: process.env.API_URL || "http://localhost:8080/v1/graphql", | ||
fetch, | ||
fetchOptions: { | ||
headers: { "X-Hasura-Admin-Secret": "secret" }, | ||
}, | ||
requestPolicy: "cache-and-network", | ||
}); | ||
|
||
const WithGraphQLQuery = ({ children }: any) => ( | ||
<Provider value={client}>{children}</Provider> | ||
); | ||
|
||
export default WithGraphQLQuery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Client, defaultExchanges, subscriptionExchange, Provider } from "urql"; | ||
import { SubscriptionClient } from "subscriptions-transport-ws"; | ||
import ws from "isomorphic-ws"; | ||
|
||
const subscriptionClient = new SubscriptionClient( | ||
process.env.WS_URL || "ws://localhost:8080/v1/graphql", | ||
{ | ||
reconnect: true, | ||
connectionParams: { | ||
headers: { "X-Hasura-Admin-Secret": "secret" }, | ||
}, | ||
}, | ||
ws | ||
); | ||
|
||
const client = new Client({ | ||
url: process.env.WS_URL || "ws://localhost:8080/v1/graphql", | ||
exchanges: [ | ||
...defaultExchanges, | ||
subscriptionExchange({ | ||
forwardSubscription(operation) { | ||
return subscriptionClient.request(operation); | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
const WithGraphQLSubscription = ({ children }: any) => ( | ||
<Provider value={client}>{children}</Provider> | ||
); | ||
|
||
export default WithGraphQLSubscription; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters