简体   繁体   中英

Relay generated mutation query is missing some fields

I have set up a basic Relay mutation to add a user, but once executed it returns this error/warning:

Warning: writeRelayUpdatePayload(): Expected response payload to include the newly created edge 'changedUserEdge' and its 'node' field. Did you forget to update the 'RANGE_ADD' mutation config?

I noticed Relay leaves out the changedUserEdge node on the mutation payload and I have no idea why. I looked at a few Relay examples, but the mutation is constructed exactly the same way.

The mutation, the React component I call it from and the generated query can be found in this gist .

I used graffiti-mongoose to generate my GraphQL schema.

I'm not sure if I will be able to help, what you have in your gist seems fine to me so I think that your issue might be on the server.

The documentation doesn't say it explicitly, but when executing a "RANGE_ADD" kind of mutation Relay expects the edge with the node and the cursor.

The cursor is generated by calling Relay's cursorForObjectInConnection(ArrayOfUsers, User) , where User can be found inside the array by calling ArrayOfUsers.indexOf(User) .

So in our case when adding a user, we call the API to insert it into the database, then we get the list of all users and we execute this to find the right user for the function

// mutation > outputFields > changedUserEdge...

    let selectedUser = allUsers.find(u => u.uuid === newUser.uuid)[0];
    let cursor = cursorForObjectInConnection(allUsers, selectedUser);
    resolve({
        node: selectedUser,
        cursor,
    });

Personally I found this to be the hardest one to implement, but once you got it it's really simple. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM