react-apollo

Apollo Query with Variable

馋奶兔 提交于 2019-12-22 04:59:11
问题 Just a basic apollo query request this.client.query({ query: gql` { User(okta: $okta){ id } }` }).then(result => { this.setState({userid: result.data.User}); console.log(this.state.userid.id) }).catch(error => { this.setState({error: <Alert color="danger">Error</Alert>}); }); The question is, how/where to set the $okta variable. Didn't find a solution on Stackoverflow or Google - would be great if someone could help me:) 回答1: It should be something like this: const query = gql` query User(

Missing selection set for object GraphQL+Apollo error

混江龙づ霸主 提交于 2019-12-21 04:18:25
问题 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

How to setState() in React/Apollo with graphQL

不问归期 提交于 2019-12-20 10:57:09
问题 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

Apollo Client Write Query Not Updating UI

拜拜、爱过 提交于 2019-12-19 09:42:15
问题 We are building an offline first React Native Application with Apollo Client. Currently I am trying to update the Apollo Cache directly when offline to update the UI optimistically. Since we offline we do not attempt to fire the mutation until connect is "Online" but would like the UI to reflect these changes prior to the mutation being fired while still offline. We are using the readQuery / writeQuery API functions from http://dev.apollodata.com/core/read-and-write.html#writequery-and

How to disable cache in apollo-link or apollo-client?

こ雲淡風輕ζ 提交于 2019-12-18 11:18:59
问题 I'm using apollo-client , apollo-link and react-apollo , I want to fully disable cache, but don't know how to do it. I read the source of apollo-cache-inmemory , it has a config argument in its constructor, but I can't build a dummy storeFactory to make it works. 回答1: You can set defaultOptions to your client like this: const defaultOptions = { watchQuery: { fetchPolicy: 'no-cache', errorPolicy: 'ignore', }, query: { fetchPolicy: 'no-cache', errorPolicy: 'all', }, } const client = new

How to disable cache in apollo-link or apollo-client?

久未见 提交于 2019-12-18 11:18:32
问题 I'm using apollo-client , apollo-link and react-apollo , I want to fully disable cache, but don't know how to do it. I read the source of apollo-cache-inmemory , it has a config argument in its constructor, but I can't build a dummy storeFactory to make it works. 回答1: You can set defaultOptions to your client like this: const defaultOptions = { watchQuery: { fetchPolicy: 'no-cache', errorPolicy: 'ignore', }, query: { fetchPolicy: 'no-cache', errorPolicy: 'all', }, } const client = new

How to use client.query without JSX components in Apollo Client?

三世轮回 提交于 2019-12-18 08:54:08
问题 I'm trying to make a query in Apollo Client with React without returning a JSX component, just an object (the data object that is received when making a common query to Apollo Server). I tried using <Query /> component, but it returns me a React Node and I only need an object. The documentation only explain methods that return JSX components at some point, when all that I'm looking to do is send a request and process the response in a callback. Actually I'm trying this way (I'm using

How to pass variable to graphql from method when onClick with button and get it's return data back?

落花浮王杯 提交于 2019-12-13 03:29:55
问题 I need to pass asset_type; value to graphql when user click on a button. What is the proper way to do that because currently I'm getting this error: GraphQL error: Illegal value for Message.Field .am.AssetRequest.asset_type of type string: object (proto3 field without field presence cannot be null) This is what I have in my code: import gql from 'graphql-tag'; import { graphql } from 'react-apollo'; constructor(props) { super(props); this.state = { value: '', }; this.handleChange = this

React Nextjs won't compile when using react-apollo

℡╲_俬逩灬. 提交于 2019-12-13 03:10:40
问题 A very strange one here, so if anybody can shed light on it I will be impressed. Good When I use a <h1 /> inside a component and build the server with npm run dev everything will work as expected. I can replace the h1 with the <Query /> component from react-apollo the app reloads correctly and I receive data as I should. Bad However, if I restart the server either manually or with a /server file change. It will just hang indefinitely. return ( <Query query={query}> {({ loading, data, error,

Dynamically set GraphQL queries for React components with Apollo Client

China☆狼群 提交于 2019-12-12 08:13:44
问题 I am building an React front end which allows users to select an "active" query from a list of static queries and flattens to the result to be displayed in a table. What is the best way to pass the GraphQL query from a higher order component into a nested child component? Most of the documentation/solutions that I've seen focus on binding a static query with dynamically conditions from component states to a component, which would not work for my purpose as the different static queries have