|
| 1 | + |
| 2 | +# Introduction |
| 3 | + |
| 4 | +This RFC proposes adding support to adding descriptions to open DD objects which will ultimately show up in the description of different types of entities in the GraphQL schema. |
| 5 | + |
| 6 | +Description can be added to the following user facing types: |
| 7 | + |
| 8 | +1. Scalars |
| 9 | +2. Objects |
| 10 | +3. Models |
| 11 | +4. Commands |
| 12 | +5. Relationships |
| 13 | + |
| 14 | +Descriptions can be useful to the users of the GraphQL schema to understand a type/root field/argument better. |
| 15 | + |
| 16 | + |
| 17 | +## Adding a description field to the metadata object |
| 18 | + |
| 19 | + |
| 20 | +### `ScalarType` metadata object |
| 21 | + |
| 22 | +The scalar type can only have one type of description associated with it, i.e. |
| 23 | +the description of the GraphQL type. |
| 24 | + |
| 25 | +```json |
| 26 | +{ |
| 27 | + "kind": "ScalarType", |
| 28 | + "version": "v1", |
| 29 | + "definition": { |
| 30 | + "name": "NonNegativeInt", |
| 31 | + "description": "Type to represent integers that are greater than or equal to 0", |
| 32 | + "graphql": { |
| 33 | + "typeName": "NonNegativeInt" |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +The description will show up in the GraphQL schema, as following: |
| 40 | + |
| 41 | + |
| 42 | +```graphql |
| 43 | +""" |
| 44 | +Type to represent integers that are greater than or equal to 0 |
| 45 | +""" |
| 46 | +scalar NonNegativeInt |
| 47 | +``` |
| 48 | + |
| 49 | +### `ObjectType` metadata object |
| 50 | + |
| 51 | +The `ObjectType` can have two kinds of descriptions: |
| 52 | + |
| 53 | +1. Description of the object type. |
| 54 | +2. Description of the individual fields. |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "kind": "ObjectType", |
| 59 | + "version": "v1", |
| 60 | + "definition": { |
| 61 | + "name": "author", |
| 62 | + "description": "Author object containing unique identifier and name.", |
| 63 | + "fields": [ |
| 64 | + { |
| 65 | + "name": "author_id", |
| 66 | + "type": "CustomInt!", |
| 67 | + "description": "ID to uniquely identify an author." |
| 68 | + }, |
| 69 | + { |
| 70 | + "name": "first_name", |
| 71 | + "type": "String!" |
| 72 | + }, |
| 73 | + { |
| 74 | + "name": "last_name", |
| 75 | + "type": "String!" |
| 76 | + } |
| 77 | + ], |
| 78 | + "globalIdFields": [ |
| 79 | + "author_id" |
| 80 | + ], |
| 81 | + "graphql": { |
| 82 | + "typeName": "Author" |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +The description will show up in the GraphQL schema, as following: |
| 89 | + |
| 90 | +```graphql |
| 91 | +""" |
| 92 | +Author object containing unique identifier and name. |
| 93 | +""" |
| 94 | +type Author { |
| 95 | + """ |
| 96 | + ID to uniquely identify an author. |
| 97 | + """ |
| 98 | + author_id: CustomInt!, |
| 99 | + first_name: String!, |
| 100 | + last_name: String! |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### `Model` metadata object |
| 105 | + |
| 106 | +A model can have three diffrent types of descriptions, the number of descriptions correspond |
| 107 | +to the number of GraphQL APIs that are chosen to expose. At the moment of writing this |
| 108 | +document, two types of GraphQL APIs are supported, `select_many` and `select_one`. |
| 109 | + |
| 110 | +Models can also accept arguments and the argument fields can also accept descriptions. |
| 111 | + |
| 112 | + |
| 113 | +```json |
| 114 | +{ |
| 115 | + "kind": "Model", |
| 116 | + "version": "v1", |
| 117 | + "definition": { |
| 118 | + "name": "Authors", |
| 119 | + "objectType": "author", |
| 120 | + "globalIdSource": true, |
| 121 | + "arguments": [ |
| 122 | + { |
| 123 | + "name": "include_inactive", |
| 124 | + "type": "boolean", |
| 125 | + "description": "If set to true, returns authors even if they are inactive." |
| 126 | + } |
| 127 | + ], |
| 128 | + "graphql": { |
| 129 | + "selectUniques": [ |
| 130 | + { |
| 131 | + "queryRootField": "AuthorByID", |
| 132 | + "description": "Returns at most an author identified by the given author_id, returns null if author is not found with the provided ID.", |
| 133 | + "uniqueIdentifier": [ |
| 134 | + "author_id" |
| 135 | + ] |
| 136 | + } |
| 137 | + ], |
| 138 | + "selectMany": { |
| 139 | + "queryRootField": "AuthorMany", |
| 140 | + "description": "Selects multiple authors and supports filtering and pagination." |
| 141 | + }, |
| 142 | + "filterExpressionType": "Author_Where_Exp", |
| 143 | + "orderByExpressionType": "Author_Order_By", |
| 144 | + "argumentsInputType": "Author_Arguments" |
| 145 | + }, |
| 146 | + "filterableFields": [ |
| 147 | + "author_id" |
| 148 | + ], |
| 149 | + "orderableFields": [ |
| 150 | + "author_id" |
| 151 | + ] |
| 152 | + } |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +The descriptions will show up in the GraphQL schema, as following: |
| 157 | + |
| 158 | +```graphql |
| 159 | + |
| 160 | + |
| 161 | +type Query { |
| 162 | + """ |
| 163 | + Selects multiple authors and supports filtering and pagination. |
| 164 | + """ |
| 165 | + AuthorMany( |
| 166 | + args: Author_Arguments, |
| 167 | + where: Author_Where_Exp, |
| 168 | + limit: Int, |
| 169 | + offset: Int, |
| 170 | + order_by: Author_Order_By): [Author!] |
| 171 | + """ |
| 172 | + Returns at most an author identified by the given author_id, returns null if author is not found with the provided ID. |
| 173 | + """ |
| 174 | + AuthorByID( |
| 175 | + author_id: Int!, |
| 176 | + """If set to true, returns authors even if they are inactive.""" |
| 177 | + include_inactive: boolean |
| 178 | + ): Author |
| 179 | +} |
| 180 | +``` |
| 181 | + |
| 182 | +### `Command` metadata object |
| 183 | + |
| 184 | +Commands can have two kinds of descriptions. One is the description of the |
| 185 | +root field that will be exposed by the command and second is the description |
| 186 | +of the input arguments to the command. |
| 187 | + |
| 188 | +```json |
| 189 | +{ |
| 190 | + "kind": "Command", |
| 191 | + "version": "v1", |
| 192 | + "definition": { |
| 193 | + "name": "get_article_by_id", |
| 194 | + "description": "Command to get an article by using the ID.", |
| 195 | + "arguments": [ |
| 196 | + { |
| 197 | + "name": "article_id", |
| 198 | + "type": "Int!", |
| 199 | + "description": "ID of the article." |
| 200 | + } |
| 201 | + ], |
| 202 | + "outputType": "commandArticle", |
| 203 | + "graphql": { |
| 204 | + "rootFieldName": "getArticleById", |
| 205 | + "rootFieldKind": "Query" |
| 206 | + } |
| 207 | + } |
| 208 | +} |
| 209 | +``` |
| 210 | + |
| 211 | +The descriptions will show up in the GraphQL schema, as following: |
| 212 | + |
| 213 | +```graphql |
| 214 | +type Query { |
| 215 | + """ |
| 216 | + Command to get an article by using the ID. |
| 217 | + """ |
| 218 | + getArticleById( |
| 219 | + "ID of the article." |
| 220 | + article_id: Int! |
| 221 | + ) |
| 222 | +} |
| 223 | +``` |
| 224 | + |
| 225 | +### `Relationship` metadata object |
| 226 | + |
| 227 | +Relationships can have one kind of description. This description will become the |
| 228 | +GraphQL description of the relationship field. |
| 229 | + |
| 230 | + |
| 231 | +```json |
| 232 | +{ |
| 233 | + "kind": "Relationship", |
| 234 | + "version": "v1", |
| 235 | + "definition": { |
| 236 | + "source": "author", |
| 237 | + "name": "Articles", |
| 238 | + "description": "Fetches the corresponding articles of the author.", |
| 239 | + "target": { |
| 240 | + "model": { |
| 241 | + "name": "Articles", |
| 242 | + "relationshipType": "Array" |
| 243 | + } |
| 244 | + }, |
| 245 | + "mapping": [ |
| 246 | + { |
| 247 | + "source": { |
| 248 | + "fieldPath": [ |
| 249 | + { |
| 250 | + "fieldName": "article_id" |
| 251 | + } |
| 252 | + ] |
| 253 | + }, |
| 254 | + "target": { |
| 255 | + "modelField": [ |
| 256 | + { |
| 257 | + "fieldName": "article_id" |
| 258 | + } |
| 259 | + ] |
| 260 | + } |
| 261 | + } |
| 262 | + ] |
| 263 | + } |
| 264 | +} |
| 265 | + |
| 266 | +``` |
| 267 | + |
| 268 | +The descriptions will show up in the GraphQL schema, as following: |
| 269 | + |
| 270 | +```graphql |
| 271 | + type author { |
| 272 | + author_id: Int!, |
| 273 | + article_id: Int!, |
| 274 | + """ |
| 275 | + Fetches the corresponding articles of the author. |
| 276 | + """ |
| 277 | + Articles: [Articles!] |
| 278 | + } |
| 279 | +``` |
0 commit comments