Ricardas
Ricardas

Reputation: 548

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?

Upvotes: 5

Views: 10896

Answers (1)

Abdellah El Mennani
Abdellah El Mennani

Reputation: 268

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

Upvotes: 5

Related Questions