relayjs

How to pass total count to the client in pageInfo

流过昼夜 提交于 2019-12-05 03:19:39
I use first after and last before to do pagination. hasNextPage and hasPreviousPage are very useful. But what I need is also the total count so that I can calculate and show things like page 5 of 343 pages on the client. Unfortunately that is not part of pageInfo even though I have the information on the server site. Can you please include a total field in the pageInfo and extend connectionFromArray to take in the total arrayLength like connectionFromArraySlice already does? Thanks pageInfo is designed to represent information about the specific page, whereas the total number of items is

Relayjs Graphql user authentication

懵懂的女人 提交于 2019-12-05 02:21:55
Is it possible to authenticate users with different roles solely trough a graphql server in combination with relay & react? I looked around, and couldn't find much info about this topic. In my current setup, the login features with different roles, are still going trough a traditional REST API... ('secured' with json web tokens). I did it in one of my app, basically you just need a User Interface, this one return null on the first root query if nobody is logged in, and you can then update it with a login mutation passing in the credentials. The main problem is to get cookies or session inside

How to manage cursors and sorting in Relay?

好久不见. 提交于 2019-12-04 23:07:46
问题 We have a graphql server (not written in javascript) serving a paginated list of objects. We're trying to conform to the relay specification, but we've hit an interesting case that could use clarification. Specifically: are cursors allowed to depend on other inputs to the connection? Similar to https://github.com/graphql/graphql-relay-js/issues/20, our connection takes a sort_key argument that determines the sort order of the returned list. Depending on the specified sort order, the edge for

How to fetch and display item by id using Relay container, react-router and GraphQL

倾然丶 夕夏残阳落幕 提交于 2019-12-04 22:00:16
I am having a really hard time trying to get my head around Relay routes, react-router params and building the queries and containers in general! I want to edit a Feature when the user clicks on a specific Feature in a FeatureList. It passes a param called "id" which is the id of the Feature in Route.js <Route path='/' component={AppComponent} queries={ViewerQuery}> <IndexRoute component={FeaturesContainer} queries={ViewerQuery} /> <Route path='/feature' component={FeatureComponent} queries={ViewerQuery} /> <Route path="/feature/edit/:id" component={FeatureEditComponent} queries={FeatureQuery}

Send a Cookie header field in relay request

不羁的心 提交于 2019-12-04 16:51:42
It looks like stock relay networklayer does'nt send a cookie header field with his request. So I tried to add it by adding Cookie field like this: Relay.injectNetworkLayer( new Relay.DefaultNetworkLayer('/graphql', { headers: { 'Cookie': 'user=thibaut', }, }) ); but still the Cookie field is not present in my post request. If I replace 'Cookie' with 'Set-Cookie', IT IS in my post request... I need my server to use cookies please help ! :) Set your cookies in the usual way (using browser APIs) then configure fetch as follows to have them sent along with each request: Relay.injectNetworkLayer(

Union types support in Relay

[亡魂溺海] 提交于 2019-12-04 09:10:21
When you have defined field as an union of two types (in example machines contains Ships and Droid) then in Relay you can do something like that: fragment on Faction@ relay(plural: true) { name, machines { ... on Ship { name } ... on Droid { name, primaryFunction } } } so under machines prop your objects are correctly evaluated, but if you want to do that using fragments from external components: fragment on Faction@ relay(plural: true) { name, machines { ${StarWarsShip.getFragment('ship')} ${StarWarsDroid.getFragment('droid')} } } then you end up with fragment definitions under machines. It

Which relay objects must implement `Node`?

喜夏-厌秋 提交于 2019-12-04 08:18:34
https://facebook.github.io/relay/graphql/objectidentification.htm is very clear around what Node is and how it behaves, but it doesn't specify which objects must implement it, or what the consequences are if your object doesn't implement it. Is there a set of features that don't work? Are such objects completely ignored? Not all objects in the existing spec (e.g. pageInfo ) implement it, so it's clearly not universally required, but pageInfo is somewhat of a special case. Another way of thinking about the Node interface is that objects that implement it are refetchable . Refetchability

When should I use a Relay GraphQL connection and when a plain list?

久未见 提交于 2019-12-04 07:38:39
问题 In Relay GraphQL, connections and lists are both array-like, but they have different features. When should I use each? 回答1: Connections More powerful and flexible than simple lists. Support pagination (forward and back), with cursors. Fine-grained mutation support (eg. RANGE_ADD , RANGE_DELETE , NODE_DELETE , as described in the guide). Requires a first or last argument in order to limit the size of the result set. Has an edges field that provides a place to locate per-edge, edge-specific

Mixing of schema-level and app-level errors in GraphQL

守給你的承諾、 提交于 2019-12-04 06:35:16
While building a new application on top of a graphql API we have run into the following problem: We have a mutation with an input field whose type is a custom scalar with its own validation rules (in this case that the input is a well-formed email address). On the client, the user of the app fills in a bunch of fields and hits submit. Currently, validation of the email address is handled by the GraphQL layer and aborts the mutation if it fails with a top-level error. Validation of all other fields is handled by the mutation, returning app-level errors in the mutation payload. The other

Authentication in Relay & GraphQL

≯℡__Kan透↙ 提交于 2019-12-03 15:01:09
问题 I've been working on an application using react and relay, and now I'm stuck on implementing authentication. I know that you can pass value to each graphql request through the context which is available in GraphQL resolves functions. I'm more confused about what to pass for it and how. Is it better to use JSON Web token, passport, something else? And how should I pass the identifier for the user? Basically what I'm asking, What is best suitable for Relay: jwt, passport, something else? And