\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Demetrio} \pdfinfo{ /Title (api-graphql.pdf) /Creator (Cheatography) /Author (Demetrio) /Subject (API GraphQL Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{1D1545} \definecolor{LightBackground}{HTML}{F7F7F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{API GraphQL Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Demetrio} via \textcolor{DarkBackground}{\uline{cheatography.com/175545/cs/36839/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Demetrio \\ \uline{cheatography.com/demetrio} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 1st February, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Mutations: OnChangeResponse}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{ \newline "id": "Query", \newline "data": \{ \newline "generalQueryName": {[}... UPDATED DATA ...{]}, // For queries without pagination/filters \newline "-anotherQueryName": null, {\emph{// For queries with pagination and/or filter}} \newline \} \newline \} \newline \{\{nobreak\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{- QueryName there is top level properties on your `Query` type. \newline - You should list all top level QueryNames that may be affected (data could be changed) after applying mutation} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.32 cm} x{3.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Entity / ID's}} \tn % Row 0 \SetRowColor{LightBackground} `id:` {\bf{`ID!`}}\{\{nobreak\}\} & Main Entity id \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `userId:` {\bf{`ID!`}}\{\{nobreak\}\} & Foreign Entity id \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `deletedByAdminId:` {\bf{`ID`}}\{\{nobreak\}\} & Foreign Entity id with modifier \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{`deletedByAdminName:`} {\bf{`String`}}\{\{nobreak\}\} & Foreign Entity field with modifier \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{- `deletedBy` - is modifier/action \newline - `Admin` - is Foreign Type/Entity name \newline - `Id`/`Name` - is Foreign Entity field} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Filters: Date / Time}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`startTime:` {\bf{`DateTime`}}\{\{nobreak\}\}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`endTime:` {\bf{`DateTime`}}\{\{nobreak\}\}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`startDate:` {\bf{`Date`}}\{\{nobreak\}\}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`endDate:` {\bf{`Date`}}\{\{nobreak\}\}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`createdTimeFrom:` {\bf{`DateTime`}}\{\{nobreak\}\}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`createdTimeTo:` {\bf{`DateTime`}}\{\{nobreak\}\}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Know how to deprecate}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{type MyType \{ \newline id: ID! \newline oldField: String @deprecated(reason: "oldField is deprecated. Use newField instead.") \newline newField: String \newline anotherField: String @deprecated \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{For example `userId` in the `User` Type could be deprecated, because there is `id` have been added \newline https://spec.graphql.org/June2018/\#sec-{}-deprecated} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Non Nullable}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Ensure that all fields that always should have a value is marked as Non Nullable (!) in response% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{For example Nullable Boolean have a three state which makes a confusion. \newline Only really optional fields, may be Nullable} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Group Fields}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{type GeoPoint \{ \newline lat: Float! \newline lon: Float! \newline \} \newline \newline \newline type Address \{ \newline street: String \newline city: String \newline country: String! \newline geo: GeoPoint \newline \} \newline \newline type User \{ \newline address: Address \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Do not shy to group related fields. \newline That simplify reading/understanding of API, reusing the same Fragments, and write common utilities to work with that} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Filters: Nullability}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`isActive:` {\bf{`Boolean`}}\{\{nobreak\}\}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`startTime:` {\bf{`DateTime`}}\{\{nobreak\}\}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `siteId:` {\bf{`ID!`}} & {\bf{Required}} filter field is {\bf{Not Nullable}} \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} `limitNames:` {\bf{`{[}LimitName!{]}`}}\{\{nobreak\}\} & No Nullable Entities inside array \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{- Fields is {\bf{Nullable}}, because `null` means that we {\emph{opt-out}} filter \newline - Empty array is also means that we {\emph{opt-out}} filter} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pagination}} \tn % Row 0 \SetRowColor{LightBackground} `totalPages:` {\bf{`NonNegativeInt!`}}\{\{nobreak\}\} & 0 – ∞ \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `totalElements:` {\bf{`NonNegativeInt!`}}\{\{nobreak\}\} & 0 – ∞ \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} `page:` {\bf{`PositiveInt!`}}\{\{nobreak\}\} & 1 – ∞ \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} `size:` {\bf{`PositiveInt!`}}\{\{nobreak\}\} & 1 – ∞ \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`isFirst:` {\bf{`Boolean!`}}\{\{nobreak\}\}} \tn % Row Count 11 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`isLast:` {\bf{`Boolean!`}}\{\{nobreak\}\}} \tn % Row Count 12 (+ 1) % Row 6 \SetRowColor{LightBackground} `content:` {\bf{`{[}SomeEntity!{]}!`}}\{\{nobreak\}\} & If there is no entities - Empty Array is pretty good! \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Translations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`period: "P1Y"`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `periodName: "One Year"` & Translation for `period` values \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} `type: TypeEnum` & "TEMPORATY" | "PERMANENT" \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} `typeName: "Temporaty"` & Tranlation for `TypeEnum` values \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Boolean Fields}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`isActive:` {\bf{`Boolean!`}}\{\{nobreak\}\}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`isDeleted:` {\bf{`Boolean!`}}\{\{nobreak\}\}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`hasContent:` {\bf{`Boolean!`}}\{\{nobreak\}\}} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{- Always start boolean fields with `is` / `has` prefix. {\emph{(That's just a good practice)}} \newline - Do not forget that Nullable Boolean have a three state: `true`, `false` and `"I'm not sure"`, don't do that!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Use specific Scalar types}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Bad}}\{\{nobreak\}\} & {\bf{Good}}\{\{nobreak\}\} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `country:` {\bf{`String!`}}\{\{nobreak\}\} & `country:` {\bf{`Country!`}}\{\{nobreak\}\} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} `pageContent:` {\bf{`String!`}}\{\{nobreak\}\} & `pageContent:` {\bf{`HTML!`}}\{\{nobreak\}\} \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} `currency:` {\bf{`String!`}}\{\{nobreak\}\} & `currency:` {\bf{`Currency!`}}\{\{nobreak\}\} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `metadata:` {\bf{`String!`}}\{\{nobreak\}\} & `metadata:` {\bf{`JSON!`}}\{\{nobreak\}\} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} `value:` {\bf{`String!`}}\{\{nobreak\}\} & `value:` {\bf{`Duration!`}}\{\{nobreak\}\} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} `addressType:` {\bf{`Int!`}}\{\{nobreak\}\} & `addressType:` {\bf{`AddressTypeEnum!`}}\{\{nobreak\}\} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{- That allow you to implement validation for corresponding type once, and reuse it everywhere. \newline - For FE that also allows to validate the types, and improving readability and understanding of API} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}