-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] subscribeToMore sample code #29
why ์ ํผ๋ ์๋์ ์ํด์ sample code ์์ฑ how subscribeToMore ๋ก ์ ๋ฐ์ดํฐ ๋ฐ์์ data ์ ๋ฐ์๋๋์ง ํ์ธ์ฐจ ์ ์ฉ ์ฃผ์ - subscribeToMore๋ ์๋์ด ์์ ๋ ์ด๋ค ์์ ์ ํ๊ณ ์ถ์ ๋ ์ฌ์ฉ - ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ ๋ฐ๋ก ์ฟผ๋ฆฌ์ ๋ฐ์ดํฐ์ ๋จธ์งํ๊ณ ์ถ์ ๊ฒฝ์ฐ- existing queries are automatically notified ๋์ ๋ฐ์ดํฐ ํํ๊ฐ ๊ฐ์์ผ๋จ!!!
- Loading branch information
1 parent
4065ddf
commit bdab9b4
Showing
5 changed files
with
97 additions
and
31 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
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,63 @@ | ||
import React from 'react'; | ||
import { useQuery, useSubscription } from '@apollo/react-hooks'; | ||
import gql from 'graphql-tag'; | ||
import { OnMount } from './onMount'; | ||
|
||
const FEEDS_SUBSCRIPTION = gql` | ||
subscription { | ||
newUser | ||
} | ||
`; | ||
|
||
const COMMENT_QUERY = gql` | ||
query { | ||
testPubsub | ||
} | ||
`; | ||
|
||
const SusbscriptionTest = () => { | ||
const { data, loading } = useSubscription<{ newUser: string }, {}>( | ||
FEEDS_SUBSCRIPTION, | ||
{} | ||
); | ||
/* const { subscribeToMore, fetchMore, ...result } = useQuery(COMMENT_QUERY, { | ||
variables: {} | ||
}); | ||
// const [testMutation] = useMutation(COMMENT_QUERY, {}); | ||
const subscribeToNewComments = () => { | ||
return subscribeToMore({ | ||
document: FEEDS_SUBSCRIPTION, | ||
variables: {}, | ||
updateQuery: (prev, { subscriptionData }) => { | ||
if (!subscriptionData.data) return prev; | ||
const newFeedItem = subscriptionData.data; | ||
// console.log('new data! -', newFeedItem); | ||
return newFeedItem; | ||
} | ||
}); | ||
}; | ||
const onLoadMore = () => | ||
fetchMore({ | ||
variables: {}, | ||
updateQuery: (prev, { fetchMoreResult }) => { | ||
if (!fetchMoreResult) return prev; | ||
return fetchMoreResult; | ||
} | ||
}); */ | ||
|
||
// return <> lalala </>; | ||
if (!loading) { | ||
console.log(data); | ||
return <> data </>; | ||
} | ||
return ( | ||
<> | ||
New comment: {/* <OnMount onEffect={subscribeToNewComments} /> */} | ||
<div>FETCH</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default SusbscriptionTest; |
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