-
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 pages for query and subscription
- Loading branch information
1 parent
d81aed1
commit e2547e9
Showing
16 changed files
with
312 additions
and
113 deletions.
There are no files selected for viewing
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,23 @@ | ||
import React, { FC } from "react"; | ||
import { Box, useColorMode } from "@chakra-ui/core"; | ||
|
||
const Container: FC = ({ children }) => { | ||
const { colorMode } = useColorMode(); | ||
const bgColor = { light: "gray.100", dark: "gray.900" }; | ||
const heightOfNavbar: string = "74px"; | ||
|
||
return ( | ||
<Box | ||
minH={`calc(100vh - ${heightOfNavbar})`} | ||
p={4} | ||
fontSize="sm" | ||
bg={bgColor[colorMode]} | ||
> | ||
<Box maxW="6xl" mx="auto"> | ||
{children} | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default Container; |
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 React, { FC } from "react"; | ||
import { ColorModeProvider, LightMode } from "@chakra-ui/core"; | ||
import Container from "components/layout/container"; | ||
import Navbar from "components/navbar"; | ||
|
||
const Layout: FC = ({ children }) => { | ||
return ( | ||
<ColorModeProvider> | ||
<LightMode> | ||
<Navbar /> | ||
<Container>{children}</Container> | ||
</LightMode> | ||
</ColorModeProvider> | ||
); | ||
}; | ||
|
||
export default Layout; |
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
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,40 @@ | ||
import React from "react"; | ||
import gql from "graphql-tag"; | ||
import { useQuery } from "urql"; | ||
import { Box, Stack, Text } from "@chakra-ui/core"; | ||
import IUser from "types/user"; | ||
|
||
const usersQuery = gql` | ||
query FetchUsers { | ||
users { | ||
id | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const Query = () => { | ||
const [result] = useQuery({ | ||
query: usersQuery, | ||
}); | ||
|
||
if (result.fetching || !result.data) { | ||
return null; | ||
} | ||
|
||
if (result.error) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Stack spacing={4}> | ||
{result.data.users.map((user: IUser) => ( | ||
<Box key={user.id} p={4} shadow="sm" rounded="md"> | ||
<Text>{user.name}</Text> | ||
</Box> | ||
))} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default Query; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defaultExchanges } from "urql"; | ||
|
||
const graphqlQueryConfig = () => ({ | ||
url: process.env.API_URL || "http://localhost:8080/v1/graphql", | ||
exchanges: [...defaultExchanges], | ||
fetch, | ||
fetchOptions: { | ||
headers: { "X-Hasura-Admin-Secret": "secret" }, | ||
}, | ||
}); | ||
|
||
export default graphqlQueryConfig; |
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,18 @@ | ||
import { defaultExchanges, subscriptionExchange } from "urql"; | ||
import subscriptionClient from "lib/graphql-subscription-client"; | ||
|
||
const graphqlSubscriptionConfig = () => ({ | ||
url: process.env.WS_URL || "ws://localhost:8080/v1/graphql", | ||
exchanges: [ | ||
...defaultExchanges, | ||
subscriptionExchange({ | ||
forwardSubscription(operation) { | ||
return subscriptionClient.request(operation); | ||
}, | ||
}), | ||
], | ||
fetch, | ||
suspense: true, | ||
}); | ||
|
||
export default graphqlSubscriptionConfig; |
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,15 @@ | ||
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 | ||
); | ||
|
||
export default subscriptionClient; |
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
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 React from "react"; | ||
import Head from "next/head"; | ||
import Page from "components/pages/query"; | ||
import { withUrqlClient } from "next-urql"; | ||
import { NextPage } from "next"; | ||
import Loader from "components/loader"; | ||
import AccessDeniedIndicator from "components/access-denied-indicator"; | ||
import { useSession } from "next-auth/client"; | ||
import graphqlQueryConfig from "configs/graphql-query"; | ||
|
||
const QueryPage: NextPage = () => { | ||
const [session, loading] = useSession(); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
if (!session) { | ||
return <AccessDeniedIndicator />; | ||
} | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>People Page</title> | ||
</Head> | ||
<Page /> | ||
</> | ||
); | ||
}; | ||
|
||
export default withUrqlClient(graphqlQueryConfig)(QueryPage); |
Oops, something went wrong.