graphql/graphql-fragments

Use Fragments

Query with reusable fragments

graphql
fragments
query

Command

curl -X POST http://localhost:4000/graphql -H 'Content-Type: application/json' -d '{"query":"fragment userFields on User { id name email } query { users { ...userFields } }"}'

Explanation

Fragments allow you to reuse field selections. Useful for reducing repetition and keeping queries DRY.

Examples

Reuse fragment for posts

fragment postFields on Post { id title } query { posts { ...postFields } }