react-apollo

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

女生的网名这么多〃 提交于 2019-12-04 14:52:37
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 wondering what are the differences between them and which kind of GraphQL apps would benefit more from using Relay as compared to Apollo. TL;DR: The answer to this question boils down to "it depends". I encourage you to try both GraphQL clients and come up with your own conclusion. Learn Apollo and Learn Relay are great

Missing selection set for object GraphQL+Apollo error

南楼画角 提交于 2019-12-03 13:07:06
I have a set of mutations that trigger the local state of certain types of popups. They're generally set up like this: openDialog: (_, variables, { cache }) => { const data = { popups: { ...popups, dialog: { id: 'dialog', __typename: 'Dialog', type: variables.type } } }; cache.writeData({ data: data }); return null; } And the defaults I pass in look like: const defaults = { popups: { __typename: TYPENAMES.POPUPS, id, message: null, modal: null, menu: null, dialog: null } }; The way they're used in my React code is with a Mutation wrapper component, like so: const OPEN_ALERT_FORM = gql`

How do I handle deletes in react-apollo

十年热恋 提交于 2019-12-03 08:31:57
问题 I have a mutation like mutation deleteRecord($id: ID) { deleteRecord(id: $id) { id } } and in another location I have a list of elements. Is there something better I could return from the server, and how should I update the list? More generally, what is best practice for handling deletes in apollo/graphql? 回答1: I am not sure it is good practise style but here is how I handle the deletion of an item in react-apollo with updateQueries: import { graphql, compose } from 'react-apollo'; import gql

GraphQL - How to respond with different status code?

老子叫甜甜 提交于 2019-12-03 06:04:33
I'm having a trouble with Graphql and Apollo Client. I always created differents responses like 401 code when I using REST but here I don't know how I to do a similar behavior. When I get the response I want it go to the catch function. I have this code in the front: client.query({ query: gql` query TodoApp { todos { id text completed } } `, }) .then(data => console.log(data)) .catch(error => console.error(error)); Can anybody help me? The way to return errors in GraphQL (at least in graphql-js) is to throw errors inside the resolve functions. Because HTTP status codes are specific to the HTTP

React Apollo - Make Multiple Queries

≡放荡痞女 提交于 2019-12-03 03:06:35
问题 I have a queries file that looks like this: import {gql} from 'react-apollo'; const queries = { getApps: gql` { apps { id name } } `, getSubjects: gql` { subjects { id name } } ` }; export default queries; I then import this file to my React component: import React, {Component} from 'react' import queries from './queries' class Test extends Component { ... } export default graphql(queries.getSubjects)(graphql(queries.getApps)(Test)); This will only get data for one of the queries (getApps)

How to setState() in React/Apollo with graphQL

一曲冷凌霜 提交于 2019-12-03 00:42:22
I am trying to setState() to a query result I have from graphQL, but I am having difficulty finding out how to do this because it will always be loading, or it's only used from props. I first set the state constructor (props) { super(props); this.state = { data: [] }; Then I have this query const AllParams = gql` query AllParamsQuery { params { id, param, input } }` And when it comes back I can access it with this.props.AllParamsQuery.params How and when should I this.setState({ data: this.props.AllParamsQuery.params }) without it returning {data: undefined} ? I haven't found a way to make it

React Apollo - Make Multiple Queries

心不动则不痛 提交于 2019-12-02 16:37:50
I have a queries file that looks like this: import {gql} from 'react-apollo'; const queries = { getApps: gql` { apps { id name } } `, getSubjects: gql` { subjects { id name } } ` }; export default queries; I then import this file to my React component: import React, {Component} from 'react' import queries from './queries' class Test extends Component { ... } export default graphql(queries.getSubjects)(graphql(queries.getApps)(Test)); This will only get data for one of the queries (getApps) and not both. If I do one at a time so that it looks like this: export default graphql(queries

Apollo GraphQl Storing derived data

好久不见. 提交于 2019-12-02 14:59:44
问题 Some context : I'm developing a React JS app that reads geographic points out of a database and graphs/maps them in various ways. There are raw maps and plots that just show data straight from the database but there are also plots and metrics that involve analysis on the points like slope plot, area under graph, histograms, Euclidean distance etc. I have a GraphQL client set up to feed me data to my react app with Apollo-Client installed. Here's a sample of the GraphQL response: { "data": {

Apollo GraphQl Storing derived data

六眼飞鱼酱① 提交于 2019-12-02 05:38:34
Some context : I'm developing a React JS app that reads geographic points out of a database and graphs/maps them in various ways. There are raw maps and plots that just show data straight from the database but there are also plots and metrics that involve analysis on the points like slope plot, area under graph, histograms, Euclidean distance etc. I have a GraphQL client set up to feed me data to my react app with Apollo-Client installed. Here's a sample of the GraphQL response: { "data": { "Points": [ { "pid": 13196, "x": 251.88491821289062, "y": 374.1650085449219 }, { "pid": 13197, "x": 257

React Apollo Client not sending cookies

陌路散爱 提交于 2019-12-02 00:13:04
问题 I have tried following the instructions on Apollo Client for sending cookies along with the graphql request, but the express server is not receiving any cookies and when I inspect the request it shows that no cookies are being sent with the response. Following this page: https://www.apollographql.com/docs/react/recipes/authentication.html My code is const link = createHttpLink({ uri: 'http://localhost:3000/api/graphql', opts: { credentials: 'include', } }); const client = new ApolloClient({