What is GraphQL Fragment Generator?
This tool generates GraphQL fragments from your schema SDL. For each type in your schema, it creates a fragment that includes all scalar fields and uses nested fragment spreads (...TypeNameFields) for object type fields. This creates a reusable, composable set of fragments that can be used in your GraphQL queries and mutations.
How to Use
- Paste your GraphQL schema SDL with type definitions into the input area
- Click "Generate" to create fragments for each type
- Review the generated fragments with scalar fields and nested fragment spreads
- Copy the fragments and use them in your GraphQL queries for consistent field selection
Why Use This Tool?
Tips & Best Practices
- Use these fragments as building blocks in your queries and mutations
- You can extend generated fragments with additional fields as needed
- Combine multiple fragments in a single query for complex data requirements
- Consider using a GraphQL code generator to auto-generate TypeScript types from these fragments
Frequently Asked Questions
What are GraphQL fragments?
Fragments are reusable units of GraphQL that let you construct sets of fields and then include them in queries where needed. They help avoid duplication and keep your queries maintainable.
How are nested object types handled?
For fields that reference other types defined in your schema, the tool generates nested fragment spreads (e.g., ...UserFields) instead of listing individual fields. This keeps the fragments composable and avoids duplication.
What about list scalar fields like tags: [String!]!?
List scalar fields (arrays of primitive types) are included directly in the fragment since they don't require nested fragment spreads.
Can I customize the generated fragments?
The generated fragments include all fields by default. You can modify the output to remove fields you don't need or add additional fields for specific use cases.
Is my schema data sent to a server?
No, all processing happens entirely in your browser. Your GraphQL schema never leaves your device.