relayjs - In a GraphQL/Relay mutation that creates a model, is there a way to get back the model ID? -
we're using relay , graphql in new project.
we've got relay mutation creates new model in db:
export default class addcampaignmutation extends relay.mutation { getmutation() { return relay.ql`mutation { addcampaign }`; } getvariables() { return { type: this.props.campaigntype }; } getfatquery() { return relay.ql` fragment on addcampaignpayload { campaignedge viewer } `; } getconfigs() { return [{ type: 'range_add', parentname: 'viewer', parentid: this.props.viewer.id, connectionname: 'campaigns', edgename: 'campaignedge', rangebehaviors: { '': 'append', }, }]; } static fragments = { viewer: () => relay.ql` fragment on user { id } `, }; }
however, since none of components querying range specified in range_add (viewer { campaigns }
), relay intelligently excludes query addcampaignpayload
.
this results in console warning:
warning: writerelayupdatepayload(): expected response payload include newly created edge `campaignedge` , `node` field. did forget update `range_add` mutation config?
i want id of newly created model, can navigate client it. example, getting new campaignedge
, want send client /campaigns/${campaignedge.node.id}
.
is there way tell relay fetch edge? have configured mutation correctly?
you can use required_children
in context. more details, see https://github.com/facebook/relay/issues/237 , https://github.com/facebook/relay/issues/236.
required_children
lets specify data dependency pattern.
Comments
Post a Comment