apollo

Query.products is defined in resolvers but not in schema

橙三吉。 提交于 2019-12-11 06:18:36
问题 Hi I defined rootQuery in Customer schema and then in Product schema I extended query. I wrote resolvers for product schema but then I got following error: Error: Query.products defined in resolvers, but not in schema. When I move product queries to customer query definition it works. I dont understand why I'm getting this error. Do I need implement some rootQuery and insert it into typeDefs array and then extend queries in Customer and Product ? Customer schema import CustomerPhoto from ".

apollo client delete from store without mutation

痞子三分冷 提交于 2019-12-11 02:44:26
问题 I need to remove a "record" from the local store by id without using mutation because the server does not support mutations. I have tried to access manually the store like that: delete this.apolloClient.store.getState().apollo.data['1112'] this removes the record but when I ask apollo to fetch the items it goes to the server, like there is no cache. by the way, if instead of removing I just update one of the primitive properties like that : this.apolloClient.store.getState().apollo.data['1112

Apollo-React-GraphQL Mutation

泄露秘密 提交于 2019-12-11 02:38:09
问题 Is it possible to pass an object into a graphQL mutation as variables? let salesDate = { company_id: "abcd", source: "tally", data: { value: "02", date: "2016-17-01" } }; const mutation = gql` mutation addData($data: Object){ addData(data: $data){ data } } `; This is not working and I don't see any way to define an object as a parameter type. 回答1: You have to define a GraphQL input type. Take a look at this cheat sheet. So in your case you have to define a input on the server and use it in

Update Apollo GraphQL cache without using refetchQueries?

耗尽温柔 提交于 2019-12-11 00:27:44
问题 I have a React app accessing GraphQL server with the Apollo Client (version 1.x). There is a server schema that looks like this. type Query { currentShop: Shop } type Shop { id: ID! name: String! products: [Product!]! ...etc } I do have dataIdFromObject defined like this. const dataIdFromObject = o => { if (o.__typename != null && o.id != null) { return `${o.__typename}-${o.id}` } return null } Throughout the app, I am running queries asking for different fields of currentShop . At various

How to use data from readFragment in Apollo?

爷,独闯天下 提交于 2019-12-10 23:37:45
问题 After a login mutation, a jwt token and a user object (id and firstName) are returned and stored in cache (as shown in the image below). I want to retrieve the user informations from the cache by using readFragment and pass it to Layout component. So I've tried to use read Fragment in my Layout component like this : class Layout extends Component { render() { const test = this.props.client.readFragment({ id: 1, // `id` is any id that could be returned by `dataIdFromObject`. fragment: gql`

Apollo: data / mutation prop not passed to component

随声附和 提交于 2019-12-10 21:06:18
问题 I have the following component with a query and a mutation, but my Component does not receive the data and the mutation prop. Am I doing something wrong or missing in my code? The query does get executed though, it's just not passed down. this.props.mutate as well as this.props.data is undefined. class ResetConfirm extends React.Component { static propTypes = { intl: intlShape.isRequired, token: React.PropTypes.string, data: React.PropTypes.shape({ loading: React.PropTypes.bool.isRequired,

React Apollo dynamically create query from state

自古美人都是妖i 提交于 2019-12-10 19:03:56
问题 Heres a model situation I have some fields in my DB lets say color,size,height ... I can fetch and display these fields to user who can choose these fields and they are afterwards set to components state What i want to achieve is to dynamically create GQL query (not query variables) from these fields stored in state Example //import react gql .... class MyComponent extends Component { constructor(props){ super(props) this.state = { fields : [] } } render(){ ... } componentWillMount(){ fetch(.

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

Apollo refetch not rerendering component

霸气de小男生 提交于 2019-12-10 12:45:04
问题 I'm fetching data from a web service using graphql my client code is this import React, { Component } from 'react'; import { Platform, StyleSheet, Text, ActivityIndicator, View, FlatList, TouchableHighlight, TextInput, Button, } from 'react-native'; import PropTypes from 'prop-types'; import { graphql, compose } from 'react-apollo'; import ZONES_QUERY from '../graphql/zones.query' class ZonesScreen extends Component { render() { const { zones, loading, error } = this.props; if (loading) {

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