Thank you for the great article!
Svad
1

Thanks, that’s a great question! Technically, the answer is yes: you could set the owner_id on list, and then pass that back to the user when list.owner is resolved. Something like this:

const mocks = {
User: () => {
const user_id = uuid.v4();
return {
id: () => user_id,
list: () => ({ name: 'A list', owner_id: user_id }),
};
},
List: () => {
return {
owner: (list) => ({ id: list.owner_id }),
};
},
};

However, as you can probably guess, this gets more and more complicated the more relationships you add, so my recommendation for that would be to just create some mock data and insert it into a sqlite database, or something like that. That way, it’s much easier to make sure it works as intended.

Even when you do that, GraphQL still makes mocking very easy, because you could just write a function that takes the GraphQL schema and creates an in-memory database with a few instances of the mocked data.