relayjs

Pass variables to fragment container in relay modern

淺唱寂寞╮ 提交于 2019-11-30 09:08:20
I'm using Relay Modern (compat). I have a fragment that contains a field that has one argument, but I can't find a way of passing the variable value from the parent component: // MyFragmentComponent.jsx class MyFragmentComponent extends Component {...} const fragments = { employee: graphql` fragment MyFragmentComponent_employee on Employee { hoursWorked(includeOvertime: $includeOvertime) dob fullName id } `, } export default Relay.createFragmentContainer(MyFragmentComponent, fragments) It will end up saying $includeOvertime is not defined. The context where this component is being rendered

Relay mutation expects data fetched by Relay

落花浮王杯 提交于 2019-11-30 08:34:21
I have two Relay mutations that I'm nesting to first add an object then set its name. I believe what I'm passing to the second mutation is in fact data fetched by Relay, but it appears to disagree with me. The code in the React view is as follows: Relay.Store.update( new AddCampaignFeatureLabelMutation({ campaign: this.props.campaign }), { onSuccess: (data) => { Relay.Store.update( new FeatureLabelNameMutation({ featureLabel: data.addCampaignFeatureLabel.featureLabelEdge.node, name: this.addLabelInputField.value }) ); }, onFailure: () => {} } ); This does work, but gives me a warning: Warning:

Authentication and privileges on Relay/GraphQL

不想你离开。 提交于 2019-11-30 08:27:18
Facebook does not mention authentication for their GraphQL library. Suppose I have a users table fetchable from GraphQL and I do not wish to disclose users information to anybody who demands it except the logged in user, at what level should I add the authentication layer ? At the schema level by mutating a "logged-in" state ? Or maybe by passing extra parameters to the graphql function that currently takes only query and schema ? It's possible to add auth header with token to your GraphQL queries. var token = localStorage.getItem('id_token'); Relay.injectNetworkLayer( new Relay

How to get RelayJS to understand that a response from GraphQL is an array of items, not just a single item

对着背影说爱祢 提交于 2019-11-30 07:34:13
I have a GraphQL server running with a schema roughly like this: type Card { id: String! name: String } type Query { card(name: String!): Card cards(power: String): [Card] } Notice that I have a query on a single card, but also on multiple cards. When I use the GraphIQl UI and make a query like this "query {cards { name }}" I get back an array of cards, as expected. However, I have a RelayContainer that is making the same query, but the props that come back are just the first result, rather than an array of results. class MyApp extends React.Component { render() { return ( <div> <h1> Hello

search functionality using relay

本小妞迷上赌 提交于 2019-11-30 07:14:38
问题 How to implement a search functionality with relay? So, the workflow is user navigate to search form . there should not be any query (as in relay container) when initializing the view. user fills the field values, and press the action/search button. a relay query is sent to the server results are received from the server. page displays it and relay reconciles the filtered results with local cache. I have not seen an example of ad hoc query but only part of a relay container (which it resolves

How to get the ID of a new object from a mutation?

懵懂的女人 提交于 2019-11-30 07:03:41
I have a createObject mutation that returns the ID of the new object. After it returns I want to redirect to a detail page about the new object. How can I get response fields from a mutation in the containing component using react/relay? E.g. my createObject page contains the mutation with code like: var onFailure = (transaction) => { }; var onSuccess = () => { redirectTo('/thing/${newthing.id}'); // how can I get this ID? }; // To perform a mutation, pass an instance of one to `Relay.Store.update` Relay.Store.update(new AddThingMutation({ userId: this.props.userId, title: this.refs.title

How would you do file uploads in a React-Relay app?

拈花ヽ惹草 提交于 2019-11-30 06:42:42
A file upload seems like a mutation. It's often accompanied by other data. But it's a big binary blob, so I'm not sure how GraphQL can deal with it. How would you integrate file uploads into an app built with Relay? First you need to write the Relay update in your frontend component. Like this: onDrop: function(files) { files.forEach((file)=> { Relay.Store.commitUpdate( new AddImageMutation({ file, images: this.props.User, }), {onSuccess, onFailure} ); }); }, And then follow by implementing the mutation on the frontend: class AddImageMutation extends Relay.Mutation { static fragments = {

Conditional fragments or embedded root-containers when using Relay with React-Native

↘锁芯ラ 提交于 2019-11-30 04:47:51
问题 I've got relay working with react-native , but I'm confused about how to best utilize relay routes and root containers, especially when working with a Navigator that renders multiple routes. Take the following class: var Nav = React.createClass({ renderScene(route, nav) { switch(route.id) { case 'first': return <First navigator={nav} /> case 'second': return <Second navigator={nav} /> } }, render() { <Navigator initialRoute={{ id: 'first' }} renderScene={this.renderScene} /> } }) module

Relay mutation expects data fetched by Relay

青春壹個敷衍的年華 提交于 2019-11-29 11:52:20
问题 I have two Relay mutations that I'm nesting to first add an object then set its name. I believe what I'm passing to the second mutation is in fact data fetched by Relay, but it appears to disagree with me. The code in the React view is as follows: Relay.Store.update( new AddCampaignFeatureLabelMutation({ campaign: this.props.campaign }), { onSuccess: (data) => { Relay.Store.update( new FeatureLabelNameMutation({ featureLabel: data.addCampaignFeatureLabel.featureLabelEdge.node, name: this

Authentication and privileges on Relay/GraphQL

拜拜、爱过 提交于 2019-11-29 11:47:20
问题 Facebook does not mention authentication for their GraphQL library. Suppose I have a users table fetchable from GraphQL and I do not wish to disclose users information to anybody who demands it except the logged in user, at what level should I add the authentication layer ? At the schema level by mutating a "logged-in" state ? Or maybe by passing extra parameters to the graphql function that currently takes only query and schema ? 回答1: It's possible to add auth header with token to your