react-apollo

Apollo duplicates first result to every node in array of edges

霸气de小男生 提交于 2019-12-10 13:13:59
问题 I am working on a react app with react-apollo calling data through graphql when I check in browser network tab response it shows all elements of the array different but what I get or console.log() in my app then all elements of array same as the first element. I don't know how to fix please help 回答1: Put this in your App.js cache: new InMemoryCache({ dataIdFromObject: o => o.id ? `${o.__typename}-${o.id}` : `${o.__typename}-${o.cursor}`, }) 回答2: The reason this happens is because the items in

React-Apollo Mutation returns empty response

帅比萌擦擦* 提交于 2019-12-10 12:44:31
问题 I am using AWS Appsync where I want to get a response from a successfully executed mutation. When I try my setup in the Appsync Graphql console I get a filled "data": { "mutateMeeting" } response: When I try the same in my react application I can see in the dynamodb database, that the mutations happen, but react-apollo does not return the mutation response. As you can see in the apollo dev tool, the "data": { "mutateMeeting" } is null : What am I missing? The corresponding graphql schema

Pass variable from input to GraphQL search call

时间秒杀一切 提交于 2019-12-10 12:41:56
问题 I am in the process of learning graphql and react-apollo. I have set up a search query in my code. I am unsure how to pass a variable from my code (i.e. this.state.search ) to my grapnql call. I have looked at many answers including this one, but it seems a bit different. The docs also don't seem to give any guidance on how to use state as the variable. My code is below. Can anyone advise how to connect both of these? import React, { Component} from 'react' import { graphql } from 'react

Apollo Optimistic UI does not work in Mutation Component?

Deadly 提交于 2019-12-10 12:29:14
问题 I am using <Mutation /> component which has Render Prop API & trying to do Optimistic Response in the UI. So far I have this chunk in an _onSubmit function - createApp({ variables: { id: uuid(), name, link }, optimisticResponse: { __typename: "Mutation", createApp: { __typename: "App", id: negativeRandom(), name, link } } }); And my <Mutation /> component looks like - <Mutation mutation={CREATE_APP} update={(cache, { data: { createApp } }) => { const data = cache.readQuery({ query: LIST_APPS

Using Apollo's MockedProvider why don't the component's props get populated with result?

自古美人都是妖i 提交于 2019-12-10 10:22:52
问题 Following some ideas from this Gist, I am unable to get a component test to work as expected. Everything seems to work except the props never get populated with the data from the response. Any reason why this isn't working as I expect it to? Here is the simplest real-world example I could make based on an existing component: // test-component.js import React from 'react'; import { graphql } from 'react-apollo'; import userQuery from './userQuery.graphql'; function TestComponent (props) {

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

落花浮王杯 提交于 2019-12-10 06:06:30
问题 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

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

守給你的承諾、 提交于 2019-12-10 04:06:46
问题 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

Reset store after logout with Apollo client

狂风中的少年 提交于 2019-12-09 17:59:02
问题 I'm trying to reset the store after logout in my react-apollo application. So I've created a method called "logout" which is called when I click on a button (and passed by the 'onDisconnect' props). To do that I've tried to follow this example : https://www.apollographql.com/docs/react/recipes/authentication.html But in my case I want LayoutComponent as HOC (and it's without graphQL Query). Here is my component : import React, {Component} from 'react'; import { withApollo, graphql } from

How to chain together Mutations in apollo client

﹥>﹥吖頭↗ 提交于 2019-12-09 00:42:12
问题 I have a bunch of information stored in my state that I need to pass to my graphQL server using mutations, but I need to use the results of each mutation before I call the next one since I need to: Create a new object in my database Use the id generated for that object to create another object Modify the original object to store the id generated by the second object I noticed that apollo Mutation components have an onCompleted callback, but I don't know how to use this callback to fire off

Remove unnecessary fields before mutation in GraphQL

泄露秘密 提交于 2019-12-08 17:32:06
问题 I've got a type called Article in my schema: type Article { id: ID! updated: DateTime headline: String subline: String } For updates to it, there's a corresponding input type that is used by a updateArticle(id: ID!, article: ArticleInput!) mutation: input ArticleInput { headline: String subline: String } The mutation itself looks like this: mutation updateArticle($id: ID!, $article: ArticleInput!) { updateArticle(id: $id, article: $article) { id updated headline subline } } The article is