Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested create Mutation #1407

Closed
timsuchanek opened this issue Oct 4, 2016 · 1 comment
Closed

Nested create Mutation #1407

timsuchanek opened this issue Oct 4, 2016 · 1 comment
Labels

Comments

@timsuchanek
Copy link

Hi, I have this nested create mutation with my graphql backend:

mutation {
  createPost(input: {
    imageUrl: "http://lorempixel.com/400/400"
    description: "hello"
    clientMutationId: "asd"
    extra: {
      text: "extra text"
    }
  }) {
    edge {
      node {
        id
        description
        imageUrl
        extra {
          text
        }
      }
    }
  }
}

Each post has one Extra model, that just contains a text.
Now my question:
Does relay update the local representation of model B properly if I create B nested in A in one create mutation?

Thanks!

@wincent
Copy link
Contributor

wincent commented Jan 31, 2017

Thanks for the question, @timsuchanek!

This seems like the sort of thing that you could confirm by testing. Without running it myself, I believe the answer is "probably"; it may depend on whether the object at extra has an id and whether it is already in the store. If not, it's possible that you could use REQUIRED_CHILDREN to force an arbitrary set of fields to be fetched, although you would be responsible for doing something with the data in the mutation callback.

However, one thing to bear in mind is that the former Relay mutation API is now considered "legacy". We have a new, static mutation API (Relay.GraphQLMutation) that you can use to force fetching of exactly the data you require for a given mutation without any of the magic and inference of fat and tracked queries. Additionally, we're rolling out an even newer API built on top of a new core (see recent work on the master branch, and further pieces that we'll be merging in over the coming weeks/months); all of this is static too, so moving to Relay.GraphQLMutation right now is a worthwhile incremental step.

Going to close this for now. Please comment again if you have anything further to add. For questions, we'd also encourage you to use a purpose-built Q&A forum like Stack Overflow, and use the tag #relayjs? You're morel likely to get a timely response, and others are more likely to find it there too. If you do, post a link to your Stack Overflow question here, so that others can benefit from it if they stumble across this.

@wincent wincent closed this as completed Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants