Code Monkey home page Code Monkey logo

Comments (4)

bruce avatar bruce commented on August 25, 2024 1

I'm closing this as stale / out of scope, as it's really more a question about Relay's JS side (and questions like this are probably better addressed in Slack).

from absinthe_relay.

panayi avatar panayi commented on August 25, 2024

In your example, couldn't you do:

cursor = Connection.offset_to_cursor(length(faction.ships) - 1)

Assuming the new resource is the last one in the collection. Otherwise:

cursor = faction.ships
|> Enum.find_index(fn(x) -> x == ship end)
|> Connection.offset_to_cursor

from absinthe_relay.

hisapy avatar hisapy commented on August 25, 2024

Maybe yes @panayi ... at the moment I was writing the example I believe I didn't know about the function Connection.offset_to_cursor.

Anyway, the idea, based on the Javascript implementation is to return the cursor for the recently added object and thus, I believe your latter suggestion seems more appropriate in case someone else is adding ships to a faction.

from absinthe_relay.

hisapy avatar hisapy commented on August 25, 2024

Hello again.

I have some more questions regarding RANGE_ADD mutation. Suppose I have the following mutation in Relay

import Relay from 'react-relay';

export default class AddMemberMutation extends Relay.Mutation {
  getMutation() {
    return Relay.QL`mutation {addMember}`;
  }

  getVariables() {
    const { member } = this.props;

    return {
      ...member
    };
  }

  getFatQuery() {
    return Relay.QL`
      fragment on AddMemberPayload {
        club { members },
        newMemberEdge,
        errors
      }`;
  }

  getConfigs() {
    return [{
      type: 'RANGE_ADD',
      parentName: 'club',
      parentID: this.props.club.id,
      connectionName: 'members',
      edgeName: 'newMemberEdge',
      rangeBehaviors: {
        '': 'append'
        'status(active)': 'prepend'
      }
    }];
  }
}

I'm trying to understand the following:

a. How do we know the page info to be used to return the Club's membersConnection in the mutation?. For example, Connection.from_query needs some page info like first: 10 to know what "page" to return.
b. Supposing I figured out what connection to return, how can determine the cursor of the newMemberEdge without having to cycle through the edges to find the corresponding member?

from absinthe_relay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.