मुख्य बिंदु
- 01Official graphql.js parser का उपयोग करके queries, mutations, subscriptions, और SDL schemas को format करता है।
- 02Syntax को validate करता है और errors के लिए exact line और column को report करता है — कोई schema की जरूरत नहीं।
- 03GraphQL comments (#) formatting पर strip हो जाते हैं; documentation के लिए description strings का उपयोग करें जिन्हें आप preserve करना चाहते हैं।
- 04पूरी तरह से आपके ब्राउज़र में चलता है — internal API queries और proprietary schemas निजी रहते हैं।
GraphQL Documents को क्यों Format करें?
GraphQL queries जल्दी ही complex हो जाते हैं — nested fragments, inline variables, multiple operation definitions, और SDL type definitions interfaces और directives के साथ। Consistent formatting peer review को faster बनाता है और missing closing braces या argument mismatches को एक नज़र में spot करना आसान बनाता है।
Formatter reference graphql.js parser का उपयोग करता है — same parser जो GraphQL specification के साथ ships करता है। इसका मतलब canonical formatting जो आप यहाँ get करते हैं वह Prettier के GraphQL plugin और most GraphQL tooling produce करते हैं match करता है। कुछ भी जो cleanly यहाँ parse करता है वह Apollo, Relay, और graphql-request में cleanly parse करेगा।
GraphQL Document को कैसे Format करें
- 01
अपना GraphQL paste करें
एक query, mutation, subscription, fragment, या SDL schema definition को input panel में paste करें।
- 02
Format पर क्लिक करें
Parser document को canonical indentation — two-space indent, एक field एक line पर, consistent argument alignment के साथ emit करता है। परिणाम output panel में दिखाई देता है।
- 03
Optionally validate करें
Document को बिना एक formatted output produce किए parse करता है confirm करने के लिए Validate पर क्लिक करें। Result एक confirmation या line और column numbers के साथ एक syntax errors list है।
- 04
परिणाम को copy करें
Formatted document को grab करने के लिए Copy पर क्लिक करें। अपने codebase, एक PR description, या एक documentation file में paste करें।
Internal Schemas और API Queries के लिए सुरक्षित
graphql.js parser पूरी तरह से आपके ब्राउज़र में चलता है। कोई भी operation text या schema definition किसी भी server को नहीं भेजा जाता है। यह उन queries को format करने के लिए सुरक्षित बनाता है जो private field names को reference करते हैं या internal type systems जिन्हें आप third-party tools को expose नहीं करना चाहते।
यहाँ Validation syntactic केवल है — tool check करता है कि document एक valid GraphQL document है, लेकिन यह check नहीं करता कि field names एक real schema में exist करते हैं, यदि variables argument types को match करते हैं, या यदि directives सही तरीके से apply होते हैं। Schema-aware validation को target schema को document के alongside load किया जाना आवश्यक है।
GraphQL Formatter FAQ
क्या GraphQL formatting एक schema के against validate करता है?
नहीं — केवल syntax validation। यह check करना कि fields और arguments exist करते हैं target schema की जरूरत है। यह tool confirm करता है कि document एक valid GraphQL document है, बस इतना ही।
क्या मेरे GraphQL में comments को preserve किया जाएगा?
नहीं। # से शुरू होने वाली lines को parser strip करता है। Documentation के लिए triple-quoted description strings का उपयोग करें जिसे formatting से survive करना चाहिए।
कौन सा GraphQL spec version support किया जाता है?
अक्टूबर 2021 का specification, OneOf input objects और @specifiedBy directive सहित।
क्या मैं operation documents नहीं SDL schema definitions को format कर सकता हूँ?
हाँ। Type definitions, interface declarations, union types, enums, directives, और descriptions सभी formatter के through सही तरीके से round-trip करते हैं।
क्या query या schema कहीं upload किया जाता है?
नहीं। graphql.js parser पूरी तरह से आपके ब्राउज़र में चलता है — कुछ भी आपके device को नहीं छोड़ता।