Search code examples
graphqlreact-apolloapollo-clientapollostack

GraphQL query, use fragment depending on some condition. GraphQL file loaded


There is a task to request different fields of an object depending on role. Let's say administrator can view one set of metrics. Other users can see another set of metrics. The task is to request only metrics that can be viewed by the user. React application is using graphQL file loader and it should remain so.

Now there are two graphql files. On defined fragment other - query with fragment import. Are there any possibilities to change used fragments depending on conditions?


Solution

  • do you have tried directives? they may help you in this situation. Please refer to the doc: http://graphql.org/learn/queries/#directives