react-apollo

What are the differences between Apollo Client and Relay? [closed]

☆樱花仙子☆ 提交于 2019-12-06 07:10:49
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I have just been introduced to GraphQL and am deciding between the two frameworks (Apollo and Relay) for implementing my front end React web app. I'm aware that Relay is built by Facebook, while Apollo is by Meteor. Has anyone tried both and how has your experience been? I'm

Apollo updateQueries Not Called?

有些话、适合烂在心里 提交于 2019-12-06 06:11:36
I'm studying Apollo pub-sub in GitHunt-React and GitHunt-API. When I run those apps and enter a new comment, the comment is saved by the call to submit, and then the updateQueries codeblock runs here: const CommentsPageWithMutations = graphql(SUBMIT_COMMENT_MUTATION, { props({ ownProps, mutate }) { console.log('in CommentsPageWithMutations'); return { submit({ repoFullName, commentContent }) { <==RUNS THE MUTATION debugger; return mutate({ variables: { repoFullName, commentContent }, optimisticResponse: { __typename: 'Mutation', submitComment: { __typename: 'Comment', id: null, postedBy:

How to set up Apollo client only after user authenticates?

倖福魔咒の 提交于 2019-12-06 05:44:49
问题 I'm a bit confused on how to structure my React/GraphQL (Apollo) app when no connection should be made until the user authenticates/logs in. Currently I have this: class App extends Component { render() { return ( <ApolloProvider client={client}> <Provider store={store}> <Router> <div> <ul> <li><Link to="/">Home</Link></li> <li><Link to="/login">Log In</Link></li> <li><Link to="/signup">Sign Up</Link></li> </ul> <AuthenticatedRoute exact path="/" component={HomePage} /> <Route path="/login"

React Apollo 2 with React Router. graphql HOC loading: true forever if I navigate

大憨熊 提交于 2019-12-06 02:15:32
This is the code: https://codesandbox.io/s/p90q6674qq I simply use: export default graphql(CURRENT_USER_QUERY)(Menu); on the Menu component and simply this code in App component: class App extends Component { render() { return ( <div> {/* <Menu /> */} <Route component={Menu} /> <Route exact path="/" component={Home} /> <Route path="/login" component={Login} /> </div> ); } } A bug? Where am I wrong? 来源: https://stackoverflow.com/questions/47733633/react-apollo-2-with-react-router-graphql-hoc-loading-true-forever-if-i-navigat

How do I update the Apollo data store/cache from a mutation query, the update option doesn't seem to trigger

此生再无相见时 提交于 2019-12-05 22:44:21
I have a higher order component in my react native application that retrieves a Profile. When I call an "add follower" mutation, I want it to update the Profile to reflect the new follower in it's followers collection. How do I trigger the update to the store manually. I could refetch the entire profile object but would prefer to just do the insertion client-side without a network refetch. Currently, when I trigger the mutation, the Profile doesn't reflect the change in the screen. It looks like I should be using the update option but it doesn't seem to work for me with my named mutations.

How to refetch a query when a new subscription arrives in react-apollo

自古美人都是妖i 提交于 2019-12-05 12:58:51
I was wondering if there's an elegant way to trigger the refetch of a query in react-apollo when a subscription receives new data (The data is not important here and will be the same as previous one). I just use subscription here as a notification trigger that tells Query to refetch. I tried both using Subscription component and subscribeToMore to call "refetch" method in Query's child component but both methods cause infinite re-fetches. NOTE: I'm using react-apollo v2.1.3 and apollo-client v2.3.5 here's the simplified version of code <Query query={GET_QUERY} variables={{ blah: 'test' }} > {(

apollo-link-state cache.writedata results in Missing field warning

送分小仙女□ 提交于 2019-12-05 02:59:34
When I call a mutation on my client I get the following warning: writeToStore.js:111 Missing field updateLocale in {} This is my stateLink: const stateLink = withClientState({ cache, resolvers: { Mutation: { updateLocale: (root, { locale }, context) => { context.cache.writeData({ data: { language: { __typename: 'Language', locale, }, }, }); }, }, }, defaults: { language: { __typename: 'Language', locale: 'nl', }, }, }); And this is my component: export default graphql(gql` mutation updateLocale($locale: String) { updateLocale(locale: $locale) @client } `, { props: ({ mutate }) => ({

Reactjs/Apollo/AppSync Mutation Optimistic Response Resolved ID

爷,独闯天下 提交于 2019-12-04 21:00:32
So first off I will start by saying I added an optimistic response to my mutation so it would it stop producing duplicates as referenced here and from this previous S.O. question . So that is all working but I have a set of dependant mutations that run after the first using async await. submitForm = async () => { // Only submit if form is complete if (!this.state.saveDisabled) { try { // Optimistic Response is necessary because of AWS AppSync // https://stackoverflow.com/a/48349020/2111538 const createGuestData = await this.props.createGuest({ name: this.state.name, }) let guestId =

Apollo-client (react) - Update on create mutation - “Can't find field Fund({}) on object (ROOT_QUERY)”

一世执手 提交于 2019-12-04 18:09:11
问题 Using: "react-apollo": "^1.4.3" In the parent component I query using GraphQL a parent node 'Fund' with children 'fundQuarterlyMetric'. This returns data in the following format: { id name ... fundQuarterlyMetrics (orderBy: asAtDate_ASC) { id year quarter ... } } When I try to create a new fundQuarterlyMetrics I have to update the local store on react-apollo using the update feature (Apollo Client docs). It gives me an error: Can't find field Fund({}) on object (ROOT_QUERY) { "Fund({\"id\":\

How to pass variables to a GraphQL query?

旧街凉风 提交于 2019-12-04 18:05:31
问题 Lets assume I have the following GraphQL query in React-Apollo const CurrentUserForLayout = gql` query CurrentUserForLayout($avatarID: Int!) { currentUser { avatar_url(avatarID: $avatarID) } } `; const ProfileWithData = graphql(CurrentUserForLayout, { options: { variables: { avatarID: 1 } }, })(Profile); Now if I want to let my React component Profile change the avatarID, how would I do that? I am new to React and GraphQl and I do not really understand the connection here: graphql