My problem is quite simple, I need to get different menu functions depending on which type of user is logged in on my app (using react/redux/graphql/apollo).
I have it all working fine, but my graphql query to get the info I need currently looks like this:
const currentUsr = gql`
query getCurrentUser {
getCurrentUser{
firstname,
id_users,
menuItem {
title,
url,
id_parent,
is_parent,
icon,
id_menu_item,
childs {
title,
url,
id_parent,
is_parent,
icon,
id_menu_item,
childs {
title,
url,
id_parent,
is_parent,
icon,
id_menu_item
}
}
}
}
}
`;
It's fairly obvious that I want to use fragments here, to make it look more like this:
my fragment
would be something like
fragment itemInfo{
title,
title,
url,
id_parent,
is_parent,
icon,
id_menu_item
}
and the result I want:
const currentUsr = gql`
query getCurrentUser {
getCurrentUser{
firstname,
id_users,
menuItem {
...itemInfo
childs {
...itemInfo
childs {
...itemInfo
}
}
}
}
}
I can't find a simple explanation on the doc, at least I don't get it right. I don't know if I need to create fragments server or client side, and how to properly do it. Can someone comfortable with graphql/apollo help me out on what to do here? Much appreciated!